Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Predicting CTR with Machine Learning in Python

Cursus bekijken

Oefeninstructies

  • Standard scale the features using .fit_transform() and split data into training and testing sets using train_test_split().
  • Create a MLP classifier.
  • Create predictions using the classifier and evaluate the accuracy using accuracy_score().

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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))
Code bewerken en uitvoeren