File size: 1,907 Bytes
e96b3e5
 
 
 
 
 
 
 
0f48ef3
e96b3e5
 
 
 
 
 
 
 
 
 
7feb426
e96b3e5
 
 
7feb426
 
 
 
 
 
 
 
 
 
e96b3e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import joblib
import pandas as pd
from flask import Flask, request, jsonify

# Initialize Flask app with a name
sales_revenue_predictor_api = Flask("Product Sales Revenue Predictor")

# Load the trained churn prediction model
model = joblib.load("product_sales_revenue_prediction_model_v1_0.joblib")

# Define a route for the home page
@sales_revenue_predictor_api.get('/')
def home():
    return "Welcome to the Product Sales Revenue Prediction API"

# Define an endpoint to predict churn for a single customer
@sales_revenue_predictor_api.post('/v1/product_sales_revenue')
def predict_churn():
    # Get JSON data from the request
    product_data = request.get_json()

    # Extract relevant customer features from the input data
    sample = {
        'Product_Weight': product_data.get('Product_Weight'),
        'Product_Sugar_Content': product_data.get('Product_Sugar_Content'),
        'Product_Allocated_Area': product_data.get('Product_Allocated_Area'),
        'Product_Type': product_data.get('Product_Type'),
        'Product_MRP': product_data.get('Product_MRP'),
        'Store_Id': product_data.get('Store_Id'),
        'Store_Establishment_Year': product_data.get('Store_Establishment_Year'),
        'Store_Size': product_data.get('Store_Size'),
        'Store_Location_City_Type': product_data.get('Store_Location_City_Type'),
        'Store_Type': product_data.get('Store_Type')
    }

    # Convert the extracted data into a DataFrame
    input_data = pd.DataFrame([sample])

    # Make a churn prediction using the trained model
    predicted_sales = model.predict(input_data).tolist()[0]

    # Convert predicted_price to Python float
    predicted_sales = round(float(predicted_sales), 2)
    

    # Return the prediction as a JSON response
    return jsonify({'Prediction': predicted_sales})

 

# Run the Flask app in debug mode
if __name__ == '__main__':
    app.run(debug=True)