UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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

3      

and here is solution if someone will look for it

My article on MLRecommender https://www.pawelmadej.com/post/mlrecommender-in-practice/

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.