Spaces:
Sleeping
Sleeping
abhinav kumar commited on
Commit ·
06b991f
1
Parent(s): 3c22404
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
from sklearn.model_selection import train_test_split
|
| 6 |
+
|
| 7 |
+
housing = pd.read_csv("housing.csv")
|
| 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 |
+
|
| 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 |
+
|
| 31 |
+
import numpy as np
|
| 32 |
+
def predict_price(input1, input2, input3, input4, input5, input6, input7, input8):
|
| 33 |
+
features = np.array([[float(input1), float(input2), float(input3), float(input4), float(input5), float(input6), float(input7), float(input8)]])
|
| 34 |
+
print("recived features are: ", features)
|
| 35 |
+
price = lin_reg.predict(features)
|
| 36 |
+
return price
|
| 37 |
+
|
| 38 |
+
input_module1 = gr.inputs.Textbox(label = "Input Feature 1")
|
| 39 |
+
input_module2 = gr.inputs.Textbox(label = "Input Feature 2")
|
| 40 |
+
input_module3 = gr.inputs.Textbox(label = "Input Feature 3")
|
| 41 |
+
input_module4 = gr.inputs.Textbox(label = "Input Feature 4")
|
| 42 |
+
input_module5 = gr.inputs.Textbox(label = "Input Feature 5")
|
| 43 |
+
input_module6 = gr.inputs.Textbox(label = "Input Feature 6")
|
| 44 |
+
input_module7 = gr.inputs.Textbox(label = "Input Feature 7")
|
| 45 |
+
input_module8 = gr.inputs.Textbox(label = "Input Feature 8")
|
| 46 |
+
|
| 47 |
+
output_module1 = gr.outputs.Textbox(label = "Output Text")
|
| 48 |
+
|
| 49 |
+
gr.Interface(fn=predict_price,
|
| 50 |
+
inputs=[input_module1, input_module2, input_module3,
|
| 51 |
+
input_module4, input_module5, input_module6,
|
| 52 |
+
input_module7, input_module8],
|
| 53 |
+
outputs=[output_module1]
|
| 54 |
+
).launch()
|