Understanding data scaling and normalization
If we inspect the coefficients of our mpg
model, from the Training, validation, and test splits section earlier, we see that they range over several orders of magnitude. The code here iterates over the variable names and coefficient values, taking advantage of Python's .enumerate()
method that iterates over the column names but also returns a counter, which we capture in coef
and use to index the model coefficients. For reference, the code prints the range of the variable in data used to fit the model:
print('var\t coef\t\t\t range')
for coef, var in enumerate(my_data.columns[1:-1]):
print(var, '\t', round(my_model.coef_[0][coef], 5),
'\twith range ', round(float(my_data[var].max() -
...