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