import gradio as gr import pandas as pd import numpy as np housing = pd.read_csv("housing.csv") from sklearn.model_selection import train_test_split train_set, test_set = train_test_split(housing, test_size=0.2, random_state=10) train_set_clean = train_set.dropna(subset=["total_bedrooms"]) 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 #print(train_features.info()) #print(train_features.describe()) from sklearn.linear_model import LinearRegression ## import the LinearRegression Function lin_reg = LinearRegression() ## Initialize the class lin_reg.fit(train_features, train_labels) # feed the training data X, and label Y for supervised learning f1 = gr.Slider(-124, -114, step=1, label = "Longitude") f2 = gr.Slider(32, 41, step=1, label = "Latitude") f3 = gr.Slider(1, 52, step=1, label = "Housing Median Age") f4 = gr.Slider(2, 15000, step=1, label = "Total Rooms") f5 = gr.Slider(1, 3000, step=1, label = "Total Bedrooms") f6 = gr.Slider(3, 10000, step=1, label = "Population") f7 = gr.Slider(1, 3000, step=1, label = "Households") f8 = gr.Slider(0, 15, step=1, label = "Median Income") out_mod = gr.Number(label = "Median House Value") def predict(f1,f2,f3,f4,f5,f6,f7,f8): return lin_reg.predict([[f1,f2,f3,f4,f5,f6,f7,f8]]) gr.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)