Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -37,14 +37,20 @@ def predict_churn():
|
|
| 37 |
# Convert the extracted data into a DataFrame
|
| 38 |
input_data = pd.DataFrame([requestData])
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Make a churn prediction using the trained model
|
| 41 |
-
prediction = model.predict(
|
| 42 |
|
| 43 |
#Calculate the actual price
|
| 44 |
predicted_sales = np.exp(prediction)
|
| 45 |
|
| 46 |
# Convert predicted_price to Python float
|
| 47 |
predicted_sales = round(float(predicted_sales), 2)
|
| 48 |
-
|
| 49 |
# Return the prediction as a JSON response
|
| 50 |
return jsonify({'Predicted_Sale': predicted_sales})
|
|
|
|
| 37 |
# Convert the extracted data into a DataFrame
|
| 38 |
input_data = pd.DataFrame([requestData])
|
| 39 |
|
| 40 |
+
# create encoder with OneHotEncoder for encoding the selected values to match the training data
|
| 41 |
+
encoder = OneHotEncoder(handle_unknown='ignore', sparse_output=False) # Important for handling unseen categories
|
| 42 |
+
|
| 43 |
+
# You MUST use the *trained* encoder to transform the new data
|
| 44 |
+
encoded_new_data = encoder.transform(input_data[['Product_Sugar_Content','Product_Type','Store_Id','Store_Size','Store_Location_City_Type','Store_Type']])
|
| 45 |
+
|
| 46 |
# Make a churn prediction using the trained model
|
| 47 |
+
prediction = model.predict(encoded_new_data).tolist()[0]
|
| 48 |
|
| 49 |
#Calculate the actual price
|
| 50 |
predicted_sales = np.exp(prediction)
|
| 51 |
|
| 52 |
# Convert predicted_price to Python float
|
| 53 |
predicted_sales = round(float(predicted_sales), 2)
|
| 54 |
+
|
| 55 |
# Return the prediction as a JSON response
|
| 56 |
return jsonify({'Predicted_Sale': predicted_sales})
|