分类模型

Python 中的模型验证

Kasey Jones

Data Scientist

分类模型

  • 分类响应:
    • 新生儿的发色
    • 篮球比赛的胜者
    • 收音机下一首歌的曲风
Python 中的模型验证

井字棋数据集

... 左下 下中 右下 类别
... X O O 正类
... O X O 正类
... O O X 正类
... X X O 负类
... ... ... ... ...
Python 中的模型验证

如果你愿意,Google 可以和你下井字棋。只需访问 Google 并搜索 Tic-Tac-Toe。

Python 中的模型验证

使用 .predict() 做分类

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
Python 中的模型验证

预测概率

rfc.predict_proba(X_test)
array([[0. , 1. ],
       [0.1, 0.9],
       [0.1, 0.9],
       ...])
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
Python 中的模型验证

来分类井字棋终局情形

Python 中的模型验证

Preparing Video For Download...