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 > Ames Housing Price Predictions - Model Ensembling

Ames Housing Price Predictions - Model Ensembling

Andrew Dodd, Roger Ren, Michael Goldman and Peter Yang
Posted on Mar 10, 2018

Introduction

The purpose of this project was to create an accurate model for Ames, Iowa home prices from the dates 2006 - 2010. This prediction model would learn from a Kaggle dataset (and competition that can be found here: https://www.kaggle.com/c/house-prices-advanced-regression-techniques). Originally, this dataset was made by a professor, Dean de Cock at Truman State University as a class project. This dataset has grown in popularity and now is the basis for a highly frequented Kaggle training competition. It has 79 explanatory features to help describe a house and the surrounding property ranging from square footage to more subjective or categorical features such as quality or garage type.

Our intrepid team of four set off to explore our dataset, draw inferences and ultimately create a model to predict the correct price of a home in Ames.

Contents:

  1. The Data:
    • Explore dataset
    • Look for trends
    • Basic stats
  2. The Models
    • Present models used
    • Explore pros and cons of models
  3. The Pipeline
    • Cleaned data --> base modeling --> metamodeling --> output csv
    • Discuss code structure
  4. The Results
    • Test set performance
  5. The Future
    • How we could improve our approach to the problem
    • What we could have done better

1.   The Data

We have about 2900 observation total with 79 numeric and categorical features; split evenly between training and test datasets. Our output variable is sales price. There is some missing data, some outliers, and some skewed variables. We want to fix some of these problems before we can have strong models.

First, let us have a look at the distribution of the response variable, sale price. We can see from the figure that the distribution of sale price is right skewed. To fix this, we will perform a log transform on the sales price. The blue line represents the original skewed data distribution while the black line represents the transformed normal distribution.Next, we plotted boxplots and scatterplots to show sale price versus different features. For example, on this sale price versus neighborhood boxplot, it seems that there is a strong correlation between neighborhood and sale price.

On the scatterplot of sale price versus overall quality, we have another strong correlation. However, when we take a closer look, the sale price actually increase exponentially as the overall quality increases.

On the correlation plot, we can see that first floor square feet is highly correlated with total basement square feet and garage cars is highly correlated with garage area. In the feature engineering, we will address these issues.

In addition to some of the EDA and transformations above, the team removed several high price outliers and added some features such as total livable square footage.

2.   The Models

For the models, we chose a variety of different base models such as Lasso and Ridge regression, Elasticnet, deep XGBoost, shallow XGBoost, GBoost, LGBM, and Random Forest.

The first models that we used were the linear models (Lasso, Ridge, and Elastic Net). The reason why we used these were that they are relatively simple to implement and do not take that long to optimize. We used Ridge because we wanted to minimize the effect of weak predictors for the House's sale price (the target), but not eliminate them because they might provide some explanatory power in the model. We also used Lasso in order to drop unnecessary columns that might not provide any explanatory power in our model. Elasticnet was also used since it is a combination of the Lasso and Ridge, so it will hopefully find the 'best of both worlds' in minimizing the impact of weak predictors while also dropping unnecessary ones. The one drawback for this model is that these models assume a linear relationship to the target, which was not always the case. Another drawback is that these models suffer from multi-colinearity, which can make the estimates for our coefficients inaccurate if they are highly collinear.

After we implemented the linear models, we also implemented a number of tree based models, such as Random Forest, XGBoost, GBoost, and LGBM. For this post, I shall separate them into two different segments, Random Forest and the various boosting models.

The reason why we included the Random Forest model is because it tends to not over-fit the training set because each decision tree is limited to a number of factors. Although each individual decision tree might over-fit the data, all of the trees can be ensembled together to make a stronger predictor. This can be done because all of the individual trees are uncorrelated. As long as we have enough trees in the Random Forest, the 'noise' of each tree will be averaged and the trend from the strong predictors will stand out. Another benefit from this model is that it does not assume a linear relationship between the variables and the target. One con of this model is that the accuracy of the model can suffer when predicting on data that it has not seen before. The reason for this is because there are only a certain number of leaf nodes, so that means there can only be a certain number of predicted prices. If the model finds that it hasn't seen before in the training set, its accuracy will suffer.

We also incorporated a number of different boosting methods in our model. We did this because although each of the models follow similar logic, they are implemented differently. For this reason, we incorporated multiple different to 'verify' our results. The general methodology of these boosting methods is that it creates a decision tree and for ever subsequent decision tree, it predicts on the residual of that previous tree. As we increase the number of trees in the boosting model, the closer our results are to the true value. This can lead to very accurate results, however it is susceptible to over-fitting, since the trees are correlated with each other.

The reason why we tried such a variety of different models was that we would later ensemble them. The more different the models were, the more independent our errors would be. We optimized all of our models through a combination of CV grid search, Bayesian optimization, which refines the parameter search region through an iterative process, and by looking through Kaggle kernels for parameters used by past submissions.

3.   The Pipeline

Now that we have a good idea of the models, the question becomes can we use them together to create an even better model; in other words, can we ensemble our models to create better predictions? To solve this question, we built a framework of Python scripts. One script, models.py would house the Model class, while another script, housing_main.py would house the master function (def main), as well as the Stacker class. Below is a breakdown of the code structure:

  1. models.py
    • Model class
      • Functions:
        • init (model_type): initialize model object, many options
        • train_validate (data): KFold CV, training and computing CV score
        • train_predict (data): Trains on full train dataset, creates pred. on Kaggle test set
    • get_error (y_true, y_pred, type): computes either RMSE or RMSLE for predictions
  2. housing_main.py
    • Stacking class
      • Functions:
        • init(metamodel_type): initialize stacking metamodel
        • train_validate_predict(base_model_predictions): KFolds CV for train, score, also predicts on Kaggle test set
    • optimize(): runs Bayesian Optimization on variety of models
    • import_data(): imports specified .csv file

Essentially when one runs housing_main.py, it creates and trains a specified list of models in a sequence. For each model, it builds the model, fits the model with KFold cross validation (CV) with the training set, computes CV score, and also creates predictions on the Kaggle test set. The predictions on the training set (through KFolds CV) and the predictions on the Kaggle test set are then sent through the stacking pipeline. The stacker (either XGB, linear, or averaging) is then used to combine the models predictions to again get CV score and again create new Kaggle test set predictions. The final Kaggle test set predictions are saved to a .csv file for later use. Below is a graphical representation of the modeling process.

One may notice that there is no accounting here for the out-of-bag error (OOB), or a completely separate validation set. The models and their parameters were chosen largely due to their CV scores, so this inherently leads to some data leakage during CV. Future work would be to set aside maybe 20-30% of the initial training dataset to serve as an untouched validation dataset.

4.   The Results

Ultimately, our rmsle was .12186 (898/4396 on Kaggle Leaderboard), which equates to our prediction being approximately an average of 13% off the true home value. Interestingly, the test error was about .012 higher than the CV error. As was mentioned previously, this may have been due to slight model and parameter overfitting while training.

5.   The Future

If we were to work more on this project we would do a number of things differently. First, we would implement a recursive feature engineering to feature importance cycle so as to help home in on good features and develop a more accurate model. This would be aided with functional based ways to find feature importance so as to accelerate the process.

Second, we would implement a better testing method. As has been mentioned, the CV error should not be the only error with which we can gauge our model. In fact, the CV error is meant as a tool to choose models, refine models (parameter tuning), and avoid overfitting among other uses. However, it does not serve as a replacement for a test set to give an accurate estimate of one's test error. Furthermore, one does not want to submit often to Kaggle, as this is the true test score and one should avoid frequent submissions as this will lead to overfitting. Therefore, to avoid this, one should use an out of bag error by setting aside part of our training set at the start (20% perhaps).

Finally, we would investigate more into the effects of time as there is clearly a trend in housing price from 2006 to 2010 in United States, so it is curious that the dataset does not seem to reflect this.

Thank you for reading!

 

About Authors

Andrew Dodd

I am a data scientist at NYCDSA with a mechanical engineering background (BS, Masters). My masters focused on space and robotics applications; this is where I developed my interest in machine learning through courses that involved path planning...
View all posts by Andrew Dodd >

Roger Ren

Roger brings in excellent Data Science skills and results oriented mindset to your team. He recently graduated with a Master in Data Science (GPA: 3.85) from University of Rochester and has a Master in Materials Engineering (GPA: 4.0)...
View all posts by Roger Ren >

Michael Goldman

Michael Goldman is an experienced data analyst with a background in economics, mathematics, and computer science (Python, R, SQL, Stata, Java, and VBA). He has worked as a Data Analyst for NERA Economic Consulting, providing expert testimony and...
View all posts by Michael Goldman >

Peter Yang

View all posts by Peter Yang >

Related Articles

Data Analysis
Injury Analysis of Soccer Players with Python
Machine Learning
Ames House Prices Predictions
Python
US Honey Production Analysis With Python (1998-2012)
Machine Learning
The Ames Data Set: Sales Price Tackled With Diverse Models
Python
EDA and machine learning Ames housing price prediction project

Leave a Comment

Cancel reply

You must be logged in to post 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