PythonTrain a classifier in the browser/20 min
Do it yourself
The task
Graded on four numbers the script prints.
This is your first complete classifier with two parts missing. It is a little shorter than the lesson: there is one split, into a training part and a test part, instead of three.
- The split. Write one line that calls
train_test_splitonXandywithtest_size=0.25andrandom_state=0, and unpacks the four results intoX_train, X_test, y_train, y_test, in that order. Step 2 of "Your first complete digit classifier" does the same thing with different names and settings. - The model. Create a
KNeighborsClassifierwithn_neighbors=3, call itmodel, and fit it onX_trainandy_train.
Then run. The script prints the accuracy on the training images, the accuracy on the test images, the gap between them (training minus test: a large gap would mean the model does much better on images it stored than on new ones), and the always-one-digit baseline. Your model should score far above the baseline.
Sign in to start
Exercises need an account.
It is free. Log in or create one, and every attempt and pass is saved to your progress.