Deploying Machine Learning Model in Flask to Render

Hello, I’m having difficulty in deploying my Flask script in Render. this is the code.
from flask import Flask, request, jsonify
import joblib
import numpy as np

app = Flask(name)

Load the trained model

model = joblib.load(‘SVR_1.joblib’)

@app.route(‘/predict’, methods=[‘POST’])
def predict():
# Get input data from the request
data = request.get_json(force=True)
input_data = np.array(data[‘features’])

    # Reshape the 1D array to a 2D array
    input_data_2d = input_data.reshape(1, -1)

    # Make predictions using the loaded model
    prediction = model.predict(input_data_2d)

    # Return the prediction as JSON
    return jsonify({"prediction": prediction.tolist()})

except Exception as e:
    return jsonify({"error": str(e)})

if name == ‘main’:‘’, port=5000)
pip install --upgrade pip
pip install -r requirements.txt


build command:

start command:

i keep having errors like this:

Traceback (most recent call last):

File “/opt/render/project/src/”, line 8, in
model = joblib.load(‘SVR_1.joblib’)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/joblib/”, line 658, in load
obj = _unpickle(fobj, filename, mmap_mode)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/joblib/”, line 577, in _unpickle
obj = unpickler.load()
File “/usr/local/lib/python3.11/”, line 1213, in load

File “/usr/local/lib/python3.11/”, line 1538, in load_stack_global

self.append(self.find_class(module, name))

File “/usr/local/lib/python3.11/”, line 1580, in find_class
import(module, level=0)
ModuleNotFoundError: No module named ‘sklearn’

thanks in advance!


The main error appears to be:

ModuleNotFoundError: No module named ‘sklearn’

I’m not a Python expert, but searching for that error seems to bring up plenty of resources with the same issue and suggested resolutions.

Maybe you’ve using the old package?


1 Like

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