Spaces:
Sleeping
Sleeping
import pickle as pkl | |
import streamlit as st | |
from sklearn.linear_model import LinearRegression | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
# loading the data | |
df = pd.read_csv('housing.csv') | |
df.rename(columns = {'Avg. Area Income':'Income','Avg. Area House Age':'House_age', 'Avg. Area Number of Rooms':'No_rooms', | |
'Avg. Area Number of Bedrooms':'No_bedrooms', 'Area Population':'population'},inplace = True) | |
# we will drop number of bedrooms column from the dataset | |
df.drop(columns= ['No_bedrooms'],inplace=True) | |
X_train,X_test,y_train,y_test = train_test_split(df.drop(columns =['Price']), | |
df['Price'], | |
test_size = 0.2, | |
random_state =2) | |
#model building | |
from sklearn.linear_model import LinearRegression | |
lr = LinearRegression() | |
# training the model or fitting the model | |
lr.fit(X_train,y_train) | |
# FUNCTION | |
def user_report(): | |
Income = st.sidebar.slider('Income', 50000,107701, 58000 ) | |
House_age = st.sidebar.slider('House_age', 2,10, 4 ) | |
No_rooms = st.sidebar.slider('No_rooms', 3,11, 5 ) | |
population = st.sidebar.slider('population', 30000,70000, 50000 ) | |
user_report_data = { | |
'Income':Income, | |
'House_age':House_age, | |
'No_rooms':No_rooms, | |
'population':population | |
} | |
report_data = pd.DataFrame(user_report_data, index=[0]) | |
return report_data | |
# Housing Data | |
user_data = user_report() | |
st.subheader('Housing Data') | |
st.write(user_data) | |
# MODEL | |
user_result = lr.predict(user_data) | |
# VISUALISATIONS | |
st.title('Visualised Housing Data') | |
# COLOR FUNCTION | |
if user_result[0]==0: | |
color = 'blue' | |
else: | |
color = 'red' | |
# OUTPUT | |
st.subheader('Price of House is : ') | |
st.write(str(user_result)) | |