NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

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 Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.