Bianco
Bianco

Reputation: 551

Swift CreateML error while trying to train data model. Any input is greatly appreciated

I'm doing a tutorial on how to create a Machine Learning Data model using Swift CoreML & CreateML. I'm getting a weird error when trying to load the training data into the MLTextClassifier object from a .csv file.

What I'm expecting it to do is simply train the classifier object and show my evaluation results on how well it learned based on the data given, but instead I'm getting the error shown below. Any input is greatly appreciated.

I've made sure my code is free of typos and that the .csv file path is correct. I've also read Apple's documentation and followed it accordingly for this setup. I've also looked online for a solution and found nothing.

The console shows that my csv file is loading, and that the "randomSplit()" function is correctly parsing the data, but once I try to create the "sentimentClassifier" thats where the error appears.

Here's my code:

import Cocoa
import CreateML

let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/path/file.csv"))

let (trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5)

let sentimentClassifier = try MLTextClassifier(trainingData: trainingData, textColumn: "text", labelColumn: "sentiment")

let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "sentiment")

let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100

Here's the error:

error: Couldn't lookup symbols:

static CreateML.MLTextClassifier.defaultParameters.getter : CreateML.MLTextClassifier.ModelParameters

Upvotes: 2

Views: 1118

Answers (1)

Mansa Pratap
Mansa Pratap

Reputation: 66

let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "class")

Enter this code instead. Hopefully this will work.

Upvotes: 1

Related Questions