I am new with machine learning and want to do following implementation
Want to create a custom .mlmodel with input of "xls or csv or nsdata of this files" and output should be double or array.
Pythone file should be able to read input data because i am going to use train_data from this input.
Pythone will do some calculation on this input data and provide prediction on this (i will do this calculation using sklearn,LinearRegression)
Can any one please help me how i can do this ?
You can use python to train your model with SKLearn as you suggested. This is a good post on getting started with that (make sure you use Sklearn and not Statsmodels).
https://towardsdatascience.com/simple-and-multiple-linear-regression-in-python-c928425168f9
When you have trained your model, you can convert it using Apple's coremltools:
https://github.com/apple/coremltools
When you've converted it you can add your .mlmodel file to your xcode project. You'll then need to write some code to get all of the your model inputs collected from your app and pass them as inputs to the model.
Good luck!
Related
I want LSTM to learn with newer data. It needs to update itself depending on the trend in the new data and I wish to save this say in a file. Then I wish to call this pre-fed training file into any other X,Y,Z fresh files where testing is done. So I wish to 're-fit' [update NOT re-train] the model with new data such that model parameters are just updated and not re-initialized. I understand this is online learning but how to implement it through Keras? Can someone please advise how to successfully implement it?
I'm attempting to create a text-classification model with tensorflow. There are many datasets you can import into a project using tfds.load(), but I want to create a unique dataset of my own. In tensorflow.js, all I had to do was create a JSON file with training/testing data. There doesn't seem to be an easy way to do this with python.
Does anyone have experience with this?
ŧf.data.Dataset is the place to be. Lil' pointer: https://www.tensorflow.org/api_docs/python/tf/data/Dataset. If your dataset fits into memory, you can go with tf.data.from_tensor_slices which lets you create a Dataset from numpy arrays. If not, from_generator might suit you, as you can write your generator in plain python. For the "correct" way to do it (this gives you the fastest pipeline in theory) you should save your data as TFRecords and read them with tf.data.TFRecordDataset. Whatever floats your boat. Just click the link!
I'm developing a RNN for a project and I need to train it on a computer and be able to predict on another. The solution I found is to save the model into a .h5 file using the code below:
... # Train the data etc....
model.save("model.h5")
My problem is that I need to store some meta-data from my training dataset and pre-process and be able to load it together with the model. (e.g. name of dataset file, size of the dataset file, number of characters, etc...)
I don't want to store this information in a second file (e.g. a .txt file) because I would have to use two files. I don't want to use any additional library or framework for this task.
I was thinking (brainstorming) a code like this:
model.save("model.h5", metaData={'myVariableName': myVariable})
And to load would be:
myVariable = model.load("model.h5").getMetaData('myVariableName')
I know this is not possible in the current version and I already read Keras doc, but I couldn't find any efficient method to do that. Notice that what I'm asking is different from custom_object because want to save and load my own variables.
Is there a smarter approach to solve this problem?
I am trying to check if my .onnx model is correct, and need to run inference to verify the output for the same.
I know we can run validation on .mlmodel using coremltools in Python - basically load the model and input and get the prediction. I am trying to do a similar thing for the .onnx model.
I found the MXNet framework but I can't seem to understand how to import the model - I just have the .onnx file and MXNet requires some extra input besides the onnx model.
Is there any other simple way to do this in Python? I am guessing this is a common problem but can't seem to find any relevant libraries/frameworks to do this as easily as coremltools for .mlmodel.
I do not wish to convert .onnx to another type of model (like say PyTorch) as I want to check the .onnx model as is, not worrying if the conversion was correct. Just need a way to load the model and input, run inference and print the output.
This is my first time encountering these formats, so any help or insight would be appreciated.
Thanks!
I figured out a way to do this using Caffe2 - just posting in case someone in the future tries to do the same thing.
The main code snippet is:
import onnx
import caffe2.python.onnx.backend
from caffe2.python import core, workspace
import numpy as np
# make input Numpy array of correct dimensions and type as required by the model
modelFile = onnx.load('model.onnx')
output = caffe2.python.onnx.backend.run_model(modelFile, inputArray.astype(np.float32))
Also it is important to note that the input to run_model can only be a numpy array or a string. The output will be an object of the Backend.Outputs type. I was able to extract the output numpy array from it.
I was able to execute inference on the CPU, and hence did not need the Caffe2 installation with GPU (requiring CUDA and CDNN).
I have trained a classifier model using RapidMiner after a trying a lot of algorithms and evaluate it on my dataset.
I also export the model from RapidMiner as XML and pkl file, but I can't read it in my python program (scikit-learn).
Is there any way to import RapidMiner classifier/model in a python program and use it to predict or classify new data in my end application?
Practically, I would say no - just train your model in sklearn from the beginning if that's where you want it.
Your RapidMiner model is some kind of object. The two formats you are exporting as are just storage methods. Sklearn models are a different kind of object. You can't directly save one and load it into the other. A similar example would be to ask if you can take an airplane engine and load it into a train.
To do what you're asking, you'll need to take the underlying data that your classifier saved, find the format, and then figure out a way to get it in the same format as a sklearn classifier. This is dependent on what type of classifier you have. For example, if you're using a bayesian model, you could somehow capture the prior probabilities and then use those, but this isn't trivial.
You could use the pmml extenstion for RapidMiner to export your model.
For python there is for example the augustus library that can work with pmml files.