NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

MLRecommender issues

Forums > Swift


I want to create CoreML Recommender model where my training data looks like that:

userID (UUID)  | itemID (UUID) | rating (Int)

user can rate from 0 to x number of items and until every user in training data rates same number of items (for example 10) everything works fine.

But when I try to create traiing model where user1 rates two items, user2 rates five items, user3 rates one item I start having this error:

Playground execution terminated: An error was thrown and was not caught:
▿ Item IDs in the recommender model must be numbered 0, 1, ..., num_items - 1.
  ▿ generic : 1 element
    - reason : "Item IDs in the recommender model must be numbered 0, 1, ..., num_items - 1."

how can I fix this?

full playground code:

let trainingData = try MLDataTable(contentsOf: URL(fileURLWithPath: "/.../test.csv"))
let model = try MLRecommender (trainingData: trainingData, userColumn: "userID", itemColumn: "itemID", ratingColumn: "rating")
let recs = try model.recommendations(fromUsers: ["050510A3-0C96-4F57-8A45-433422680464"])


and here is solution if someone will look for it

My article on MLRecommender


Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.