Spaces:
Sleeping
Sleeping
File size: 2,013 Bytes
1a9845c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.linear_model import LinearRegression
import gradio as gr
longitude = gr.inputs.Textbox(label = "Longitude")
latitude = gr.inputs.Textbox(label = "Latitude")
housing_median_age = gr.inputs.Textbox(label = "Housing median age")
total_rooms = gr.inputs.Textbox(label = "total rooms")
total_bedrooms = gr.inputs.Textbox(label = "total bedrooms")
population = gr.inputs.Textbox(label = "population")
households = gr.inputs.Textbox(label = "housholds")
median_income = gr.inputs.Textbox(label = "median income")
output_house_value = gr.inputs.Textbox(label = "predicted house value")
def process_function(longitude,latitude,housing_medain_age,total_rooms,total_bedrooms,population,households,median_income):
housing=pd.read_csv('/content/drive/MyDrive/housing.csv')
train_set, test_set = train_test_split(housing, test_size=0.2, random_state=10)
train_set_clean = train_set.dropna(subset=["total_bedrooms"])
train_labels = train_set_clean["median_house_value"].copy()
train_features = train_set_clean.drop("median_house_value", axis=1)
scaler = MinMaxScaler()
scaler.fit(train_features)
train_features_normalized = scaler.transform(train_features)
lin_reg=LinearRegression()
lin_reg.fir(train_features_normalized,train_labels)
new_features=np.array([[longitude,latitude,housing_medain_age,total_rooms,population,households,median_income]])
new_features_normalized=scaler.transform(new_features)
output_house_value=lin_reg.predict(new_features_normalized)
return output_house_value
myexamples=[["-116.52", "33.82", "21.0", "10227.0", "2315.0", "3623.0","1734.0", "2.5212"]]
iface = gr.Interface(
fn=process_function,
inputs=[longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income],
outputs=output_house_value,
examples=myexamples,
)
iface.launch(share=True, debug=True) |