Data Visualization on Machine Learning

Posted on Aug 15, 2020
The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

Thanks for reading this article! I'll try to make it straightforward for you so you can find what you're looking for!


I largely broke this data study project in to 3 stages:

  1. Data preprocessing
  2. Model Experimentation
  3. Analysis

Data Preprocessing

In data preprocessing I dealt the the following topics:

  1. Missing values
  2. Outliers and apparently incorrect data
  3. Multicolinearity
  4. Feature Variance


In many features, an NA value indicates None or Zero (absence of feature rather than absence of data) and in so in those instances I imputed the appropriate value. In particular, in many categorical values, NA indicated that the property was missing that feature, and so in those instances I imputed a "None" value. Purportedly, missing values in LotFrontage indicate that the lot has no contact with the street, so I imputed zeros for missing values in that variable.

When NA indicated missing data, I generally imputed the mean, median, mode, or a random value based on data type and skew. For example, data for the MasVnrArea feature was highly skewed to the right, so I imputed the median for NAs in that value. The Electical variable had one lonely missing value and apparently nearly all properties in Ames use a standard circuit breaker, so I imputed the mode but also removed this feature from later models.

Data Visualization on Machine Learning

In a few specialty cases I used a different strategy, such as GarageYrBlt, where I imputed the year the house was constructed.

Outliers and Apparently Incorrect Data

I evaluated features with highest correlation value with SalePrice (correlation greater than .6) using visualization for outliers and in instances where features had apparent outliers I removed them. I also inspected SalePrice and SalePrice by neighborhood and year and removed a few points that represented obvious outliers. At this point I also discovered that data for one of the neighborhoods (Veenker) seemed to be missing several year's worth of data and since it seemed unlikely that an entire neighborhood would see no sales for two years I reasoned this was the result of poor data gathering and removed it from the dataset.


Data Visualization on Machine Learning


I also noticed a number of instances in which MasVnrArea (the area of masonry veneer on the house) was listed as a non-zero, but the house's masonry type was listed as "None". This seemed like obvious incorrect recording and so I deleted these rows from the dataset.

Features with High Multicolinearity

A number of features possessed high multicolinearity (correlation > .6). For each cluster of correlated points I considered their relationship with SalePrice and removed the feature with lower correlation. In some instances I considered feature skew or variance as a tie-breaker. I also removed a MSZoning because most neighborhoods only had one type of zoning.

Feature Variance

I considered a range of thresholds for feature variance, but found that while removing features with low variance improved later model fit on most model types, it also widened the gap between train score (r2) and test score, which I judged to indicate overfitting. As a result I did not remove any features with low variance.

Data on Model Experimentation

Following data preprocessing I performed an 80/20 train/test split on the data and assigned dummy variables to my categoricals using pd.get_dummies. I considered untuned (default settings, with the exception of random forest, where I set n_estimators to 100 to improve runtime) and tuned versions of Multiple Linear Regression, Lasso, Random Forest, XGBoost, and SVR (tuning strategies below).

I found that a tuned XGBoost offered the best score both for train and test set fit (again using R2 as our metric).Β 

Data Visualization on Machine Learning


Final model mean absolute error for the models attempted in this project ranged from $16,556 to $20,600, with our winning model on the low end of that range. Mean sale price for this dataset (our response variable) was $176,834. So, how happy are we with the outcome? How should we feel about the quality of our predictions for this dataset?

One way to thing about this is to ask ourselves whatΒ isn't in the data. How confident are we that we have all the data available that might reasonably influence sales outcomes? Presumably, if there's information thatΒ should influence the outcome not represented in the dataset, then we should expect an increased degree of error in our predictions. Conversely, if we see error in our model when our domain knowledge suggests that all (or nearly all) relevant factors should be accounted for, then our model is suspect.


So what might influence sale price that isn't listed in our dataset as currently available? I can think of a few things:

  • Seller financial/job situation (Is the sale a short sale? Did the seller recently undergo a financial loss that requires an urgent sale or receive a job offer requiring urgent move to another city?)
  • Buyer/Seller negotiation skill
  • Negotiation skill or years of experience of the real estate agents and brokers involved

Reflecting on personal experience, I can easily see how these factors could account for a 10% +/- variation in the sale price of an individual listing, though much more than that begins to feel like a stretch, and so it seems that we can rest reasonably secure that our winning model (XGBoost) is giving us sufficiently accurate predictions relative to the breadth of information available to it. It also gives us some ideas for our wish list of data for future expansion of the project, with anonymized listing agent (and preferably data to reflect their degree of sales experience) high on our list of data to request for future iterations of our project.

About Author


Data scientist in training with a background in education and a passion for solving challenges using data-driven decision-making. Methodological, tenacious self-starter. Building skills with Python, R, SQL, statistical analysis, and machine learning models. Ask me where I am...
View all posts by Nathan >

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

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 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 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 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