0

app.py

In my app.py file, I have written this code to load the model (random_forest_reg_model.pkl):

filename = 'random_forest_reg_model.pkl'
model = pickle.load(open(filename, "rb"))

Error

Now I am getting this error:

C:\Users\ADMIN\anaconda3\envs\carpriceprediction\lib\site-packages\sklearn\base.py:310: UserWarning: Trying to unpickle estimator RandomForestRegressor from version 0.23.2 when using version 0.24.1. This might lead to breaking code or invalid results. Use at your own risk.
  warnings.warn(
Traceback (most recent call last):
  File "C:\Users\ADMIN\Desktop\ML\Projects\CarPricePrediction\app.py", line 10, in <module>
    model = pickle.load(open(filename, "rb"))
EOFError: Ran out of input
Bhavik Jain
  • 45
  • 10
  • Where is your `random_forest_reg_model.pkl` file? – Parzival Apr 11 '21 at 06:03
  • it is in the same directory where my app.py file is saved – Bhavik Jain Apr 11 '21 at 06:14
  • Did you use `wb` when you wrote the pickle? If it possible you snuck the pickle file into an editor and accidentally changed it? – Tim Roberts Apr 11 '21 at 06:18
  • 2
    Does this answer your question? [Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?](https://stackoverflow.com/questions/24791987/why-do-i-get-pickle-eoferror-ran-out-of-input-reading-an-empty-file) – Jürgen Gmach Apr 11 '21 at 06:20
  • Yes I have used 'wb' : ```import pickle file = open('random-forest-model.pkl', 'wb') pickle.dump(rf_random, file) ``` – Bhavik Jain Apr 11 '21 at 06:20
  • @BhavikJain `wb` will actually overwrite your file. Try changing it to `rb` – Parzival Apr 11 '21 at 06:33
  • @Parzival I want to create a new file to export the ML model into it. That is why I am using `wb`. Even I have done it before but never get this type of error. – Bhavik Jain Apr 11 '21 at 06:40
  • You can check my code here: [Github](https://github.com/Bhavik-Jain/CarPricePrediction) – Bhavik Jain Apr 11 '21 at 06:44

0 Answers0