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

MLRecommender issues

Forums > Swift

Hello,

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 https://www.pawelmadej.com/post/mlrecommender-in-practice/

   

Hacking with Swift is sponsored by NSSpain

SPONSORED Announcing NSSpain 2020: Remote Edition! An online, continuous conference for iOS developers. We’ll start on Thursday and finish on Friday, with talks, activities, and lots of fun for 36 hours, non-stop. Sound good? Join us!

Find out more

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.