...

/

Solution: Customer Segmentation

Solution: Customer Segmentation

Walk-through the solution of the challenge.

We'll cover the following...

Task 1

Here is the solution to the feature engineering challenge.

Press + to interact
import numpy as np
import pandas as pd
# Task 1: Read the csv dataset named 'mall_customers.csv', use the first row as header
df_customers = pd.read_csv('mall_customers.csv', header=0)
# Task 2: Encode 'Gender' column
df_customers['Gender'] = df_customers['Gender'].apply(lambda x: 1 if x=='Male' else 0)
# Task 3: Pick 'AnnualIncome' and 'SpendingScore' for the segmentation model
df_features = df_customers[['AnnualIncome', 'SpendingScore']]
# Task 4: Standardize the features
# Task 4.1: Import the StandardScaler class from Scikit-learn
from sklearn.preprocessing import StandardScaler
# Task 4.2: Create an object of the Standard Scaler
scaler = StandardScaler()
# Task 4.3: Scale the df_features dataframe
features_std = scaler.fit_transform(df_features)

Explanation

    ...