sklearn.linear_model.TweedieRegressor?

class sklearn.linear_model.TweedieRegressor(*, power=0.0, alpha=1.0, fit_intercept=True, link='auto', max_iter=100, tol=0.0001, warm_start=False, verbose=0)

[源碼]

具有Tweedie分布的廣義線性模型。

此估計器可用于根據power參數確定不同的GLM ,從而確定基礎分布。

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

參數 說明
power float, default=0
power根據下表確定基礎目標分布:

對于0 < power < 1,不存在分布。
alpha float, default=1
該常數乘以懲罰項,從而確定正則化強度。alpha = 0等同于未懲罰的GLM。在這種情況下,設計矩陣X必須具有全列秩(無共線性)。
link {‘auto’, ‘identity’, ‘log’}, default=’auto’
GLM的鏈接函數,即從線性預測模型X @ coeff + intercept到預測值y_pred的映射 。選項“auto”根據所選族設置link,如下所示:
- ‘identity’ 對應正態分布
- ‘log’ 對應泊松,伽瑪和高斯逆分布
fit_intercept bool, default=True
是否將常數(即偏置或截距)添加到線性預測模型(X @ coef +截距)。
max_iter int, default=100
求解器的最大迭代次數。
tol float, default=1e-4
停止標準。對于lbfgs求解器,當max{g_j,j = 1, ..., d} <= tol,其中g_j為目標函數的梯度(導數)的第j個分量,迭代將停止。
warm_start bool, default=False
如果設置為True,重用前面調用的解決方案進行fit,作為coef_intercept_的初始化。
verbose int, default=0
對于lbfgs求解器,請將verbose設置為代表詳細程度的任何正數。
屬性 說明
coef_ array of shape (n_features,)
GLM中線性預測模型(X @ coef_ + intercept_)的估計系數。
intercept_ float
已添加到線性預測變量中的截距(又稱偏置)。
n_iter_ int
求解器中使用的實際迭代數。

方法

方法 說明
fit(X, y[, sample_weight]) 擬合廣義線性模型。
get_params([deep]) 獲取此估計器的參數。
predict(X) 利用GLM與特征矩陣X進行預測。
score(X, y[, sample_weight]) 計算D ^ 2,說明偏差百分比。
set_params(**params) 設置此估計器的參數。
__init__(*, power=0.0, alpha=1.0, fit_intercept=True, link='auto', max_iter=100, tol=0.0001, warm_start=False, verbose=0)

[源碼]

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

fit(X, y, sample_weight=None)

[源碼]

擬合廣義線性模型。

參數 說明
X {array-like, sparse matrix} of shape (n_samples, n_features)
訓練數據。
y array-like of shape (n_samples,)
目標值。
sample_weight array-like of shape (n_samples,), default=None
樣本權重
返回值 說明
self returns an instance of self.
get_params(deep=True)

[源碼]

獲取此估計器的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算器和所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
predict(X)

[源碼]

使用GLM與特征矩陣X進行預測。

參數 說明
X {array-like, sparse matrix} of shape (n_samples, n_features)
樣本數據
返回值 說明
y_pred array of shape (n_samples,) 返回預測值。
score(X, y, sample_weight=None)

[源碼]

計算D ^ 2,說明偏差百分比。

D ^ 2是確定系數R ^ 2的推廣。R ^ 2使用平方誤差,D ^ 2使用偏差。請注意,對于family='normal',這兩個是相等的。

D ^ 2定義為 是零偏差,即僅具有截距的模型的偏差,對應于 。均值由sample_weight取平均值。最佳可能得分為1.0,并且可能為負(因為該模型可能會更差)。

參數 說明
X {array-like, sparse matrix} of shape (n_samples, n_features)
測試樣本。
y array-like of shape (n_samples,)
目標的真實值。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。
返回值 說明
score float
預測值與真實值的D^2。
set_params(**params)

[源碼]

設置此估計器的參數。

該方法適用于簡單的估計器以及嵌套對象(例如管道)。后者具有形式為 <component>__<parameter>的參數,這樣就可以更新嵌套對象的每個組件。

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

sklearn.linear_model.TweedieRegressor使用示例?