0% found this document useful (0 votes)
10 views3 pages

Data Analyzing AI Web App

The document provides a complete guide for building a Data Analyzing AI Web App using Flask and Machine Learning. It includes sections on data preprocessing, training a machine learning model, creating a Flask backend API, and developing a frontend with HTML and JavaScript. Additionally, it offers deployment instructions for various platforms like Render, Heroku, and AWS.

Uploaded by

ps7271159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Data Analyzing AI Web App

The document provides a complete guide for building a Data Analyzing AI Web App using Flask and Machine Learning. It includes sections on data preprocessing, training a machine learning model, creating a Flask backend API, and developing a frontend with HTML and JavaScript. Additionally, it offers deployment instructions for various platforms like Render, Heroku, and AWS.

Uploaded by

ps7271159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Data Analyzing AI Web App

This document contains the complete code for building a Data Analyzing AI Web App using Flask

and Machine Learning.

1. Data Preprocessing
import pandas as pd
from sklearn.preprocessing import MinMaxScaler

# Load dataset
df = pd.read_csv("data.csv")

# Handle missing values


df = df.dropna()

# Normalize data
scaler = MinMaxScaler()
df_scaled = scaler.fit_transform(df)

2. Train Machine Learning Model


from sklearn.linear_model import LinearRegression

# Train a simple model


model = LinearRegression()
X = df[['feature1', 'feature2']] # Independent variables
y = df['target'] # Dependent variable
model.fit(X, y)

# Save model
import pickle
pickle.dump(model, open("model.pkl", "wb"))

3. Flask Backend API


from flask import Flask, request, jsonify
import pickle
import numpy as np

app = Flask(__name__)

# Load trained model


model = pickle.load(open("model.pkl", "rb"))

@app.route('/predict', methods=['POST'])
def predict():
data = request.json['data']
prediction = model.predict(np.array(data).reshape(1, -1))
return jsonify({"prediction": prediction.tolist()})

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

4. Frontend (HTML + JavaScript)


<input type="text" id="inputData" placeholder="Enter Data">
<button onclick="analyzeData()">Analyze</button>
<p id="result"></p>

<script>
function analyzeData() {
let inputData = document.getElementById("inputData").value;

fetch("http://localhost:5000/predict", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ data: [parseFloat(inputData)] })
})
.then(response => response.json())
.then(data => document.getElementById("result").innerText = "Prediction: " + data.prediction);
}
</script>

5. Deployment Instructions
To deploy the Flask API, use Render, Heroku, or AWS. For frontend, use Netlify or Vercel.

You might also like