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"))

rmaddy
  • 314,917
  • 42
  • 532
  • 579
AlbF
  • 51
  • 1
  • 3
  • 11

1 Answers1

1

URL is from the Foundation framework.

Add:

import Foundation

just before import CreateML.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 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. – rmaddy Oct 04 '18 at 05:03