多任务套索回归
MultiTaskLasso Regression是 Lasso 回归的增强版本。 MultiTaskLasso 是 sklearn 提供的一个模型,用于通过估计它们的稀疏系数来解决多个回归问题。所有称为任务的回归问题都有相同的特征。该模型使用混合 l1/l2 范数进行正则化训练。它在许多方面类似于 Lasso 回归。主要区别在于 alpha 参数,其中 alpha 是乘以 l1/l2 范数的常数。
MultiTaskLasso 模型具有以下参数:
alpha: a float value that multiplies l1/l2 norms. by default 1.0
fit_intercept: decide whether to use intercept for calculations.
normalize: used to normalize the regressors in the data
max_itr: number of maximum iteration. by default -1000
selection: to determine how the updation of the coefficient will take place values – {‘cyclic’, ‘random’} by default cyclic
tol: tolerance for optimization.
random_state: A random feature is selected to update.
代码:为了说明 MultiTaskLasso Regression 在Python中的工作
python3
# import linear model library
from sklearn import linear_model
# create MultiTaskLasso model
MTL = linear_model.MultiTaskLasso(alpha = 0.5)
# fit the model to a data
MTL.fit([[1, 0], [1, 3], [2, 2]], [[0, 2], [1, 4], [2, 4]])
# perform prediction and print the result
print("Prediction result: \n", MTL.predict([[0, 1]]), "\n")
# print the coefficients
print("Coefficients: \n", MTL.coef_, "\n")
# print the intercepts
print("Intercepts: \n", MTL.intercept_, "\n")
# print the number of iterations performed
print("Number of Iterations: ", MTL.n_iter_, "\n")
输出:
Prediction result:
[[0.8245348 3.04089134]]
Coefficients:
[[0. 0.26319779]
[0. 0.43866299]]
Intercepts:
[0.56133701 2.60222835]
Number of Iterations: 2