Aan de slagGa gratis aan de slag

Scaling data - standardizing columns

Since we know that the Ash, Alcalinity of ash, and Magnesium columns in the wine dataset are all on different scales, let's standardize them in a way that allows for use in a linear model.

Deze oefening maakt deel uit van de cursus

Preprocessing for Machine Learning in Python

Cursus bekijken

Oefeninstructies

  • Import the StandardScaler class.
  • Instantiate a StandardScaler() and store it in the variable, scaler.
  • Create a subset of the wine DataFrame containing the Ash, Alcalinity of ash, and Magnesium columns, assign it to wine_subset.
  • Fit and transform the standard scaler to wine_subset.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import StandardScaler
from sklearn.preprocessing import ____

# Create the scaler
scaler = ____

# Subset the DataFrame you want to scale 
____ = wine[[____]]

# Apply the scaler to wine_subset
wine_subset_scaled = scaler.____(____)
Code bewerken en uitvoeren