Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# prompt: make a web app for house price using Deep Learning ang and dashbording using Gradio
|
| 2 |
+
#!pip install scikit-learn --upgrade
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
from sklearn.preprocessing import StandardScaler
|
| 6 |
+
from sklearn.neural_network import MLPRegressor
|
| 7 |
+
from sklearn.metrics import mean_squared_error
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
# ... (Rest of your code)
|
| 11 |
+
# Load the dataset
|
| 12 |
+
df = pd.read_csv('/content/sample_data/california_housing_train.csv')
|
| 13 |
+
|
| 14 |
+
# Select features and target
|
| 15 |
+
features = df[['longitude', 'latitude', 'housing_median_age', 'total_rooms',
|
| 16 |
+
'total_bedrooms', 'population', 'households', 'median_income']]
|
| 17 |
+
target = df['median_house_value']
|
| 18 |
+
|
| 19 |
+
# Split the data
|
| 20 |
+
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42)
|
| 21 |
+
|
| 22 |
+
# Standardize the data
|
| 23 |
+
scaler = StandardScaler()
|
| 24 |
+
X_train_scaled = scaler.fit_transform(X_train)
|
| 25 |
+
X_test_scaled = scaler.transform(X_test)
|
| 26 |
+
|
| 27 |
+
# Train the model
|
| 28 |
+
model = MLPRegressor(hidden_layer_sizes=(100,), activation='relu', solver='adam', max_iter=1000)
|
| 29 |
+
model.fit(X_train_scaled, y_train)
|
| 30 |
+
|
| 31 |
+
# Evaluate the model
|
| 32 |
+
predictions = model.predict(X_test_scaled)
|
| 33 |
+
mse = mean_squared_error(y_test, predictions)
|
| 34 |
+
print(f'Mean Squared Error: {mse}')
|
| 35 |
+
|
| 36 |
+
# Create Gradio interface
|
| 37 |
+
def predict_house_price(longitude, latitude, housing_median_age, total_rooms,
|
| 38 |
+
total_bedrooms, population, households, median_income):
|
| 39 |
+
input_data = scaler.transform([[longitude, latitude, housing_median_age, total_rooms,
|
| 40 |
+
total_bedrooms, population, households, median_income]])
|
| 41 |
+
prediction = model.predict(input_data)[0]
|
| 42 |
+
return prediction
|
| 43 |
+
|
| 44 |
+
iface = gr.Interface(
|
| 45 |
+
fn=predict_house_price,
|
| 46 |
+
inputs=[
|
| 47 |
+
gr.Number(label="Longitude"), # Use gr.Number directly
|
| 48 |
+
gr.Number(label="Latitude"),
|
| 49 |
+
gr.Number(label="Housing Median Age"),
|
| 50 |
+
gr.Number(label="Total Rooms"),
|
| 51 |
+
gr.Number(label="Total Bedrooms"),
|
| 52 |
+
gr.Number(label="Population"),
|
| 53 |
+
gr.Number(label="Households"),
|
| 54 |
+
gr.Number(label="Median Income"),
|
| 55 |
+
],
|
| 56 |
+
outputs="text",
|
| 57 |
+
title="House Price Prediction",
|
| 58 |
+
description="Enter the features to get the predicted house price."
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
iface.launch()
|