- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 05:22 AM
I trained my model and was able to get the batch prediction from that model as specified below. But I want to also get the probability scores for each prediction. Do you have any idea?
Thank you!
logged_model = path_to_model
# Load model as a PyFuncModel.
loaded_model = mlflow.pyfunc.load_model(logged_model)
# Predict on a Pandas DataFrame.
import pandas as pd
loaded_model.predict(pd.DataFrame(data))
- Labels:
-
BatchPrediction
-
Model
-
Pandas dataframe
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 12:06 PM
Hi @Kaniz Fatma
The error said 'PyFuncModel' object has no attribute 'predict_proba'.
As shows above, I was using the following to load the model
loaded_model = mlflow.pyfunc.load_model(logged_model) and got the error.
After going through mlflow documentation, I changed it to
loaded_model = mlflow.sklearn.load_model(logged_model) and it is working fine.
It's all good now. Thanks for your time.
Syed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 07:21 AM
Hi Kaniz,
Great to meet you too!
Thank you for replying to my question.
Best!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 11:35 AM
Hi @Kaniz Fatma
Sorry for hijacking the post.
My question is - if I am reading a registered model from mlflow, I can only see the option of .predict method but not .predict_proba.
Do we have any straightforward solution to get the probabilities?
Thanks
Syed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 12:06 PM
Hi @Kaniz Fatma
The error said 'PyFuncModel' object has no attribute 'predict_proba'.
As shows above, I was using the following to load the model
loaded_model = mlflow.pyfunc.load_model(logged_model) and got the error.
After going through mlflow documentation, I changed it to
loaded_model = mlflow.sklearn.load_model(logged_model) and it is working fine.
It's all good now. Thanks for your time.
Syed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 12:16 PM
Hi @Kaniz Fatma
I do not see the option to select "Best Answer" but feel free to do anything that you think can help this community.
Thanks
Syed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 01:38 AM
Now you can log the model using this parameter:
mlflow.sklearn.log_model(
..., # the usual params
pyfunc_predict_fn="predict_proba"
)
which will return probabilities for the first class apparently when using the model for inference (e.g. when loading it using mlflow.pyfunc.spark_udf() ).

