sklearn.linear_model.RidgeClassifierCV?
class sklearn.linear_model.RidgeClassifierCV(alphas=(0.1, 1.0, 10.0), *, fit_intercept=True, normalize=False, scoring=None, cv=None, class_weight=None, store_cv_values=False)
內置交叉驗證的Ridge分類器。
有關交叉驗證估算器,請參閱詞匯表。
默認情況下,它執行泛化的交叉驗證,這是一種有效的“留一法”交叉驗證的形式。目前,僅有效處理n_features> n_samples的情況。
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
alphas | ndarray of shape (n_alphas,), default=(0.1, 1.0, 10.0) 要嘗試的Alpha值數組。正則強度,必須為正浮點數。正則化改善了問題的狀況,并減少了估計的方差。較大的值表示更強的正則化。在其他線性模型中,Alpha對應于 1 / (2C) ,例如 LogisticRegression 或sklearn.svm.LinearSVC |
fit_intercept | bool, default=True 是否計算此模型的截距。如果設置為false,則在計算中將不使用截距(如數據已經中心化)。 |
normalize | bool, default=Falsefit_intercept 設置為False 時,將忽略此參數。如果為True,則在回歸之前通過減去均值并除以l2-范數來對回歸變量X進行歸一化。如果你希望標準化,請先使用 sklearn.preprocessing.StandardScaler ,然后調用fit 估算器并設置normalize=False 。 |
scoring | string, callable, default=None 字符串(請參閱模型評估文檔)或帶 scorer(estimator, X, y) 簽名的評分器可調用對象 。 |
cv | int, cross-validation generator or an iterable, default=None - None,使用有效的“留一法”交叉驗證 - 整數,用于指定折疊數。 - CV分割器, - 可迭代生成(分割訓練、測試)索引數組。 有關可在此處使用的各種交叉驗證策略,請參閱用戶指南。 |
class_weight | dict or ‘balanced’, default=None 以 {class_label: weight} 的形式與類別關聯的權重。如果沒有給出,所有類別的權重都應該是1。“balanced”模式使用y的值來自動調整為與輸入數據中的類頻率成反比的權重。如 n_samples / (n_classes * np.bincount(y)) |
store_cv_values | bool, default=False 是否將與每個alpha對應的交叉驗證值存儲在 cv_values_ 屬性中(請參見下文)。該參數僅與cv=None (即使用通用交叉驗證)兼容。 |
屬性 | 說明 |
---|---|
cv_values_ | ndarray of shape (n_samples, n_targets, n_alphas), optional 每個alpha的交叉驗證值(當 store_cv_values=True 和 cv=None )。fit() 被調用之后,此屬性將包含均方誤差(默認)或 {loss,score}_func 函數(如果在構造函數中提供)的值。僅當store_cv_values 為True 時,此屬性才存在。 |
coef_ | ndarray of shape (1, n_features) or (n_classes, n_features) 決策函數中特征的系數。 當給定問題為二分類時, coef_ 形狀為(1,n_features)。 |
intercept_ | float or ndarray of shape (n_targets,) 決策函數中的截距。如果設置 fit_intercept = False ,則截距為0.0 。 |
alpha_ | float 估計的正則化參數。 |
best_score_ | float 具有最佳alpha值的基計器得分。 |
classes_ | ndarray of shape (n_classes,) 類別標簽。 |
另見
嶺回歸
嶺分類器
內置交叉驗證的Ridge回歸
注
對于多類別分類,以“一對多”的方法訓練n_class分類器。具體而言,這是通過利用Ridge中的多變量響應支持來實現的。
示例
>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import RidgeClassifierCV
>>> X, y = load_breast_cancer(return_X_y=True)
>>> clf = RidgeClassifierCV(alphas=[1e-3, 1e-2, 1e-1, 1]).fit(X, y)
>>> clf.score(X, y)
0.9630...
方法
方法 | 說明 |
---|---|
decision_function (self, X) |
預測樣本的置信度得分。 |
fit (self, X, y[, sample_weight]) |
擬合Ridge分類器模型。 |
get_params (self[, deep]) |
獲取此估計器的參數。 |
predict (self, X) |
預測X中樣本的類別標簽。 |
score (self, X, y[, sample_weight]) |
返回給定測試數據和標簽上的平均準確度。 |
set_params (self, **params) |
設置此估計器的參數。 |
__init__(self, alphas=(0.1, 1.0, 10.0), *, fit_intercept=True, normalize=False, scoring=None, cv=None, class_weight=None, store_cv_values=False)
初始化self, 請參閱help(type(self))以獲得準確的說明。
decision_function(self, X)
預測樣本的置信度得分。
樣本的置信度分數是該樣本到超平面的符號距離。
參數 | 說明 |
---|---|
X | array_like or sparse matrix, shape (n_samples, n_features) 樣本數據。 |
返回值 | 說明 |
---|---|
array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes) 每個(樣本,類別)組合的置信度得分。在二分類情況下,self.classes_ [1]的置信度得分> 0表示將預測該類。 |
fit(self,X,y,sample_weight = None )
[源碼]
擬合帶有交叉驗證的Ridge分類器模型。
參數 | 說明 |
---|---|
X | ndarray of shape (n_samples, n_features) 訓練數據,其中n_samples是樣本數,n_features是特征數。使用GCV時,如有必要,將其強制轉換為float64。 |
y | ndarray of shape (n_samples,) 如有必要,將強制轉換為X的類型。 |
sample_weight | float or ndarray of shape (n_samples,), default=None 每個樣本的權重,如果使用浮點數,每個樣品的權重都相同。 |
返回值 | 說明 |
---|---|
self | object |
get_params(self,deep = True )
[源碼]
獲取此估計器的參數。
參數 | 說明 |
---|---|
deep | bool, default=True 如果為True,返回此估計器和所包含子對象的參數。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到其值。 |
predict(self, X)
[源碼]
預測X中樣本的類別標簽。
參數 | 說明 |
---|---|
X | array_like or sparse matrix, shape (n_samples, n_features) 樣本數據 |
返回值 | 說明 |
---|---|
C | array, shape [n_samples] 每個樣本的預測類別標簽。 |
score(self,X,y,sample_weight = None )
[源碼]
返回給定測試數據和標簽上的平均準確度。
在多標簽分類中,這是子集準確性,這是一個嚴格的指標,因為你需要為每個樣本正確預測對應的標簽集。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 測試樣本。 |
y | array-like of shape (n_samples,) or (n_samples, n_outputs) X的真實標簽。 |
sample_weight | array-like of shape (n_samples,), default=None 樣本權重。 |
返回值 | 說明 |
---|---|
score | float 預測標簽與真實標簽的平均準確度 |
set_params(self, **params)
[源碼]
設置并驗證估計器的參數。
該方法適用于簡單的估計器以及嵌套對象(例如管道)。后者具有<component>__<parameter>
形式的參數, 以便可以更新嵌套對象的每個組件。
參數 | 說明 |
---|---|
**params | dict 估計器參數。 |
返回值 | 說明 |
---|---|
self | object 估計器實例。 |