Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| from sklearn.model_selection import train_test_split | |
| housing = pd.read_csv("housing.csv") | |
| train_set, test_set = train_test_split(housing, test_size=0.2, random_state=10) | |
| ## 2. clean the missing values | |
| train_set_clean = train_set.dropna(subset=["total_bedrooms"]) | |
| train_set_clean | |
| ## 2. derive training features and training labels | |
| train_labels = train_set_clean["median_house_value"].copy() # get labels for output label Y | |
| train_features = train_set_clean.drop("median_house_value", axis=1) # drop labels to get features X for training set | |
| ## 4. scale the numeric features in training set | |
| from sklearn.preprocessing import MinMaxScaler | |
| scaler = MinMaxScaler() ## define the transformer | |
| scaler.fit(train_features) ## call .fit() method to calculate the min and max value for each column in dataset | |
| train_features_normalized = scaler.transform(train_features) | |
| train_features_normalized | |
| from sklearn.linear_model import LinearRegression ## import the LinearRegression Function | |
| lin_reg = LinearRegression() ## Initialize the class | |
| lin_reg.fit(train_features_normalized, train_labels) # feed the training data X, and label Y for supervised learning | |
| import numpy as np | |
| def predict_price(input1, input2, input3, input4, input5, input6, input7, input8): | |
| features = np.array([[float(input1), float(input2), float(input3), float(input4), float(input5), float(input6), float(input7), float(input8)]]) | |
| print("recived features are: ", features) | |
| price = lin_reg.predict(features) | |
| return price | |
| input_module1 = gr.inputs.Textbox(label = "Input Feature 1") | |
| input_module2 = gr.inputs.Textbox(label = "Input Feature 2") | |
| input_module3 = gr.inputs.Textbox(label = "Input Feature 3") | |
| input_module4 = gr.inputs.Textbox(label = "Input Feature 4") | |
| input_module5 = gr.inputs.Textbox(label = "Input Feature 5") | |
| input_module6 = gr.inputs.Textbox(label = "Input Feature 6") | |
| input_module7 = gr.inputs.Textbox(label = "Input Feature 7") | |
| input_module8 = gr.inputs.Textbox(label = "Input Feature 8") | |
| output_module1 = gr.outputs.Textbox(label = "Output Text") | |
| gr.Interface(fn=predict_price, | |
| inputs=[input_module1, input_module2, input_module3, | |
| input_module4, input_module5, input_module6, | |
| input_module7, input_module8], | |
| outputs=[output_module1] | |
| ).launch() | |