Spaces:
Sleeping
Sleeping
Praneeth383
commited on
Commit
•
4184a3b
1
Parent(s):
7afdb25
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def house_price_prediction(ft1,ft2,ft3,ft4,ft5,ft6,ft7,ft8):
|
2 |
+
# output=1
|
3 |
+
import pandas as pd
|
4 |
+
housing=pd.read_csv("/content/drive/MyDrive/Colab Notebooks/lab 03/housing.csv")
|
5 |
+
|
6 |
+
## 1. split data to get train and test set
|
7 |
+
from sklearn.model_selection import train_test_split
|
8 |
+
train_set, test_set = train_test_split(housing, test_size=0.2, random_state=10)
|
9 |
+
|
10 |
+
## 2. clean the missing values
|
11 |
+
train_set_clean = train_set.dropna(subset=["total_bedrooms"])
|
12 |
+
train_set_clean
|
13 |
+
|
14 |
+
## 2. derive training features and training labels
|
15 |
+
train_labels = train_set_clean["median_house_value"].copy() # get labels for output label Y
|
16 |
+
train_features = train_set_clean.drop("median_house_value", axis=1) # drop labels to get features X for training set
|
17 |
+
|
18 |
+
|
19 |
+
## 4. scale the numeric features in training set
|
20 |
+
from sklearn.preprocessing import MinMaxScaler
|
21 |
+
scaler = MinMaxScaler() ## define the transformer
|
22 |
+
scaler.fit(train_features) ## call .fit() method to calculate the min and max value for each column in dataset
|
23 |
+
|
24 |
+
train_features_normalized = scaler.transform(train_features)
|
25 |
+
train_features_normalized
|
26 |
+
#model training
|
27 |
+
from sklearn.linear_model import LinearRegression ## import the LinearRegression Function
|
28 |
+
lin_reg = LinearRegression() ## Initialize the class
|
29 |
+
lin_reg.fit(train_features_normalized, train_labels) # feed the training data X, and label Y for supervised learning
|
30 |
+
#model prediction
|
31 |
+
import numpy as np
|
32 |
+
test_features=np.array([[ft1,ft2,ft3,ft4,ft5,ft6,ft7,ft8]])
|
33 |
+
training_predictions = lin_reg.predict(test_features)
|
34 |
+
return training_predictions
|
35 |
+
|
36 |
+
#return output
|
37 |
+
|
38 |
+
|
39 |
+
import gradio as gr
|
40 |
+
|
41 |
+
ip1 = gr.inputs.Slider(-124.35, -114.35, step=5, label = "Longitude")
|
42 |
+
ip2 = gr.inputs.Slider(32,41, step=5, label = "Latitude")
|
43 |
+
ip3 = gr.inputs.Slider(1,52, step=5, label = "Housing_median_age (Year)")
|
44 |
+
ip4 = gr.inputs.Slider(1,39996, step=5, label = "Total_rooms")
|
45 |
+
ip5 = gr.inputs.Slider(1,6441, step=5, label = "Total_bedrooms")
|
46 |
+
ip6 = gr.inputs.Slider(3,35678, step=5, label = "Population")
|
47 |
+
ip7 = gr.inputs.Slider(1,6081, step=5, label = "Households")
|
48 |
+
ip8 = gr.inputs.Slider(0,15, step=5, label = "Median_income")
|
49 |
+
op_module = gr.outputs.Textbox(label = "Output")
|
50 |
+
|
51 |
+
gr.Interface(fn=house_price_prediction,
|
52 |
+
inputs=[ip1, ip2, ip3,
|
53 |
+
ip4, ip5, ip6,
|
54 |
+
ip7,ip8],
|
55 |
+
outputs=[op_module]
|
56 |
+
).launch(debug= True)
|
57 |
+
op_module = gr.outputs.Textbox(label = "Output")
|