Spaces:
Build error
Build error
Download app.py from grcvlrn/Price_Prediction_Deployment: direct link, hf CLI and curl.
- Browser
- Download file 7.05 kB
-
https://huggingface.co/spaces/grcvlrn/Price_Prediction_Deployment/resolve/main/app.py
- Command line
-
hf download hf://spaces/grcvlrn/Price_Prediction_Deployment/app.py
-
curl -L -o app.py https://huggingface.co/spaces/grcvlrn/Price_Prediction_Deployment/resolve/main/app.py
7.05 kB
| import streamlit as st | |
| import eda | |
| import model | |
| # Sidebar navigation | |
| page = st.sidebar.selectbox(label='Select Page:', options=['Home Page', 'Exploratory Data Analysis', 'Price Prediction']) | |
| if page == 'Home Page': | |
| st.header('Welcome Page') | |
| st.write('') | |
| st.write('Milestone 2: Milestone Prediction') | |
| st.write('Name : Gracia Valerine') | |
| st.write('Batch : HCK 017') | |
| st.write('') | |
| st.caption('Select page') | |
| st.write('') | |
| st.write('') | |
| with st.expander("Background"): | |
| st.caption("""This program is designed to predict the price of houses based on collected data. Accurate house price prediction is crucial for various stakeholders in the real estate market, including buyers, sellers, and investors. By leveraging historical data, we can identify patterns and trends that influence house prices. | |
| Using this data, the program will employ statistical and machine learning techniques to build a model that can predict house prices based on the given features. The goal is to provide accurate and reliable predictions to aid in making informed decisions in the real estate market.""") | |
| with st.expander("Conceptual Problem"): | |
| st.caption("""1. **Bagging:** Bagging is an ensemble machine learning technique that improves the stability and accuracy of machine learning algorithms by reducing their variability or variance. This technique is particularly useful for models that tend to overfit, such as decision trees. It works by creating multiple subsets through random sampling, which may be the same size as the original data with duplicates. The model is then trained on these subsets. Finally, in regression, the average prediction is made from all the models, and in classification, there is majority voting to determine the final class. | |
| 2. **Random Forest:** Random Forest works by creating multiple random samples with replacement from the dataset. Decision trees are then built using these samples to predict numeric values. Each tree considers a random subset of features at each split. Finally, predictions from all trees are averaged to produce the final regression prediction. | |
| 3. **Cross Validation:** Cross validation is a statistical technique in machine learning used to evaluate the performance and generalizability of a model. It partitions the data into subsets, training the model on the training set, and testing it on the validation set. This process is repeated multiple times until the model performance is consistent and not dependent on any particular division of the data.""") | |
| with st.expander("Conclusion"): | |
| st.caption("""First, we import all necessary libraries and load the data. The data contains 21 columns with 21613 entries, all of which are numerical. There are no missing values, so we can skip missing value handling. We drop the 'id' and 'date' columns as they are unnecessary for predicting prices. | |
| Next, we explore the data using graphs and charts. We find that 45% of the sales are 3-bedroom houses, indicating a preference for such houses. Similarly, 38% of the sales are 2-story houses, and most sales are houses with 1-2 floors. The majority of the sales are for houses with 2.5 bathrooms (25%). Additionally, 90% of the houses sold do not have a good view, indicating that buyers prioritize functionality over view. Most in-demand houses have about 2000 sqft of building area, and buyers prefer recently built houses (post-2000). | |
| The data is split into features (determinants of prices) and the target (price). We handle outliers by differentiating numerical and categorical columns, using Gaussian capping for normally distributed columns and IQR capping for skewed columns. After handling outliers, we scale all columns. | |
| We test different models: Linear Regression, SVM, Decision Tree Regressor, Ridge Regression, and Random Forest. Random Forest performs the best with a train score of 79% and a test score of 77%, indicating good generalization and stability. Hyperparameter tuning using Grid Search further improves the model's performance, with an R2 score of 88%. | |
| The model's effectiveness is confirmed through cross-validation, with the Random Forest model showing the best performance. | |
| **Recommendation:** | |
| For house price prediction, the Random Forest Regressor with the specified hyperparameters is recommended. It provides higher accuracy, captures non-linear relationships, and generalizes well. Despite its time-consuming training and higher memory usage, it is effective for this task. | |
| **Business Implications:** | |
| 1. **Targeted Marketing and Sales:** Identify areas with rising prices for marketing campaigns. | |
| 2. **Investment and Development:** Acquire properties in high-growth areas for development and resale. | |
| 3. **Pricing Strategies:** Adjust prices based on market conditions to stay competitive. | |
| 4. **Inventory Management:** Optimize property sales timing based on market trends. | |
| 5. **Customer Insights:** Understand customer preferences for realistic pricing. | |
| 6. **Partnership and Alliances:** Collaborate with builders, developers, and agents for projects in high-growth areas. | |
| 7. **Innovation and Technology:** Appeal to tech-savvy buyers with smart home technology and sustainable practices.""") | |
| with st.expander('Recommendation'): | |
| st.caption("""#### **Technique** | |
| With this experiment, I can say that the best model to use in predicting the price of house sales is random forest regressor with 'regressor__max_depth': None, 'regressor__min_samples_leaf': 1, 'regressor__min_samples_split': 2, 'regressor__n_estimators': 200 hyperparameters. The model performs 88% well. | |
| This model is great for this data because it provides higher accuracy compared to decision tree, which only has 1 tree. It can capture non-linear relationships between features and target variables. Due to combining multiple trees, the model generalize well and is less prone to overfitting. It also ranks the importance of features, which helps in feature selection. The model can handle missing value in the dataset. | |
| Though, the model trainning computation is quite time consuming especially in large dataset and large number of trees. It is also harder to interpret compare to a single tree model. The model also requires more memory usage due to the number of trees. | |
| By carefully tuning parameters, optimizing features, and considering ensemble methods, you can leverage the strengths of random forests while reducing some of its downside to achieve better performance in regression tasks. | |
| #### **Business** | |
| Implement strategies such as: | |
| 1. Targeted marketing in areas with predicted price rises. | |
| 2. Investment in high-growth regions. | |
| 3. Pricing strategies to maximize profit margins. | |
| 4. Inventory management based on market peaks. | |
| 5. Customer insights for realistic pricing. | |
| 6. Strategic partnerships in high-growth areas. | |
| 7. Innovation with smart home technology and sustainable practices.""") | |
| elif page == 'Exploratory Data Analysis': | |
| eda.run() | |
| else: | |
| model.run() | |