1

I have a trained Machine Learning model saved in GitHub repository with the name "trained_model.sav". I want to download it using Requests module of Python and use it in my Python file (with .py extension). When I run the following code:

url = "https://github.com/MUmairAB/Stroke-Prediction-using-Machine-Learning/blob/main/trained_model.sav?raw=true"
r = requests.get(url)
pickle.dump(r.content,open(os.path.join(getcwd(),'trained_model12.pkl'),'wb'))
model = pickle.load(open(os.path.join(getcwd(),'trained_model12.pkl'),'rb'))

# Using the model to make predictions
input_array = np.array([[0,67,0,1,0,228.69,36.6],
              [0,58,1,0,0,87.96,39.2]])

input_df = pd.DataFrame(x)
prediction = modell.predict(input_df)

I get the following error

runfile('C:/Users/User1/Desktop/folder1/file1.py', wdir='C:/Users/User1/Desktop/folder1')
Traceback (most recent call last):

  File ~\anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\user1\desktop\folder1\file1.py:35
    prediction = model.predict(df)

AttributeError: 'bytes' object has no attribute 'predict'

About the trained_model.sav:

It is a Machine Learning Pipeline object. After downloading it, I want to use it to make predictions.

What I want to achieve with the code?

I want to use the "trained_model.sav** file present in a GitHub repository, in a Python file with .py extension.

I can easily do this easily in IPython Notebook with .ipyn extension with:

!git clone REPOSITORY_LINK

But I cannot do that in .py file.

So, any suggestion how to do it or point out mistake in this code will be highly appreciated. If there is some other approach to get the job done, please comment that as well.

I was expecting that "trained_model.sav" file will be downloaded in my Python (with extension .py) file. And use this file as a Machine Learning model.

0 Answers0