-
Notifications
You must be signed in to change notification settings - Fork 1.9k
We are not getting submodel for LinearBinaryModelParameters after loading model #3967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
IPredictorProducing is not accessible due to its protection level |
I don't have your data file, so I can't really run your code. However, with the latest ML.NET version 1.2, I can successfully compile the casting // Casting is done with ML.NET 1.2.
LinearBinaryModelParameters linearBinaryModelParameters = ((Microsoft.ML.Data.TransformerChain<Microsoft.ML.Data.BinaryPredictionTransformer<Microsoft.ML.Calibrators.CalibratedModelParametersBase<Microsoft.ML.Trainers.LinearBinaryModelParameters, Microsoft.ML.Calibrators.PlattCalibrator>>>)mlModel).LastTransformer.Model.SubModel; in static void Main(string[] args)
{
MLContext mlContext = new MLContext();
// Training code used by ML.NET CLI and AutoML to generate the model
ModelBuilder.CreateModel();
ITransformer mlModel = mlContext.Model.Load(GetAbsolutePath(MODEL_FILEPATH), out DataViewSchema inputSchema);
// Casting is done with ML.NET 1.2.
LinearBinaryModelParameters linearBinaryModelParameters = ((Microsoft.ML.Data.TransformerChain<Microsoft.ML.Data.BinaryPredictionTransformer<Microsoft.ML.Calibrators.CalibratedModelParametersBase<Microsoft.ML.Trainers.LinearBinaryModelParameters, Microsoft.ML.Calibrators.PlattCalibrator>>>)mlModel).LastTransformer.Model.SubModel;
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
// Create sample data to do a single prediction with it
ModelInput sampleData = CreateSingleDataSample(mlContext, DATA_FILEPATH);
// Try a single prediction
ModelOutput predictionResult = predEngine.Predict(sampleData);
Console.WriteLine($"Single Prediction --> Actual value: {sampleData.PurchasedBike} | Predicted value: {predictionResult.Prediction}");
Console.WriteLine("=============== End of process, hit any key to finish ===============");
Console.ReadKey();
} |
I believe this is problem is related to the problem explained in here, and which was fixed a couple of months ago in PRs #4262 and #4306 and made available in ML.NET 1.4. Basically the problem was that PredictionTransformers' parameter types weren't being set correctly when loading from disk. So what I suspect was your problem is that the last transformer in your model was a I will close this issue, since I believe it's been fixed, and without your input dataset I couldn't really test it. Please, feel free to reopen the issue if you think there's still work to be done. Thanks! |
Hi
After loading model for binary classification we are trying to get submodel and calibrator
but if you see after loading model we write below code
but failed to getting sub model which is required for us for
LinearBinaryModelParameters
if you see in CreateModel method we easily get SubModel by writing below code
but same code if we writer after loading model the we got exception of casting
please guide us.
mlApp_ex.zip
The text was updated successfully, but these errors were encountered: