LoslegenKostenlos loslegen

Center and scale with StandardScaler()

We've loaded the same dataset named data. Now your goal will be to center and scale them with StandardScaler from sklearn library.

Libraries pandas, numpy, seaborn and matplotlib.pyplot have been loaded as pd, np, sns and plt respectively. We have also imported the StandardScaler.

Feel free to explore the dataset in the console.

Diese Übung ist Teil des Kurses

Customer Segmentation in Python

Kurs anzeigen

Anleitung zur Übung

  • Initialize StandardScaler instance as scaler and fit it to the data
  • Transform the data by scaling and centering it with scaler.
  • Create a pandas DataFrame from data_normalized by adding index and column names from data.
  • Print summary statistics to make sure average is zero and standard deviation is one, and round the results to 2 decimals.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Initialize a scaler
scaler = ____()

# Fit the scaler
____.____(data)

# Scale and center the data
data_normalized = ____.____(data)

# Create a pandas DataFrame
data_normalized = pd.DataFrame(____, index=data.index, columns=data.columns)

# Print summary statistics
print(data_normalized.____().round(____))
Code bearbeiten und ausführen