04-04-2023 01:13 AM
I am running the code for prediction which will take the model from mlflow deployment. Code I have copied from the example given by mlflow experiment tab.
import mlflow
logged_model = 'runs:/id/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))
Here I am getting the error on this line
loaded_model.predict(pd.DataFrame(data))
MlflowException: The input pandas data frame column 'None' contains scalar values, which requires the shape to be (-1,), but got tensor spec shape of (-1, "Some big integer").
Can anyone help me how to resolve this error?
04-06-2023 03:05 AM
Hi @Koushik Deb try this your problem will be resolve now. if it works don't forget to accept and upvote the answer 🙂
import mlflow
import pandas as pd
# Load model as a PyFuncModel.
logged_model = 'runs:/id/model'
loaded_model = mlflow.pyfunc.load_model(logged_model)
# Create a dataframe with a single column
data = pd.DataFrame({'text': ["visit www.bet365.com for a free trial"]})
# Call predict method with the dataframe
predictions = loaded_model.predict(data)
04-04-2023 11:49 AM
You can try this out, I don't know the shape of the dataframe it would be helpful if you would also print the shape of the dataframe , based on my assumption and the input you provided try this code.
import mlflow
import pandas as pd
# Load model as a PyFuncModel.
logged_model = 'runs:/id/model'
loaded_model = mlflow.pyfunc.load_model(logged_model)
# Create a list from the pandas DataFrame
data_list = data.values.tolist()
# Predict using the loaded model
predictions = loaded_model.predict(data_list)
# Print the predictions
print(predictions)
04-06-2023 02:13 AM
I have tried this one.
I am providing data as a list of single element.
data = ["visit www.bet365.com for a free trial"]
Tried with
predictions = loaded_model.predict(data)
and
predictions = loaded_model.predict(pd.DataFrame(data))
04-06-2023 03:05 AM
Hi @Koushik Deb try this your problem will be resolve now. if it works don't forget to accept and upvote the answer 🙂
import mlflow
import pandas as pd
# Load model as a PyFuncModel.
logged_model = 'runs:/id/model'
loaded_model = mlflow.pyfunc.load_model(logged_model)
# Create a dataframe with a single column
data = pd.DataFrame({'text': ["visit www.bet365.com for a free trial"]})
# Call predict method with the dataframe
predictions = loaded_model.predict(data)
04-06-2023 03:15 AM
After executing the given code by you, I have got this error
MlflowException: The input pandas dataframe column 'None' contains scalar values, which requires the shape to be (-1,), but got tensor spec shape of (-1, 14654).
Let me know if you have any idea on this.
04-06-2023 03:40 AM
please print actual shape of your dataframe before passing it to the .predict function, the list you have provided , I have created a code from that its working fine.
you are not showing the actual shape of dataframe, there is problem with the shape of the data that you are passing.
04-04-2023 11:24 PM
Hi @Koushik Deb
Thank you for posting your question in our community! We are happy to assist you.
To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?
This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group