Why is my program returning the same output every time I run?
17:42 18 Jun 2026
app.py
from flask import Flask, request, render_template
from preprocessing import preprocess
from predict import predict

app = Flask(__name__)

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/predict", methods=["POST"])
def get_prediction():

    data = request.form.to_dict()

    processed = preprocess(data)

    result = predict(processed)

    return render_template(
        "index.html",
        prediction=float(result[0])
    )

if __name__ == "__main__":
    app.run(debug=True)


________________________________________________________________________________

Predict.py




import joblib
from pathlib import Path


model = joblib.load(Path(__file__).parent / "model.pkl")

def predict(df):
    return model.predict(df)
    
_______________________________________________________________________________



model.py




from sklearn.tree import DecisionTreeRegressor
import pandas as pd
from sklearn.model_selection import GridSearchCV
import joblib

data = pd.read_csv("ml/logisticregression/projectseries/supercars/datasets/prosupercars.csv")

y = data["price"]
x = data.drop(columns=["price"]) 

dt = DecisionTreeRegressor()

param_grid = {
    "max_depth": [None, 3, 5, 7, 10],
    "min_samples_split": [2, 5, 10],
    "min_samples_leaf": [1, 2, 5, 10],
    "max_features": [None, "sqrt", "log2"]
}

grid = GridSearchCV(
    estimator=dt,
    param_grid=param_grid,
    scoring="neg_mean_absolute_error",  
    cv=5
)

grid.fit(x, y)

model = grid.best_estimator_
print(grid.best_params_)
joblib.dump(model, "ml/logisticregression/projectseries/supercars/datasets/model.pkl")
joblib.dump(x.columns.tolist(), "ml/logisticregression/projectseries/supercars/datasets/columns.pkl")





_________________________________________________________________________________
preprocessing.py
import pandas as pd
import joblib
from pathlib import Path

columns = joblib.load(Path(__file__).parent / "columns.pkl")

def preprocess(data):
    if isinstance(data, dict):
        data = pd.DataFrame([data])

    
    for col in data.columns:
        data[col] = pd.to_numeric(data[col], errors="ignore")

    data = pd.get_dummies(data)

    data = data.reindex(columns=columns, fill_value=0)

    return data

whenever i run it always outputs the same value(2473304.0015789475)

I have a Flask app using a sklearn DecisionTreeRegressor.

Problem:

The model always returns the same prediction no matter the input.

Expected:

Different inputs should give different predictions.

Actual:

Every request returns the same value.

machine-learning preprocessor