Data Visualization on Machine Learning
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:
- Data preprocessing
- Model Experimentation
In data preprocessing I dealt the the following topics:
- Missing values
- Outliers and apparently incorrect data
- 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.
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.
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.
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).
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.