AttributeError: ‘DecisionTreeRegressor’ object has no attribute ‘monotonic_cst’

Hi! I am new to the community and trying to deploy my machine learning project.

My application runs machine learning model when doing clients click “calculate.” However, an error occurs when the button is clicked, which didn’t happen on local host:

AttributeError: ‘DecisionTreeRegressor’ object has no attribute ‘monotonic_cst’

Can anyone help me? Thank you!

I am not sure if this information can help:
A portion code is imported from the jupyter notebook in the same folder.

Link to public deployed app:
https://swd-salary-prediction.streamlit.app/

My GitHub repository:
(GitHub - aaronwu001/SWD-salary-prediction

Streamlit and Python Versions:
Streamlit: 1.3.2
Python 3.12.0

Try to specify the versions of the modules in the requirements.txt to the one you have locally and try again.
And use python 3.11 locally since streamlit does not support 3.12 in the deployment right now. :wink:

Save the downgrade version in requirements.txt on github.
Specify the correct version and save it in the requirements.txt file, such as scikit-learn==1.3.0. It will probably run. Have a nice day!!

I am getting the same error.

numpy==1.20.1
streamlit==0.76.0
seaborn==0.11.1
matplotlib==3.4.1
plotly==4.14.3
pandas==1.2.3
scikit-learn == 1.4.0
statsmodels

this is my requirements.txt file.

Hey.

numpy==1.20.1
streamlit==0.76.0
seaborn==0.11.1
matplotlib==3.4.1
plotly==4.14.3
pandas==1.2.3
scikit-learn == 1.4.0
statsmodels

this is my requirements.txt file. Can you check it? I am also getting the same error.

As always with ML models, you should ensure that the version is the same when training as when loading and using. You could try scikit-learn=1.3.2

2 Likes

downgraded to 1.3.0 and it worked fine. scikit-learn==1.3.0

2024년 2월 12일 (월) 오전 12:51, Saheli Jati via Streamlit <notifications@streamlit.discoursemail.com>님이 작성:

1 Like

Hey @Saheli_Jati , instead mentioning the versions just use the following packages :-

streamlit
scikit-learn
numpy
pandas
matplotlib
plotly
statsmodels
seaborn

Happy Streamlit-ing :balloon:

1 Like

Thanks. It worked.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.