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 > House Investing: Real Estate and What Affects a House Price

House Investing: Real Estate and What Affects a House Price

Wonchan Kim, KISOO CHO and hyelee lee
Posted on Sep 6, 2019
The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

Introduction

A lot of people hear about the subject of real estate and generally have an intuition on what factors affect a house's sale price. Some are based on feelings whereas others are grounded in learned domain knowledge. In short, there are so many factors to consider when thinking about the end goal of predicting a house's final price. Through this project, we wanted to take a peek into the plethora of features that can influence the sale price of a home by employing machine learning models to our given dataset.

Dataset

Our dataset is a very famous one that was procured from a Kaggle competition. It is a residential housing dataset for the city of Ames, Iowa from the years of 2006 to 2010. This dataset was composed of 79 features and 1460 observations and had a column of sales prices that we used to train our models in order to predict sales prices for the test and validation datasets.

Preprocessing

Due to the number of null values in the data, the pre-processing step was incorporating a variety of methods in order to impute these null values.

At first, we focused on the null values in our training data, but we soon realized that the test data also contained null values that needed to be filled in order to make predictions. Therefore, we merged the training data and test data; however, we later realized that this caused a phenomenon known as "data leakage" to occur. This is further explained in the conclusion.

There was a total of 34 columns that contained null values.

For each column, we considered how to fill the null value by using intuition while looking at the data descriptions.

We divided all features into four parts and roughly assigned 20 each to the group members. With each portion of the dataset, we each performed simple EDA, imputed the null values, and finally combined the fragmented features to recombine the dataset.

Relationship between Columns

Then, we analyzed the relationship between columns by separating the categorical and numerical columns of each group of features. If the column had no relationship, were categorical, and the null values themselves meant "NO," the column was filled with "NA" or "None". Otherwise, if the column was numerical, the column was filled with 0.

For example, the PoolQC column is related to the Pool Area. Since pool quality assumed a null value only when pool area had a 0 value, the NA value corresponding to "no pool" was filled.

There were six categorical columns (Electrical, MSZoning, KitchenQual, Exterior1st, Exterior2nd, Sales Type) that could not contain null values due to data characteristics. When we checked the distribution of these columns excluding null values, we could see that certain values of the features were much more prevalent. Therefore, the mode was suitable for and used in the imputation of the values of these 6 columns.

For the two columns of LotFrontage and GarageYrBlt, because they could not be imputed with simple "0"s, we checked the null value counts by analyzing their correlation to other columns.

For LotFrontage, we considered two different methods of imputation:

The first method was considering LotFrontage's relationship to LotArea. 

Ratio

We calculated the ratio of the mean value of LotFrontage and LotArea excluding null values and filled the null values of LotFrontage by multiplying the value of the respective observationโ€™s LotArea to the calculated LotRatio.

The second method was relating the neighborhoods to LotFrontage. 

Because houses are typically similar in neighborhoods, we grouped the data by neighborhood and found the median value of LotFrontage. Using this median value, we imputed the null values based on an observationโ€™s respective neighborhood.

Because we didn't know which method would be better for our output, both methods were used in the process of feature engineering to determine which outputted better results; the better imputation method ended up being method 2.

The garage year built feature was imputed by relating it to the year the house was built. After calculating the difference of year built and garage year built of each observation, we rounded this value so that we could maintain integer values for year. Then, the garage year built was imputed by adding the aveDiff to the year built value.

Exploratory Data Analysis

Before we could go into the processes of feature engineering and model fitting/tuning, we had to examine the dataset that we were given.

Figure 1. Correlation heatmap of variables

As can be seen by the correlation heatmap in Figure 1, there were some variables that were highly correlated to one another. Due to this presence of multicollinearity and the effects it would have in our model results, we used this figure to drop some features.

Figure 2. Chi-squared results of categorical variables that were not significant

For the categorical features, we had to take into consideration whether or not the features were significant with respect to the sales price. The figure above shows the categorical features that had p-values greater than 0.05 which meant that these features were not significant.

Using the intuition gained from this statistical testing process, we were able to drop some features or come up with other approaches to manipulate them such as binarizing the feature values.

Figure 3. Standardization outputs for numerical values

On the left side of Figure 3 shows the histograms of each of the numerical features in the dataset. However, because of the skew of some of the variables, we had to standardize them. The result of this standardization process is shown in the right side of Figure 3 with less of a skew and more of a proper normal distribution. This is further explained in the feature engineering step.

Figure 4. Violin and box plots for various categorical variables

We took a look into categorical variables not only through the statistical hypothesis test of chi-squared, but also by examining the feature values through the use of violin and box plots (Figure 4). We saw that there were trends in the sales price of the home with relation to the different values of the features.

All of this data analysis was later used in the process of feature engineering.

Wireframe

Figure 1. Wireframe of project

Figure 1 shows the modeling process of this project. After looking into the data, we developed these steps to make the feature engineering and model fitting easier to manipulate.

After loading in the file, merging datasets, and removing outliers, we put the data through a pipeline that performed feature engineering such as null imputation and standardization. This process made feature engineering seamless as it gave an efficient tool for engineering the dataset altogether rather than performing each step one by one.

For the process of model fitting, we created a grid search that generated the best hyperparameters for the models through the use of a parameter grid.  We utilized multiple linear-based regressions as well as tree-based regressions.

With these different types of regressions, a stacked model was made. The stacked regression used a support vector regressor (SVR) as its meta-regressor. Using all of these models combined, by applying weights to each model, we were able to ensemble them to generate the final predictions.

Feature Engineering

When starting this project, the general thought was that the more correctly one could tune a model, the more accurate the final price would end up being. However, after repeated trial and error, we realized that the most important aspect of this project was feature engineering.

Some of our categorical variables such as BedroomAbvGr had numerical values so we had to turn them into strings and ultimately dummify the variables using one-hot encoding.

One-hot encoding was one method used to pass in categorical features into our model; however, the other method that could account for ordinal features was to factorize them so that they could have values with magnitude that accounted for the order of the values.

For features such as FireplaceQu or KitchenQual, because of the lack of data points in some of the feature values, we had to binarize these features into 0s and 1s with the 1s being the mode of the values within the feature. 

Creating new Features

We also created new features by using intuition. An example of this was summing up all of the various square footage features of the house into one aggregated value of the entire square footage of the house. We also classified the data into a new category that took into account the neighborhood.

Figure 5. Standardization outputs for LotFrontage and LotArea

The two variables of LotFrontage and LotArea were features that were related in the imputation process. As such, we took a look into the distributions of these features and saw that they were not normally distributed.

Because of the skew within the distributions of the features, we had to incorporate methods to transform these variables. The box-cox transformation was used to produce a lambda that would be used to transform the features to be more normally distributed. In addition, the RobustScaler from scikit-learn was used as a standardizer to negate the effects of features with values that were much greater than those of other features. RobustScaler is particularly unique because it has the ability to account for outliers.

Model Fitting

After feature engineering, the first model we implemented was a stacked ensemble model.

Model stacking combines the outputs of multiple models (called base estimators) by training a higher level model (called the meta-estimator) on their outputs. Stacked regression can be used for classification or regression and uses the results of several sub-models as an input to the meta-regressor to prevent overfitting and reduce bias.

By including the random forest regressor, the accuracy of the whole model was reduced so we decided to exclude it from the final model.

We chose SVR as a meta-regressor to output the most stable score and we ensembled this stacked regression with other models without using it immediately to produce a final output. This was done to distribute weights to other individual models.

The structure of these models was not built through one step, but through multiple iterations of trial and error.

Model Tuning

After fitting our models, we tuned our parameters.

First, we reselected and modified the features. Some examples of this was combining several features together such as the size of various aspects of the house into one feature or binarizing features with multiple feature values. Not all features created or changed through feature engineering produced good results so we found the best combination of features by including or excluding features one by one, choosing ones that led to higher scores.

Second, we found the best hyperparameters for each models. Because it takes too long to find all of the best hyperparameters at once, we found the best parameters by rotating them one by one from elastic-net to lightgbm models.

Finally, we adjusted the weights among each of the models. Stacked regression had a good result by itself, but we tried to give more weight to individual models as well. To do so, we simply multiplied the results of the model by a respective weight to produce the ensembled result.

We repeated the process of feature selection, hyperparameter tuning, weight adjustment, and scoring to ultimately get a better score.

Conclusion

After finishing tuning, we got our final score to be 0.11591, which corresponded to a rank of 640 and landed us in the top 14.4% of submissions.

Here are some important lessons we learned from this project:

  • Feature engineering is much more important than model tuning. Model tuning is necessary to achieve very high scores, but it must be preceded using creative methods of feature engineering.
  • Feature engineering should be done through accurate analysis such as Z-score/VIF/chi^2, not merely guesswork.
  • Not all logical predictions bring good results, but they can be a good starting point.
  • Some complex models like XGBoost or GBM bring good results even with small effort. However, simple models like ridge or lasso can be more apt depending on the data given.
  • Some models are sensitive to feature engineering. For example, support vector regression can make an incorrect prediction if standardization is implemented incorrectly.

Data Leakage

One flaw that we unintentionally enacted from the start was data leakage. Because the test dataset contained missing values that needed to be imputed, we automatically thought to combine the datasets to provide more data in the process of imputation. However, this is not at all encouraged because although it could give better results, the fact of the matter is that we ended up making predictions on data that we used in the process of manipulating our features.

For further cases, we would avoid mixing up these datasets and only use the training data in the process of feature engineering.

Further Improvements

There is the basic approach of applying other combinations of models or hyperparameters in order to improve our score. 

We could also look into post-processing techniques of higher scoring submissions and apply the methods of feature engineering into our project.

About Authors

Wonchan Kim

Wonchan graduated from the University of California, Los Angeles with a B.S. degree in Materials Engineering and a minor in Statistics in 2019. Wonchan has proven acumen in business applications and experience tailoring data analysis and machine learning...
View all posts by Wonchan Kim >

KISOO CHO

View all posts by KISOO CHO >

hyelee lee

View all posts by hyelee lee >

Related Articles

Capstone
Predicting the Unpredictable: Revolutionizing E-commerce Delivery with Machine Learning
Capstone
The Convenience Factor: How Grocery Stores Impact Property Values
Capstone
Acquisition Due Dilligence Automation for Smaller Firms
R Shiny
Forecasting NY State Tax Credits: R Shiny App for Businesses
Machine Learning
Pandemic Effects on the Ames Housing Market and Lifestyle

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