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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.