Machine Learning - Ames, IA
Posted by Nathan
Updated: Aug 15, 2020
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 project in to 3 stages:
- Data preprocessing
- Model Experimentation
- Hyperparameter tuning and final selection
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.
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 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 when you see this!View all articles
Topics from this blog: Student Works