ML modeling steps

Machine Learning for Marketing in Python

Karolis Urbonas

Head of Analytics & Science, Amazon

Supervised learning steps

  1. Split data to training and testing
  2. Initialize the model
  3. Fit the model on the training data
  4. Predict values on the testing data
  5. Measure model performance on testing data
Machine Learning for Marketing in Python

Supervised learning with code

First, let's load the libraries.

from sklearn import tree
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
Machine Learning for Marketing in Python

Supervised learning steps with code

# 1. Split data to training and testing
train_X, test_X, train_Y, test_Y = train_test_split(X, Y, test_size=0.25)

# 2. Initialize the model mytree = tree.DecisionTreeClassifier()
# 3. Fit the model on the training data treemodel = mytree.fit(train_X, train_Y)
# 4. Predict values on the testing data pred_Y = treemodel.predict(test_X)
# 5. Measure model performance on testing data accuracy_score(test_Y, pred_Y)
Machine Learning for Marketing in Python

Unsupervised learning steps

  1. Initialize the model
  2. Fit the model
  3. Assign cluster values
  4. Explore results
Machine Learning for Marketing in Python

Unsupervised learning with code

First, let's load the libraries.

from sklearn.cluster import KMeans
import pandas as pd
Machine Learning for Marketing in Python

Unsupervised learning with code

1. Initialize the model
kmeans = KMeans(n_clusters=3)

# Fit the model kmeans.fit(data)
# 3. Asign cluster values data.assign(Cluster=kmeans.labels_)
# 4. Explore results data.groupby('Cluster').mean()
Machine Learning for Marketing in Python

Let's go build some models!

Machine Learning for Marketing in Python

Preparing Video For Download...