This chapter covers
- Using transformers and estimators to transform data into ML features
- Assembling features into a vector through an ML pipeline
- Training a simple ML model
- Evaluating a model using relevant performance metrics
- Optimizing a model using cross-validation
- Interpreting a model’s decision-making process through feature weights
In the previous chapter, we set the stage for machine learning: from a raw data set, we tamed the data and crafted features based on our exploration and analysis of the data. Looking back at the data transformation steps from chapter 12, we performed the following work, resulting in a data frame named food_features:
- Read a CSV file containing dish names and multiple columns as feature candidates
- Sanitized the column names (lowered the case and fixed the punctuation, spacing, and nonprintable characters)
- Removed illogical and irrelevant records
- Filled the null values of binary columns to 0.0
- Capped the amounts for calories, protein, fat, and sodium to the 99th percentile
- Created ratio features (number of calories from a macro over number of calories for the dish)
- Imputed the mean of continuous features
- Scaled continuous features between 0.0 and 1.0