CoolFace
Apppublic

aaronbi/Lab04

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app.py38 linesDownload Raw Back to root
1import gradio as gr2import pandas as pd3import numpy as np4 5housing = pd.read_csv("housing.csv")6 7from sklearn.model_selection import train_test_split8train_set, test_set = train_test_split(housing, test_size=0.2, random_state=10)9 10train_set_clean = train_set.dropna(subset=["total_bedrooms"])11 12train_labels = train_set_clean["median_house_value"].copy() # get labels for output label Y13train_features = train_set_clean.drop("median_house_value", axis=1) # drop labels to get features X for training set14 15#print(train_features.info())16#print(train_features.describe())17 18from sklearn.linear_model import LinearRegression ## import the LinearRegression Function19lin_reg = LinearRegression() ## Initialize the class20lin_reg.fit(train_features, train_labels) # feed the training data X, and label Y for supervised learning21 22f1 = gr.Slider(-124, -114, step=1, label = "Longitude")23f2 = gr.Slider(32, 41, step=1, label = "Latitude")24f3 = gr.Slider(1, 52, step=1, label = "Housing Median Age")25f4 = gr.Slider(2, 15000, step=1, label = "Total Rooms")26f5 = gr.Slider(1, 3000, step=1, label = "Total Bedrooms")27f6 = gr.Slider(3, 10000, step=1, label = "Population")28f7 = gr.Slider(1,  3000, step=1, label = "Households")29f8 = gr.Slider(0, 15, step=1, label = "Median Income")30 31out_mod = gr.Number(label = "Median House Value")32 33def predict(f1,f2,f3,f4,f5,f6,f7,f8):34  return lin_reg.predict([[f1,f2,f3,f4,f5,f6,f7,f8]])35 36 37gr.Interface(fn=predict, inputs=[f1,f2,f3,f4,f5,f6,f7,f8], outputs=out_mod,examples = [[-122,38,27,8986,1365,7870,1667,10], [-120,40,30,10986,800,3000,1007,6]]).launch(debug=True)38