sklearn.dummy.DummyRegressor?

class sklearn.dummy.DummyRegressor(*, strategy='mean', constant=None, quantile=None)

[源碼]

DummyRegressor是一種使用簡單規則進行預測的回歸工具。

這個回歸變量作為與其他(真實)回歸變量進行比較的簡單基線非常有用。不要用它來解決真正的問題。

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

新版本0.13。

參數 說明
strategy str
用來產生預測的策略。

“mean”:總是預測訓練集的均值

“中值”:總是預測訓練集的中值

“分位數”:總是預測訓練集的指定分位數,并提供分位數參數。

“常量”:總是預測用戶提供的常量值。
constant int or float or array-like of shape (n_outputs,)
由“常數”策略預測的顯式常數。這個參數只對“常量”策略有用。
quantile float in [0.0, 1.0]
使用“分位數”策略預測的分位數。分位數0.5對應中位數,最小值為0.0,最大值為1.0。
屬性 說明
constant_ array, shape (1, n_outputs)
訓練目標的平均值、中位數、分位數或用戶給定的常數值。
n_outputs_ int,
數量的輸出。

示例

>>> import numpy as np
>>> from sklearn.dummy import DummyRegressor
>>> X = np.array([1.02.03.04.0])
>>> y = np.array([2.03.05.010.0])
>>> dummy_regr = DummyRegressor(strategy="mean")
>>> dummy_regr.fit(X, y)
DummyRegressor()
>>> dummy_regr.predict(X)
array([5.5.5.5.])
>>> dummy_regr.score(X, y)
0.0

Methods

方法 說明
fit(self, X, y[, sample_weight]) 擬合隨機回歸。
get_params(self[, deep]) 獲取這個估計器的參數。
predict(self, X[, return_std]) 對測試向量X進行分類。
score(self, X, y[, sample_weight]) 返回預測的決定系數R^2。
set_params(self, **params) 設置這個估計器的參數。
__init__(self, *, strategy='mean', constant=None, quantile=None)

[源碼]

初始化self. See 請參閱help(type(self))以獲得準確的說明 。

fit(self, X, y, sample_weight=None)

[源碼]

擬合隨機回歸。

參數 說明
X {array-like, object with finite length or shape}
訓練數據,要求length = n_samples
y array-like of shape (n_samples,) or (n_samples, n_outputs)
目標的價值。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。
返回值 說明
self object
get_params(self, deep=True)

[源碼]

獲取這個估計器的參數。

參數 說明
deep bool, default=True
如果為真,將返回此估計器的參數以及包含的作為估計器的子對象。
返回值 說明
params mapping of string to any
參數名稱映射到它們的值。
predict(self, X, return_std=False)

[源碼]

對測試向量X進行分類。

參數 說明
X {array-like, object with finite length or shape}
訓練數據,要求length = n_samples
return_std boolean, optional
是否返回后驗預測的標準差。這里都是0。

新版本0.20。
返回值 說明
y array-like of shape (n_samples,) or (n_samples, n_outputs)
X的預測目標值。
y_std array-like of shape (n_samples,) or (n_samples, n_outputs)
查詢點預測分布的標準差。
score(self, X, y, sample_weight=None)

[源碼]

返回預測的決定系數R^2。

定義系數R^2為(1 - u/v),其中u為(y_true - y_pred) ** 2).sum()的殘差平方和,v為(y_true - y_true.mean()) ** 2).sum()的平方和。最好的可能的分數是1.0,它可能是負的(因為模型可以任意地更糟)。常數模型總是預測y的期望值,而不考慮輸入特征,得到的R^2得分為0.0。

參數 說明
X {array-like, None}
使用shape = (n_samples, n_features)或None測試樣本。對于某些估計器,這可能是一個預先計算的核矩陣,形狀= (n_samples, n_samples_fitting],其中n_samples_fitting是用于擬合估計器的樣本數量。由于DummyRegressor的操作獨立于采樣的觀察結果,所以通過測試樣本的結果與通過真實測試樣本的結果是一樣的。
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
self.predict(X) 與y的R2。
set_params(self, **params)

[源碼]

設置這個估計器的參數。

該方法適用于簡單估計量和嵌套對象。后者具有形式為<component>_<parameter>的參數,這樣就讓更新嵌套對象的每個組件成為了可能。

參數 說明
**params dict
估計器參數。
返回值 說明
self object
估計實例。

sklearn.dummy.DummyRegressor使用示例?