0
0
ML Pythonml~20 mins

Why deployment delivers value in ML Python - Experiment to Prove It

Choose your learning style9 modes available
Experiment - Why deployment delivers value
Problem:You have built a machine learning model that predicts house prices with good accuracy on your test data. However, the model is only on your computer and not used by anyone.
Current Metrics:Test accuracy: 85%, Model is not deployed
Issue:The model's value is limited because it is not accessible to users or integrated into real-world applications.
Your Task
Deploy the trained model so that users can input house features and get price predictions, demonstrating how deployment delivers real value.
Use a simple web API or interface for deployment
Do not change the model architecture or retrain the model
Hint 1
Hint 2
Hint 3
Solution
ML Python
from flask import Flask, request, jsonify
import numpy as np
import pickle

# Load the trained model
with open('house_price_model.pkl', 'rb') as f:
    model = pickle.load(f)

app = Flask(__name__)

@app.route('/predict', methods=['POST'])
def predict():
    data = request.json
    # Extract features from JSON input
    features = np.array([data['features']])
    # Predict using the loaded model
    prediction = model.predict(features)
    # Return prediction as JSON
    return jsonify({'predicted_price': float(prediction[0])})

if __name__ == '__main__':
    app.run(debug=True)
Created a Flask web API to serve the model
Added a /predict endpoint that accepts JSON input with house features
Returned the model's prediction as JSON output
Results Interpretation

Before deployment: Model accuracy 85%, but no user access.

After deployment: Same accuracy 85%, but users can send data and get predictions instantly through the API.

Deployment turns a working model into a useful tool by making it accessible and usable in real situations, delivering real value beyond just good accuracy.
Bonus Experiment
Add a simple web page that lets users enter house features and see the predicted price using the deployed API.
💡 Hint
Use HTML and JavaScript fetch to send input data to the API and display the prediction on the page.