DOMMETI commited on
Commit
8ff2368
·
verified ·
1 Parent(s): ba3b03e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import streamlit as st
2
  import numpy as np
3
  import pickle
4
- import pandas as pd
5
- from sklearn.preprocessing import OneHotEncoder
6
  from sklearn.compose import ColumnTransformer
7
  from sklearn.pipeline import Pipeline
 
8
 
9
  # Load Model
10
  try:
@@ -15,6 +14,18 @@ except FileNotFoundError:
15
  st.error("❌ Model file not found! Please upload `final_model.pkl`.")
16
  model = None
17
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Title of the application
20
  st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
@@ -37,9 +48,12 @@ if st.button("🔍 Predict Price"):
37
  input_data = [[POSTED_BY, UNDER_CONSTRUCTION, RERA, BHK_NO_, BHK_OR_RK, SQUARE_FT,
38
  READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]]
39
 
40
-
 
 
 
41
  # Make prediction using the model
42
- predicted_price = model.predict(input_data)[0]
43
 
44
  # Display predicted price
45
  st.markdown(f"<div class='result-box'>🏠 Predicted Price: ₹ {predicted_price:.2f} Lakhs</div>", unsafe_allow_html=True)
 
1
  import streamlit as st
2
  import numpy as np
3
  import pickle
 
 
4
  from sklearn.compose import ColumnTransformer
5
  from sklearn.pipeline import Pipeline
6
+ from sklearn.preprocessing import OneHotEncoder, OrdinalEncoder, RobustScaler
7
 
8
  # Load Model
9
  try:
 
14
  st.error("❌ Model file not found! Please upload `final_model.pkl`.")
15
  model = None
16
 
17
+ # Define your preprocessing pipeline (assuming it's already defined in your model)
18
+ # Example preprocessing pipeline
19
+ nom_pl = Pipeline(steps=[('Encoding', OneHotEncoder(sparse_output=False, handle_unknown='ignore'))])
20
+ ord_pl = Pipeline(steps=[('Encoding', OrdinalEncoder())])
21
+ scale_pl = Pipeline(steps=[('Scaling', RobustScaler())])
22
+
23
+ ct = ColumnTransformer(
24
+ transformers=[
25
+ ('nom_pl', nom_pl, [0, 4]), # Example for categorical columns
26
+ ('ord_pl', ord_pl, [1, 2, 3, 6, 7]), # Example for ordinal columns
27
+ ('scale_pl', scale_pl, [5, 8, 9]) # Example for numerical columns
28
+ ])
29
 
30
  # Title of the application
31
  st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
 
48
  input_data = [[POSTED_BY, UNDER_CONSTRUCTION, RERA, BHK_NO_, BHK_OR_RK, SQUARE_FT,
49
  READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]]
50
 
51
+ # Transform input data using the ColumnTransformer (fit before prediction)
52
+ # You need to transform the input data before prediction
53
+ input_data_transformed = ct.transform(input_data)
54
+
55
  # Make prediction using the model
56
+ predicted_price = model.predict(input_data_transformed)[0]
57
 
58
  # Display predicted price
59
  st.markdown(f"<div class='result-box'>🏠 Predicted Price: ₹ {predicted_price:.2f} Lakhs</div>", unsafe_allow_html=True)