Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,12 +87,11 @@ def initialize_preprocessors():
|
|
| 87 |
encoder = OneHotEncoder(drop='first', sparse_output=False)
|
| 88 |
encoder.fit(df[categorical_features])
|
| 89 |
|
| 90 |
-
|
| 91 |
-
return encoder, scaler, categorical_features
|
| 92 |
|
| 93 |
# Global variables
|
| 94 |
MODELS = load_models()
|
| 95 |
-
encoder,
|
| 96 |
|
| 97 |
# Prediction function
|
| 98 |
def make_prediction(model, X_user, model_type):
|
|
@@ -106,10 +105,10 @@ def make_prediction(model, X_user, model_type):
|
|
| 106 |
return model.predict(X_user_scaled)
|
| 107 |
|
| 108 |
elif model_type == ModelType.LINEAR_REGRESSION:
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
X_user_scaled =
|
| 113 |
return model.predict(X_user_scaled)
|
| 114 |
|
| 115 |
elif model_type == ModelType.XGBOOST:
|
|
|
|
| 87 |
encoder = OneHotEncoder(drop='first', sparse_output=False)
|
| 88 |
encoder.fit(df[categorical_features])
|
| 89 |
|
| 90 |
+
return encoder, categorical_features
|
|
|
|
| 91 |
|
| 92 |
# Global variables
|
| 93 |
MODELS = load_models()
|
| 94 |
+
encoder, categorical_features = initialize_preprocessors()
|
| 95 |
|
| 96 |
# Prediction function
|
| 97 |
def make_prediction(model, X_user, model_type):
|
|
|
|
| 105 |
return model.predict(X_user_scaled)
|
| 106 |
|
| 107 |
elif model_type == ModelType.LINEAR_REGRESSION:
|
| 108 |
+
# ✅ Fit scaler dynamically on `X_user`
|
| 109 |
+
scaler_lr = StandardScaler()
|
| 110 |
+
scaler_lr.fit(X_user)
|
| 111 |
+
X_user_scaled = scaler_lr.transform(X_user)
|
| 112 |
return model.predict(X_user_scaled)
|
| 113 |
|
| 114 |
elif model_type == ModelType.XGBOOST:
|