albedan commited on
Commit
04e5e90
1 Parent(s): 15a5f89

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import xgboost as xgb
2
+ import pandas as pd
3
+ import gradio as gr
4
+
5
+ from sklearn.model_selection import train_test_split
6
+ train = pd.read_csv('/content/sample_data/california_housing_train.csv', nrows = 10000)
7
+ train['total_bedrooms'].fillna(train['total_bedrooms'].mean(), inplace=True)
8
+ train.drop('households', axis=1, inplace=True)
9
+ train.drop('total_rooms', axis=1, inplace=True)
10
+ train.drop('total_bedrooms', axis=1, inplace=True)
11
+ train=train.loc[train['median_house_value']<=500000,:]
12
+
13
+ X=train[['longitude',
14
+ 'latitude',
15
+ 'housing_median_age',
16
+ 'population',
17
+ 'median_income']]
18
+ Y=train['median_house_value']
19
+
20
+ X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.2, random_state=0)
21
+
22
+ xg_reg = xgb.XGBRegressor(objective ='reg:squarederror', eta=0.03, max_depth = 5, n_estimators = 200)
23
+ xg_reg.fit(X_train,Y_train)
24
+
25
+ def pred_house(longitude,latitude,housing_median_age,population,median_income):
26
+ to_predict = pd.DataFrame({'longitude': [longitude],
27
+ 'latitude': [latitude],
28
+ 'housing_median_age': [housing_median_age],
29
+ 'population': [population],
30
+ 'median_income': [median_income]})
31
+ return round(xg_reg.predict(to_predict)[0],2)
32
+
33
+ demo = gr.Interface(
34
+ fn=pred_house,
35
+ inputs=[gr.Slider(-120, -114), gr.Slider(32, 39), gr.Slider(0, 50), "number", "number", ],
36
+ outputs="number",
37
+ )
38
+ demo.launch()