I am using Playground to create a Text Classifier Model using CreateML and keep getting the error:
Playground execution terminated: An error was thrown and was not caught:
▿ The validation data provided must contain class.
▿ type : 1 element
- reason : "The validation data provided must contain class."
My code is relatively simple, using two columns from a data table. The textColumn is labeled "text" and the labelColumn is labeled "class":
import Cocoa
import CreateML
let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ ... .csv"))
let(trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5)
let sentimentClassifier = try MLTextClassifier(trainingData: trainingData, textColumn: "text", labelColumn: "class")
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "class")
let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100
The only difference I can find between this and the code provided in the Apple Developer Documentation is that instead of
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "class")
their documentation is:
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData)
and version 11.2.1 of Xcode gives me a failure if I try using the line from the Apple Developer Documentation.
Thanks in advance for any help you can offer.
Try This! it works for me
let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/justinmacbook/Desktop/twitter-sanders-apple3.csv"))
let (trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5 )
let sentimentClassifier = try MLTextClassifier(trainingData: trainingData, textColumn: "class", labelColumn: "text")
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "class", labelColumn: "text")
let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100