Data Analyzing AI Web App
Data Analyzing AI Web App
This document contains the complete code for building a Data Analyzing AI Web App using Flask
1. Data Preprocessing
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
# Load dataset
df = pd.read_csv("data.csv")
# Normalize data
scaler = MinMaxScaler()
df_scaled = scaler.fit_transform(df)
# Save model
import pickle
pickle.dump(model, open("model.pkl", "wb"))
app = Flask(__name__)
@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)
<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.