Jurk06's picture
Update app.py
797c493 verified
raw
history blame
2.12 kB
# prompt: make a web app for house price using Deep Learning ang and dashbording using Gradio
#!pip install scikit-learn --upgrade
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import mean_squared_error
import gradio as gr
# ... (Rest of your code)
# Load the dataset
df = pd.read_csv('california_housing_train.csv')
# Select features and target
features = df[['longitude', 'latitude', 'housing_median_age', 'total_rooms',
'total_bedrooms', 'population', 'households', 'median_income']]
target = df['median_house_value']
# Split the data
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42)
# Standardize the data
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Train the model
model = MLPRegressor(hidden_layer_sizes=(100,), activation='relu', solver='adam', max_iter=1000)
model.fit(X_train_scaled, y_train)
# Evaluate the model
predictions = model.predict(X_test_scaled)
mse = mean_squared_error(y_test, predictions)
print(f'Mean Squared Error: {mse}')
# Create Gradio interface
def predict_house_price(longitude, latitude, housing_median_age, total_rooms,
total_bedrooms, population, households, median_income):
input_data = scaler.transform([[longitude, latitude, housing_median_age, total_rooms,
total_bedrooms, population, households, median_income]])
prediction = model.predict(input_data)[0]
return prediction
iface = gr.Interface(
fn=predict_house_price,
inputs=[
gr.Number(label="Longitude"), # Use gr.Number directly
gr.Number(label="Latitude"),
gr.Number(label="Housing Median Age"),
gr.Number(label="Total Rooms"),
gr.Number(label="Total Bedrooms"),
gr.Number(label="Population"),
gr.Number(label="Households"),
gr.Number(label="Median Income"),
],
outputs="text",
title="House Price Prediction",
description="Enter the features to get the predicted house price."
)
iface.launch()