I am working on a project involving CreateML and an MLLinearRegressor. For some reason, any time I attempt to predict a value that's not present in the training data, I get the same prediction every time. This happens both in Swift Playgrounds and when using the model in an Xcode project. Why might this be happening? I've posted my Swift Playgrounds code below.
import CreateML
import CoreML
import Foundation
do {
let data: [String: MLDataValueConvertible] = [
"Processor Name": ["A6", "A7", "A8", "A8X", "A9", "A9X", "A10X", "A10X", "A11"],
"Geekbench Singlecore": [754, 1325, 1660, 1796, 2522, 3052, 3463, 3909, 4219]
]
let CPURegressor = try MLLinearRegressor(trainingData: MLDataTable(dictionary: data), targetColumn: "Geekbench Singlecore", featureColumns: ["Processor Name"])
let testData: [String: MLDataValueConvertible] = [
"Processor Name": ["A6", "A7", "A8", "A8X", "A9", "A9X", "A10X", "A10X", "A11", "A12"],
"Geekbench Singlecore": [754, 1325, 1660, 1796, 2522, 3052, 3463, 3909, 4219,0]
]
print(try CPURegressor.predictions(from: MLDataTable(dictionary: testData))) // Notice how last (A12) and first (A6) values are the same
} catch {
print(error)
}
Update:
This is what my code looks like after adjusting my Processor Name
category
import CreateML
import CoreML
import Foundation
do {
let data: [String: MLDataValueConvertible] = [
"Processor Name": [6.0, 7.0, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0],
"Geekbench Singlecore": [754, 1325, 1660, 1796, 2522, 3052, 3463, 3909, 4219]
]
print(try MLDataTable(dictionary: data))
let CPURegressor = try MLRegressor(trainingData: MLDataTable(dictionary: data), targetColumn: "Geekbench Singlecore", featureColumns: ["Processor Name"])/*, parameters: MLBoostedTreeRegressor.ModelParameters(validationData: nil, maxDepth: 1000,
maxIterations: 1000,
minLossReduction: 1))*/
/*CPURegressor.modelParameters = MLImageClassifier.ModelParameters(featureExtractor: .scenePrint(revision: 1),
validationData: nil,
maxIterations: 30,
augmentationOptions: [])*/
/* let testData: [String: MLDataValueConvertible] = [
"Processor Name": [0, 1, 2, 3, 4, 5, 6, 7, 8, 14],
"Geekbench Singlecore": [1325, 1660, 1796, 2522, 3052, 3463, 3909, 4219,0, 1325]
]
print(try CPURegressor.predictions(from: MLDataTable(dictionary: testData))) // Notice how last (A12) and first (A6) values are the same*/
} catch {
print(error)
}