soham901 commited on
Commit
b59614d
1 Parent(s): 15519a4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. model.py +34 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import model as ml
2
+
3
+ import streamlit as st
4
+
5
+
6
+ st.title("House Price Prediction")
7
+ st.markdown("### Enter the details of the house to get the price prediction")
8
+
9
+ sqft = st.number_input("Square Feet")
10
+
11
+ if st.button("Predict"):
12
+ price = ml.predict(sqft)
13
+ st.success(f"The price of the house will be {price}")
14
+
15
+
16
+ st.divider()
17
+
18
+
19
+ st.subheader("About")
20
+
21
+ st.write("This is a simple web app to predict the price of the house based on the square feet. I used only 10 data points to train the model. So, the predictions may not be accurate. The model used is Linear Regression. Purpose of this project is to learn how to deploy a machine learning model.")
22
+ st.write("Built by [Soham Sagathiya](https://soham901.vercel.app)")
23
+
24
+ with st.expander("Model Performance"):
25
+ data = ml.get_model_details()
26
+ st.write(f"Score: {data['score']}")
27
+ st.write(f"MSE: {data['mse']}")
28
+ st.write(f"Coefficient: {data['coef']}")
29
+ st.write(f"Intercept: {data['intercept']}")
model.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sklearn.linear_model import LinearRegression
2
+ from sklearn.model_selection import train_test_split
3
+ from sklearn.metrics import mean_squared_error
4
+ import numpy as np
5
+
6
+ # Create a small dataset with 10 rows representing house prices
7
+ X = np.array([[1000], [1500], [2000], [2500], [3000], [3500], [4000], [4500], [5000], [5500]])
8
+ y = np.array([50000, 75000, 100000, 125000, 150000, 175000, 200000, 225000, 250000, 275000])
9
+
10
+ # Split the dataset into training and testing sets
11
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
12
+
13
+ # Create an instance of the Linear Regression model
14
+ model = LinearRegression()
15
+
16
+ # Train the model on the training data
17
+ model.fit(X_train, y_train)
18
+
19
+ # Make predictions on the testing data
20
+ y_pred = model.predict(X_test)
21
+
22
+ # Evaluate the model's performance
23
+ mse = mean_squared_error(y_test, y_pred)
24
+ coef = model.coef_[0]
25
+ intercept = model.intercept_
26
+ score = model.score(X_test, y_test)
27
+
28
+
29
+ def predict(sqft):
30
+ return (model.predict([[sqft]])[0]).round(2)
31
+
32
+
33
+ def get_model_details():
34
+ return {"mse": mse, "coef": coef, "intercept": intercept, "score": score}