NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship ๐Ÿ† Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lesson
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular ๐Ÿ”ฅ Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New ๐ŸŽ‰ Generative AI for Finance New ๐ŸŽ‰ Generative AI for Marketing New ๐ŸŽ‰
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular ๐Ÿ”ฅ Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular ๐Ÿ”ฅ Data Science R: Machine Learning Designing and Implementing Production MLOps New ๐ŸŽ‰ Natural Language Processing for Production (NLP) New ๐ŸŽ‰
Find Inspiration
Get Course Recommendation Must Try ๐Ÿ’Ž An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lessons
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > Machine Learning > Predicting House Sale Prices - Ames, IA

Predicting House Sale Prices - Ames, IA

Suhita Acharya
Posted on Jun 28, 2022
LinkedIn
GitHub

Introduction

Over the last two years, house sales prices have skyrocketed, and home buyers are paying more than the asking price to grab any available home in this real estate frenzy. A CNN Business article states that the National Association of Realtors said in a report on Wed June 22, 2022, that the median home price in May topped $400,000 for the first time, hitting a record of $407,600. That's up nearly 15% from a year ago. At this time, a tool that helps predict house sales prices based on its features, could prove to be handy. The said tool could assist realtors/mortgage lenders to render precise performance in such a cut-throat sales market.

The objective of this project is to create a machine learning model that can assist home realtors/mortgage lenders to determine a houseโ€™s sales price. I wanted the model to use existing information provided about the home; its features such as the number of bedrooms/bathrooms, basement size, garage size/capacity, etc. to predict the house sales price. Through this research, I also made some recommendations about some probable ways that may get the homeowners a high sales price. Several models were developed, and some were shortlisted to create an optimal price determination tool.

Factors affecting House Sales Price:

Any house's sale price depends upon some universal factors that make the house more desirable among the pool of potential buyers. Some of these factors include:

  • Location
  • Usable Space
  • House Condition (external and internal)
  • Remodeling
  • The number of bedrooms/bathrooms

For this project, I decided to focus on the house properties only and how they can influence sales price. According to an article by Opendoor, a homeโ€™s usable space (not garages, attics, and unfinished basements) matters when determining its value. Similarly, homes that are newer possibly remodeled, and in good condition appraise at a higher value.

Dataset Introduction

The house sales data used in this project comes from a Kaggle dataset - House Prices - Advanced Regression Techniques. This dataset includes sales price information for several homes in Ames, Iowa. Along with the sales price, we also get in this dataset 79 explanatory variables describing (almost) every aspect of the residential homes. Some of these variables give information on Lot Frontage/shape, neighborhood, house condition/quality, year remodeled, roof material, etc. The aim here is to use these unique descriptors in creating a model to best predict house prices.

House Sales Price Analysis

House Sale Prices - Before and After Log-Transformation

In my quest to figure out what factors influence a house's sales price, the first thing that I looked at was how the distribution looked for all sale prices. Sales prices for the houses were right-skewed and required log transformation for a more Gaussian-like distribution. This step ensures that our model achieves the goal of linearity. I then conducted some exploratory data analysis to research relationships between the dataset variables and the house sales price.

What we can see from these graphs here is that there is a clear relationship between some of the numerical/categorical features and the sales prices. The higher the first floor and total above-ground living area, the higher the house's sales price will be. Similarly, if the sales price relation to some of the categorical features is looked at, we can gain some useful information. From the boxplots below, we can see that a house with a higher basement and overall house quality rating evaluation will surely command a higher sales price.

Data Preprocessing

Next, before going into more detail on the data modeling let us first discuss how the data was preprocessed which is a crucial step in machine learning (several model types are sensitive to outliers). Upon initial evaluation, I notice some of the data variables had a lot of missing values. Missing values were imputed in the data accordingly. For example, I saw a lot of missing values in Pool QC and Fence categorical features, meaning the houses probably did not have a pool or a fence. In such cases, values were imputed as "No Pool" and "No Fence". For any missing numerical area-related missing values, the value of zero was added.

I also removed extreme outliers (something that can make our model prediction) from some of the features such as a single categorical value for the Utilities feature. Another thing that I changed in terms of preprocessing was that I changed the data type for some numerical columns with year, and month-related information to categories.

Feature Engineering

After the basic data preprocessing, I also created some numerical and categorical features and combined some categories into one for some categorical features.

  • New Numerical Features:
    • sold_age = Age of the house when it was sold.
    • Usable_space = Sum of basement, above ground, first and second floor areas.
    • yr_since_remod = Years since the remodeling was done.
    • Total_Halfbaths = Sum of all half baths.
    • Total_Fullbaths = Sum of all full baths.
    • Encl_Porch_tot = Sum of all enclosed porch areas.
    • BsmtFinSF = Sum of Type 1 and Type 2 finished basement area.
  • New Categorical Features:
    • remod_y_n: Whether house was remodeled or not.
  • Combined values in categorical features:
    • LandContour: replacing values other than Lvl to Notlvl.
    • Heating: replacing values other than GasA to Heat_other.
    • Electrical: replacing values other than SBrkr to Electr_other.
    • PavedDrive: replacing values other than Y to NP.

House Sales Price Analysis (New Features):

After creating the new features to understand the data better, I also studied the relationship of some of these features to the house sales prices. One of the interesting clear relationships that I uncovered was between House Sales Price and Usable Space Area. It looked like a house with greater usable space area, will cost much more than a house with a low area.

Similarly, I also looked at how the sales price was related to whether the house was remodeled or not and the years since it was remodeled. It seems like the homes that were more recently remodeled had a higher median sales price than those that were remodeled 60 years ago. If we look at the boxplot below, we can see that although the average house sales price is lower for remodeled houses, some of the remodeled houses have commanded higher sales prices than ones that were not.

Data Modeling

Next, we will look at the regression models (both linear and tree-based models were attempted) attempted for this project. All the data was log-transformed and numerical features were standardized. Models were trained/evaluated on a 70:30 train-test split.

Linear Models:

For the Linear models, categorical features were either label encoded or dummified (see below) based on the type of feature. For these models, variables with high multicollinearity were removed (based on VIF values) for example Roof Style, and Garage Type. The types of Linear models attempted are listed below:

  • Multiple Linear Regression (MLR)
  • Ridge and Lasso Regression
  • Support Vector Regression

Multiple Linear Regression (MLR):

For the final MLR model, independent features were selected via Lasso regression (hyperparameter alpha was chosen by grid search cross-validation). List of selected features (Lasso alpha=0.01) is shown below.

If we look at the residuals and prediction error plots for this model, we see that the residuals are fairly random and uniformly distributed and there is a decent linear agreement between the actual and predicted house sale price values.

Penalized Regression (PLR):

The results for the Ridge and Lasso PLR models are shown below. The only change to note is that, for the Lasso model, the data was normalized beforehand.

For both models, the residuals are uniformly distributed (low variation for the Ridge model), with a good agreement between the actual and the predicted house sales price values. The accuracy for both Ridge and the Lasso Regression models, (90.6% and 90% respectively) are decent and an improvement over the MLR model accuracy (87.6%).

Support Vector Regression Model (SVR):

For the final SVR model, all the basic preprocessing steps were the same as other linear models. Some features with high multicollinearity were dropped. Some additional work was done in selecting model hyperparameters. Hyperparameters C (controls regularization; the strength of the regularization is inversely proportional to C), and epsilon (specifies the epsilon-tube within which no penalty is associated in the training loss function with points predicted within a distance epsilon from the actual value) were determined from plotting R2 and errors for train and test data. Other hyperparameters (kernel coefficients gamma and kernel in this case) were selected by Grid Search CV.

In terms of uniform residual distribution, actual/expected sale price agreement and accuracy it seems like the SVR model fares much better than its other linear counterparts.

Tree-based models

For the tree-based models, categorical features were label-encoded only. Features with high multicollinearity were not dropped. The model hyperparameters which are listed below, were chosen by Grid Search CV. The types of tree-based models attempted are listed below:

  • Random Forest
  • XGBoost

Random Forest (RF) model:

For the final Random Forest model, the residual and prediction error plots provide us with impressive results. This model is an improvement over the other linear models; however, there seems to be a bit of a difference in the training and testing data accuracy, indicating overfitting.

Next, I also looked at the feature importances as provided by the final Random Forest Model to gain more information on which features were contributing to the results.

XGBoost Model:

The next and the last model type that I attempted was the XGBoost. For this model type, I ran two different versions of this model. For one version, all features were used, and the other features were selected by Sklearn's Recursive Feature Selection (RFE). RFE is a feature selection algorithm that uses feature elimination to select features for the model to use.

As per Scikit Learn's documentation, the estimator is trained on the initial set of features and the importance of each feature is obtained either through any specific attribute or callable. Then, the least important features are pruned from the current set of features. That procedure is recursively repeated on the pruned set until the desired number of features to select is eventually reached.

Lastly, the performances of both model types were compared with each other. For both models, the hyperparameter max_depth (the maximum depth of a tree) was determined from plotting R2 and errors for train and test data. An eta (step size shrinkage used in update to prevent overfitting) hyperparameter value was selected to optimize performance. Other hyperparameters were selected by Grid Search CV.

The results for the XGBoost model with RFE selected features are displayed below. In the first graph below, we see the similarity between the predicted and expected house sale price value. The test dataset house sales values are in decent agreement with each other.

The second graph shows the model importances as shown by the XGBoost model.

XGBoost model feature importances

Final model evaluation metrics:

The table below shows train and test data accuracy scores and errors for all the models attempted, including different versions for each. For all the model types, the final model had the RFE selected features, except for the XGBoost model for which the two different versions were run.

Based on accuracies and RMSE (Root Mean Squared Error) scores, the SVR, XGBoost and XGBoost (RFE) models were shortlisted to be used for creation of the house sales price determination tool. These models were chosen because they were not overfitting and have relatively low errors scores.

Conclusion

If we look at the evidence provided by exploratory data analysis, we can see that overall house quality and usable available space inside the house matter when determining the final house sales price. Some other necessary characteristics that emerged while studying the data modeling results are listed below:

  • Overall condition that the house is in.
  • Finished Basement area (in square feet).
  • Total above ground living area (in square feet).
  • Whether the house has been remodeled or not.
  • Years since the house has been remodeled.

Based on what I have uncovered through the research in this project; the few things that I can recommend realtors/mortgage lenders do to possibly get a higher sales price are as follows:

  • Make sure the house on sale has more usable living space.
  • The realtor/mortgage lenders can check if the house, basement, and garage is are good condition and if evaluation rating is high. If not, steps need to be taken to correct this issue.
  • If the house basement is unfinished, recommend the seller consider getting it finished.
  • Recommending the seller for renovation if not done in a long time.

Future Work

Something, I would like to do if given some more time with this data is to go back and do a more thorough data analysis and work to see if the models themselves can provide more insight not previously uncovered.

References:

  • Paul R. La Monica, C., 2022. Could a housing slump threaten the stock market and the entire economy? [online] CNN. Available at: <https://www.cnn.com/2022/06/22/investing/premarket-stocks-trading/index.html> [Accessed 27 June 2022].
  • Gomez, J., 2022. 8 critical factors that influence a home's value | Opendoor. [online] Opendoor. Available at: <https://www.opendoor.com/w/blog/factors-that-influence-home-value> [Accessed 27 June 2022].
  • Kaggle.com. 2022. House Prices - Advanced Regression Techniques | Kaggle. [online] Available at: <https://www.kaggle.com/c/house-prices-advanced-regression-techniques> [Accessed 27 June 2022].
  • scikit-learn. 2022. sklearn.feature_selection.RFE. [online] Available at: <https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.RFE.html> [Accessed 27 June 2022].

About Author

Suhita Acharya

NYCDSA Bootcamp graduate with background in Environmental Sciences, previously worked professionally as a QA Chemist at Environmental Standards, Inc.
View all posts by Suhita Acharya >

Related Articles

Capstone
Catching Fraud in the Healthcare System
Capstone
The Convenience Factor: How Grocery Stores Impact Property Values
Capstone
Acquisition Due Dilligence Automation for Smaller Firms
Machine Learning
Pandemic Effects on the Ames Housing Market and Lifestyle
Machine Learning
The Ames Data Set: Sales Price Tackled With Diverse Models

Leave a Comment

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day ChatGPT citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay football gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income industry Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    ยฉ 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application