Scikit-Learn 常用函数
生活随笔
收集整理的這篇文章主要介紹了
Scikit-Learn 常用函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Scikit-Learn 常用函數
1、數據集劃分
函數原型:
train_test_split(train_data, train_label, test_size=None, random_state=None, shuffle=True)
- train_data:數據集的數據,可以是列表或者numpy數組
- train_label:數據集的標簽
- test_size:測試集的樣本占比(0.0, 1.0),如果是整數的話就是樣本的數量
- random_state:隨機數的種子
shuffle: 是否需要打亂數據集
返回劃分完成的數據,順序:訓練集數據、測試集數據、訓練集標簽、測試集標簽
實例:
# 導入相關函數 from sklearn.model_selection import train_test_split# 按照測試集占0.2得比例劃分數據集 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數組shape = [n_samples],真實標簽值
- y_pred : numpy數組shape = [n_samples],預測值
實例:
# 導入相關函數 from sklearn.model_selection import confusion_matrix# 計算混淆矩陣 confu_matrix = confusion_matrix(y_true=train_label, y_pred=train_pred)總結
以上是生活随笔為你收集整理的Scikit-Learn 常用函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 编程语言_如何正确地学习编程语言
- 下一篇: 全国计算机英语四六级准考证打印准考证号,