sklearn.model_selection.validation_curve?

sklearn.model_selection.validation_curve(estimator, X, y, *, param_name, param_range, groups=None, cv=None, scoring=None, n_jobs=None, pre_dispatch='all', verbose=0, error_score=nan)

[源碼]

驗證曲線。

用于確定不同參數值的訓練集和測試集準確率。

計算具有指定參數不同值的估計器的準確率。這類似于帶有一個參數的網格搜索。但是,也會計算訓練集的準確率,僅是一個繪制結果的工具。

用戶指南中閱讀更多內容。

參數 說明
estimator object type that implements the “fit” and “predict” methods
每次驗證都會克隆的該類型的對象。
X array-like of shape (n_samples, n_features)
用于訓練的向量,其中n_samples是樣本數量,n_features是特征數量。
y array-like of shape (n_samples,) or (n_samples, n_outputs) or None
相對于X的標簽,用于分類或回歸;無監督學習為None
param_name str
將會改變的參數名稱。
param_range array-like of shape (n_values,)
將要評估的參數值。
groups array-like of shape (n_samples,), default=None
將數據集拆分為訓練/測試集時使用的樣本的標簽分組。僅與“ Group” cv 實例(例如GroupKFold)結合使用。
cv int, cross-validation generator or an iterable, default=None
確定交叉驗證切分策略。cv值可以輸入:

- None,默認使用5折交叉驗證
- int,用于指定(Stratified)KFold的折數
- CV splitter,
- 可迭代輸出訓練集和測試集的切分作為索引數組

對于int或 None輸入,如果估計器是分類器,并且y是二分類或多分類,則使用StratifiedKFold。在所有其他情況下,均使用KFold

有關可在此處使用的各種交叉驗證策略,請參閱用戶指南

在版本0.22中:如果cv為None,默認值從3折更改為5折。
scoring str or callable, default=None
一個str(參見模型評估文檔)或一個信息為scorer(estimator, X, y)的可調用對象或函數的評分器,它應該只返回一個值。
n_jobs int, default=None
用于進行計算的CPU數量。 None除非在joblib.parallel_backend環境中,否則表示1 。 undefined表示使用所有處理器。有關更多詳細信息,請參見詞匯表
pre_dispatch int or str, default=’all’
并行執行的預調用CPU數(默認為全部)。該選項可以減少分配的內存。str可以是類似“ 2 * n_jobs”的表達式。
verbose int, default=0
控制詳細程度:越高,消息越多。
error_score ‘raise’ or numeric, default=np.nan
如果估計器擬合出現錯誤,則分配給分數的值。如果設置為“ raise”,則會引發錯誤。如果給出數值,則引發FitFailedWarning。此參數不會影響重新擬合步驟,這將總是引發錯誤。

0.20版中的新功能。
返回值 說明
train_scores array of shape (n_ticks, n_cv_folds)
訓練集準確率。
test_scores array of shape (n_ticks, n_cv_folds)
測試集準確率。

參閱 繪制驗證曲線

sklearn.model_selection.validation_curve使用示例?