Classification models

Model Validation in Python

Kasey Jones

Data Scientist

Classification models

  • Categorical Responses:
    • Newborn's hair color
    • Winner of a basketball game
    • Genre of the next song on the radio
Model Validation in Python

The Tic-Tac-Toe dataset

... Bottom-Left Bottom-Middle Bottom-Right Class
... X O O positive
... O X O positive
... O O X positive
... X X O negative
... ... ... ... ...
Model Validation in Python

Google will play Tic-Tac-Toe against you if you would like. Just visit Google and search Tic-Tac-Toe games.

Model Validation in Python

Using .predict() for classification

from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier(random_state=1111)
rfc.fit(X_train, y_train)
rfc.predict(X_test)
array([1, 1, 1, 1, 0, 1, ...])
pd.Series(rfc.predict(X_test)).value_counts()
1    627
0    331
Model Validation in Python

Predicting probabilities

rfc.predict_proba(X_test)
array([[0. , 1. ],
       [0.1, 0.9],
       [0.1, 0.9],
       ...])
Model Validation in Python
rfc = RandomForestClassifier(random_state=1111)
rfc.get_params()
{'bootstrap': True,
 'class_weight': None,
 'criterion': 'gini',
 ...}
rfc.fit(X_train, y_train)
rfc.score(X_test, y_test)
0.8989
Model Validation in Python

Let's classify Tic-Tac-Toe end-game scenarios

Model Validation in Python

Preparing Video For Download...