Scikit-Learn 常用函数
生活随笔
收集整理的這篇文章主要介紹了
Scikit-Learn 常用函数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Scikit-Learn 常用函數(shù)
1、數(shù)據(jù)集劃分
函數(shù)原型:
train_test_split(train_data, train_label, test_size=None, random_state=None, shuffle=True)
- train_data:數(shù)據(jù)集的數(shù)據(jù),可以是列表或者numpy數(shù)組
- train_label:數(shù)據(jù)集的標簽
- test_size:測試集的樣本占比(0.0, 1.0),如果是整數(shù)的話就是樣本的數(shù)量
- random_state:隨機數(shù)的種子
shuffle: 是否需要打亂數(shù)據(jù)集
返回劃分完成的數(shù)據(jù),順序:訓(xùn)練集數(shù)據(jù)、測試集數(shù)據(jù)、訓(xùn)練集標簽、測試集標簽
實例:
# 導(dǎo)入相關(guān)函數(shù) from sklearn.model_selection import train_test_split# 按照測試集占0.2得比例劃分數(shù)據(jù)集 X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2)2、評估指標
sklearn.metrics:
- accuracy_score:準確率
- average_precision_score:平均準確率
- confusion_matrix:混淆矩陣
- precision_score:精確率,查準率
- recall_score:召回率
- f1_score:FI值
- classification_report:包含precision_score、recall_score、f1_score
xx(y_true, y_pred):
- y_true : numpy數(shù)組shape = [n_samples],真實標簽值
- y_pred : numpy數(shù)組shape = [n_samples],預(yù)測值
實例:
# 導(dǎo)入相關(guān)函數(shù) from sklearn.model_selection import confusion_matrix# 計算混淆矩陣 confu_matrix = confusion_matrix(y_true=train_label, y_pred=train_pred)總結(jié)
以上是生活随笔為你收集整理的Scikit-Learn 常用函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 编程语言_如何正确地学习编程语言
- 下一篇: 全国计算机英语四六级准考证打印准考证号,