Close Menu
    Trending
    • You’re Only Three Weeks Away From Reaching International Clients, Partners, and Customers
    • How Brain-Computer Interfaces Are Changing the Game | by Rahul Mishra | Coding Nexus | Jun, 2025
    • How Diverse Leadership Gives You a Big Competitive Advantage
    • Making Sense of Metrics in Recommender Systems | by George Perakis | Jun, 2025
    • AMD Announces New GPUs, Development Platform, Rack Scale Architecture
    • The Hidden Risk That Crashes Startups — Even the Profitable Ones
    • Systematic Hedging Of An Equity Portfolio With Short-Selling Strategies Based On The VIX | by Domenico D’Errico | Jun, 2025
    • AMD CEO Claims New AI Chips ‘Outperform’ Nvidia’s
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»Deploying a Production-Ready AI Model — Titanic Survival Predictor | by Akhilesh Veerapareddy | Feb, 2025
    Machine Learning

    Deploying a Production-Ready AI Model — Titanic Survival Predictor | by Akhilesh Veerapareddy | Feb, 2025

    FinanceStarGateBy FinanceStarGateFebruary 24, 2025No Comments2 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    1. Coaching the Machine Studying Mannequin

    Step one was to scrub and preprocess the Titanic dataset and prepare a machine studying mannequin:

    import pandas as pd
    from sklearn.model_selection import train_test_split
    from sklearn.linear_model import LogisticRegression
    from sklearn.metrics import accuracy_score

    # Load dataset
    df = pd.read_csv("titanic.csv")
    df = df.drop(columns=["Cabin", "Name", "Ticket"])

    df = pd.get_dummies(df, columns=["Sex", "Embarked"], drop_first=True)

    # Cut up options and labels
    X = df.drop("Survived", axis=1)
    y = df["Survived"]

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

    # Practice mannequin
    mannequin = LogisticRegression(max_iter=1000)
    mannequin.match(X_train, y_train)

    # Consider mannequin
    y_pred = mannequin.predict(X_test)
    print("Mannequin Accuracy:", accuracy_score(y_test, y_pred))

    2. Serving the Mannequin as a Flask API

    As soon as the mannequin was skilled, the following step was to make it accessible via a REST API:

    from flask import Flask, request, jsonify
    import joblib
    import numpy as np
    from flask_cors import CORS

    app = Flask(__name__)
    CORS(app)

    # Load skilled mannequin
    mannequin = joblib.load("mannequin/titanic_model.pkl")

    @app.route("/predict", strategies=["POST"])
    def predict():
    knowledge = request.get_json()
    options = np.array([[data["Pclass"], knowledge["Sex"], knowledge["Age"], knowledge["SibSp"], knowledge["Parch"], knowledge["Fare"], knowledge["Embarked_Q"], knowledge["Embarked_S"]]])
    likelihood = mannequin.predict_proba(options)[0][1]
    prediction = "Survived" if likelihood > 0.5 else "Did Not Survive"
    return jsonify({"prediction": prediction, "likelihood": spherical(likelihood * 100, 2)})

    if __name__ == "__main__":
    app.run(debug=True)

    3. Making a Trendy UI for Predictions

    A React frontend was constructed to work together with the API and show predictions in a wealthy, user-friendly interface:

    import { useState } from "react";
    import { ChakraProvider, Field, Button, Enter, Choose, Textual content, VStack } from "@chakra-ui/react";
    import axios from "axios";

    const API_URL = "https://your-api.onrender.com/predict";

    perform App() {
    const [formData, setFormData] = useState({ Pclass: "3", Intercourse: "male", Age: "", SibSp: "0", Parch: "0", Fare: "", Embarked: "S" });
    const [prediction, setPrediction] = useState(null);

    const handleSubmit = async (e) => {
    e.preventDefault();
    const payload = { ...formData, Intercourse: formData.Intercourse === "feminine" ? 1 : 0 };
    const res = await axios.submit(API_URL, payload);
    setPrediction(res.knowledge);
    };

    return (


    Titanic Survival Predictor


    setFormData({ ...formData, Age: e.goal.worth })} required />

    {prediction && {prediction.prediction} ({prediction.likelihood}%)}



    );
    }
    export default App;

    3. Undertaking Hyperlinks

    This enhanced Medium submit now offers a detailed, partaking walkthrough that showcases each the technical depth and deployment points of the mission.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleThis Is the Real Secret to Exceeding Your Customer’s Expectations
    Next Article 6 Common LLM Customization Strategies Briefly Explained
    FinanceStarGate

    Related Posts

    Machine Learning

    How Brain-Computer Interfaces Are Changing the Game | by Rahul Mishra | Coding Nexus | Jun, 2025

    June 14, 2025
    Machine Learning

    Making Sense of Metrics in Recommender Systems | by George Perakis | Jun, 2025

    June 14, 2025
    Machine Learning

    Systematic Hedging Of An Equity Portfolio With Short-Selling Strategies Based On The VIX | by Domenico D’Errico | Jun, 2025

    June 14, 2025
    Add A Comment

    Comments are closed.

    Top Posts

    On-Device Machine Learning in Spatial Computing

    February 17, 2025

    The AI Playbook Billion-Dollar Brands Are Using to Automate & Dominate (And How You Can Too)

    April 12, 2025

    ‘Plug, Baby, Plug’: France to Use Nuclear Power to Expand its AI Computing Capacity

    February 12, 2025

    Understanding the Power of Sequence-to-Sequence Models in NLP | by Faizan Saleem Siddiqui | Mar, 2025

    March 20, 2025

    Audio Spectrogram Transformers Beyond the Lab

    June 10, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    Toward AGI: AI Innovation Will Be Driven by Applications, Not LLMs

    February 14, 2025

    Daniela Rus wins John Scott Award | MIT News

    February 15, 2025

    Tariffs are a tax and the impact is broader than high prices

    March 11, 2025
    Our Picks

    TL;DW (YouTube Learning Aid). Introduction | by Diya Saha | Apr, 2025

    April 11, 2025

    10 Highest-Paying, ‘Little-to-No-Experience’ Side Hustles

    March 4, 2025

    Microsoft’s Majorana 1: The Breakthrough That Could Change Quantum Computing Forever ( A Complete Guide) | by 7William | Feb, 2025

    February 23, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 Financestargate.com All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.