CodingBuddy commited on
Commit
97e0dae
·
verified ·
1 Parent(s): 6e01b8a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +8 -2
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(input_data).tolist()[0]
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})