|
import pandas as pd |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.preprocessing import StandardScaler |
|
from sklearn.linear_model import LinearRegression |
|
from sklearn.metrics import mean_squared_error |
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
df = pd.read_csv('california_housing_train.csv') |
|
|
|
col=['population', 'households', 'median_income'] |
|
|
|
|
|
features = df[col] |
|
target = df['median_house_value'] |
|
|
|
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42) |
|
|
|
|
|
scaler = StandardScaler() |
|
X_train_scaled = scaler.fit_transform(X_train) |
|
X_test_scaled = scaler.transform(X_test) |
|
|
|
|
|
model = LinearRegression() |
|
model.fit(X_train_scaled, y_train) |
|
|
|
|
|
predictions = model.predict(X_test_scaled) |
|
mse = mean_squared_error(y_test, predictions) |
|
print(f'Mean Squared Error: {mse}') |
|
|
|
|
|
def predict_house_price(feature1, feature2, feature3): |
|
input_data = scaler.transform([[feature1, feature2, feature3]]) |
|
prediction = model.predict(input_data) |
|
return prediction[0] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_house_price, |
|
inputs=[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() |