How to create a core ml model programmatically

Hello,
I am trying to create a tabular classifier using core ml. I wanted to keep track of how the user play's the game (using spriteKit) and train my model accordingly. Can anyone help me out.

Thanks!

Replies

Can you say more about what you want the model to do?
In other words, what prediction would you like your model to make?
Are you considering a classifier or regressor model type?
I am using a classifier that trains using three positions and returns whether to jump or no

I wanted to keep track of how the user play's the game (using spriteKit) and train my model accordingly. Can anyone help me out. 

How do you plan to collect the data in this case? Do you plan to take it over to some central server and train a model there or you are looking to train an empty model on the device - for use on the device? Solutions might be quite different based on what you are looking to do.
I want to train the model on device and will only be used on the device.
I want to train the model on device and will only be used on the device. 
Hello.

What you need currently exists only on macOS with Xcode by using Create ML framework.
You can find documentation here.

You can't use Create ML framework today in your apps. Only available into scripts and playgrounds.

But you can easily create Core ML models on servers using Turi Create.
It works fine with Tabular data.

My suggestion if you want to ensure privacy for your users:
  • use encryption with server (end-to-end encryption is the best)

  • upload real data with a UUID and append fake data with random UUID (ie. 1 good sample, 3 fake samples)

  • store the "good" UUID locally

  • download results later by sending UUID (ie. 1 good UUID, 3 fake UUID)

  • server will return good result + random results

  • use local UUID to identify good result.

If your model is public and can be used by any user, you can use distribute it by using model deployment presented this year.

And, once Create ML will be available for apps, you will be able to make it available for your users.
Isn’t there is a way to train the empty model using core ml?
On the iPhone
Yes, there is a way but you're not going to like it. ;-) You'll have to write your own training code from scratch so that it can run on the phone.

Then to turn this into a Core ML model, you can write protobuf messages to a new mlmodel file. Finally, you can load this mlmodel using the Core ML API, compile it on the device, and then you can use it make predictions.

But if you already have to write your own training code, it also makes sense to write your own inference code and skip Core ML altogether.