Separate features and target variable
Now that you have split the data intro training and testing, it's time to perform he final step before fitting the model which is to separate the features and target variables into different datasets. You will use the list of columns names that have been loaded for you.
The main dataset is loaded as telcom
, and split into training and testing datasets which are loaded as pandas
DataFrames into train
and test
respectively. The target
and custid
lists contain the names of the target variable and the customer ID respectively. You will have to create the cols
list with the names of the remaining columns. Feel free to explore the datasets in the console.
This is a part of the course
“Machine Learning for Marketing in Python”
Exercise instructions
- Store the column names of
telcom
in a list excluding the target variable and customer ID names. - Extract the training features and target.
- Extract the testing features and target.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Store column names from `telcom` excluding target variable and customer ID
cols = [col for col in ___.columns if col not in ___ + target]
# Extract training features
train_X = train[___]
# Extract training target
train_Y = train[___]
# Extract testing features
test_X = test[___]
# Extract testing target
test_Y = test[___]
This exercise is part of the course
Machine Learning for Marketing in Python
From customer lifetime value, predicting churn to segmentation - learn and implement Machine Learning use cases for Marketing in Python.
In this chapter you will learn churn prediction fundamentals, then fit logistic regression and decision tree models to predict churn. Finally, you will explore the results and extract insights on what are the drivers of the churn.
Exercise 1: Churn prediction fundamentalsExercise 2: Explore churn rate and split dataExercise 3: Separate features and target variableExercise 4: Predict churn with logistic regressionExercise 5: Fit logistic regression modelExercise 6: Fit logistic regression with L1 regularizationExercise 7: Identify optimal L1 penalty coefficientExercise 8: Predict churn with decision treesExercise 9: Fit decision tree modelExercise 10: Identify optimal tree depthExercise 11: Identify and interpret churn driversExercise 12: Explore logistic regression coefficientsExercise 13: Break down decision tree rulesWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.