sklearn.linear_model.enet_path?

sklearn.linear_model.enet_path(X, y, *, l1_ratio=0.5, eps=0.001, n_alphas=100, alphas=None, precompute='auto', Xy=None, copy_X=True, coef_init=None, verbose=False, return_n_iter=False, positive=False, check_input=True, **params)

[源碼]

計算具有坐標下降的彈性網絡路徑。

對于單輸出和多輸出,彈性網絡優化函數各不相同。

單輸出任務為:

多輸出任務為:

(1 / (2 * n_samples)) * ||Y - XW||^Fro_2
+ alpha * l1_ratio * ||W||_21
0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2

其中:

||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}

即每一行的范數之和。

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

參數 說明
X {array-like, sparse matrix} of shape (n_samples, n_features)
用于訓練的數據。直接作為Fortran-contiguous數據傳遞,避免不必要的內存重復。如果y是單輸出,則X 可以是稀疏的。
y {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)
目標值。
l1_ratio float, default=0.5
0到1之間的數字傳遞給彈性網(在l1和l2懲罰之間縮放)。l1_ratio=1對應于套索(Lasso)。
eps float, default=1e-3
路徑的長度。eps=1e-3意味著alpha_min / alpha_max = 1e-3
n_alphas int, default=100
沿著正則化路徑的Alpha數。
alphas ndarray, default=None
用于在其中計算模型的alpha列表。如果為None,則自動設置Alpha。
precompute ‘auto’, bool or array-like of shape (n_features, n_features), default=’auto’
是否使用預先計算的Gram矩陣來加快計算速度。如果設置'auto'讓我們決定。Gram矩陣也可以作為參數被傳遞。
Xy array-like of shape (n_features,) or (n_features, n_outputs), default=None
可以預先計算Xy = np.dot(XT,y)。僅當預先計算了Gram矩陣時才有用。
copy_X bool, default=True
如果為True,將復制X;否則,它可能會被覆蓋。
coef_init ndarray of shape (n_features, ), default=None
系數的初始值。
verbose bool or int, default=False
詳細程度。
return_n_iter bool, default=False
是否返回迭代次數。
positive bool, default=False
如果設置為True,則強制系數為正。(僅當y.ndim == 1時允許)。
check_input bool, default=True
跳過輸入驗證檢查,包括提供的Gram矩陣(假設提供),假設在check_input = False時由調用方處理。
**params kwargs
關鍵字參數傳遞給坐標下降求解器。
返回值 說明
alphas ndarray of shape (n_alphas,)
沿模型計算路徑的Alpha。
coefs ndarray of shape (n_features, n_alphas) or (n_outputs, n_features, n_alphas)
沿路徑的系數。
dual_gaps ndarray of shape (n_alphas,)
每個alpha優化結束時的雙重間隔。
n_iters list of int
坐標下降優化器為達到每個alpha的指定公差所進行的迭代次數。(當return_n_iter設置為True 時返回)。

另見:

MultiTaskElasticNet

MultiTaskElasticNetCV

ElasticNet

ElasticNetCV

有關示例,請參閱examples/linear_model/plot_lasso_coordinate_descent_path.py.

sklearn.linear_model.enet_path使用示例?