Beginning model
In this exercise, you will build an MLP classifier on the dataset of images used in chapter 1. As a reminder, each image represents a number 0
through 9
and the goal is to classify each imagine as a number. The features used are specific pixel values ranging from 0-16 that make up the image. After scaling features, you will evaluate the accuracy of the classifier on the testing set.
In your workspace, sample image data in DataFrame form is loaded as image_data
along with sklearn
and pandas
as pd
. StandardScaler()
from sklearn.preprocessing
is available as well.
This exercise is part of the course
Predicting CTR with Machine Learning in Python
Exercise instructions
- Standard scale the features using
.fit_transform()
and split data into training and testing sets usingtrain_test_split()
. - Create a MLP classifier.
- Create predictions using the classifier and evaluate the accuracy using
accuracy_score()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define X and y
X, y = image_data.data, image_data.target
# Scale features and split into training and testing
X_scaled = ____().____(X)
X_train, X_test, y_train, y_test = ____(
X_scaled, y, test_size = .2, random_state = 0)
# Create classifier, train and evaluate accuracy
clf = ____()
y_pred = clf.____(X_train, y_train).____(X_test)
print(____(y_test, y_pred))