1

Apple has recently released a framework that allows to create machine learning models. I am interested in tabular data but I haven't found any example online. Could anyone please provide a piece of code that works? I have tried the following provided by Apple without success:

import CreateML

// Specify Data
let trainingCSV = URL(fileURLWithPath: "/Users/createml/HouseData.csv")
let houseData = MLDataTable(contentsOf: trainingCSV)
let (trainingData,testData) = houseData.randomSplit(by: 0.8, seed: 0)

// Create Model
let pricer = try MLRegressor(trainingData: houseData, targetColumn: "price")

// Evaluate Model
let metrics = try pricer.testingMetrics(on: testData)

// Save Model
try pricer.write(to: URL(fileURLWithPath: "/Users/createml/HousePricer.mlmodel"))

In particular this code throws me the following error on line 4 and 15:

error: MyPlaygroundu.playground:9:22: error: use of unresolved identifier 'URL' try pricer.write(to: URL(fileURLWithPath: "/Users/createml/HousePricer.mlmodel"))

0

1 Answer 1

1

URL is from the Foundation framework.

Add:

import Foundation

just before import CreateML.

Sign up to request clarification or add additional context in comments.

1 Comment

That's another issue for another question. Mark this one as resolved. Then do some research into your new errors. If needed, post a new question with all relevant details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.