Solution: Customer Segmentation
Walk-through the solution of the challenge.
Task 1
Here is the solution to the feature engineering challenge.
Press + to interact
import numpy as npimport pandas as pd# Task 1: Read the csv dataset named 'mall_customers.csv', use the first row as headerdf_customers = pd.read_csv('mall_customers.csv', header=0)# Task 2: Encode 'Gender' columndf_customers['Gender'] = df_customers['Gender'].apply(lambda x: 1 if x=='Male' else 0)# Task 3: Pick 'AnnualIncome' and 'SpendingScore' for the segmentation modeldf_features = df_customers[['AnnualIncome', 'SpendingScore']]# Task 4: Standardize the features# Task 4.1: Import the StandardScaler class from Scikit-learnfrom sklearn.preprocessing import StandardScaler# Task 4.2: Create an object of the Standard Scalerscaler = StandardScaler()# Task 4.3: Scale the df_features dataframefeatures_std = scaler.fit_transform(df_features)
Explanation