我尝试在python中使用套索回归。 我正在使用scikit学习库中的套索函数。在
我希望我的模型在训练时不要惩罚某些变量。(仅惩罚其余变量)
以下是我目前的培训代码
rg_mdt = linear_model.LassoCV(alphas=np.array(10**np.linspace(0, -4, 100)), fit_intercept=True, normalize=True, cv=10)
rg_mdt.fit(df_mdt_rgmt.loc[df_mdt_rgmt.CLUSTER_ID == k].drop(['RESPONSE', 'CLUSTER_ID'], axis=1), df_mdt_rgmt.loc[df_mdt_rgmt.CLUSTER_ID == k, 'RESPONSE'])
df_mdt_rgmt是数据集市,我试图将某些列的系数保持为非零。在
在python中提供了这个参数,但是这个参数是怎么做到的?在
下面是我在R中的代码
^{pr2}$
恐怕不行。当然这不是一个理论问题,只是一个设计决定。在
我的推理是基于可用的API的,虽然有时会有未记录的函数,但这次我不认为有您需要的,因为user-guide已经以1-factor-norm-of-all形式
alpha*||w||_1
发布了这个问题根据您的设置,您可能会修改sklearn的代码(有点害怕CD调整),甚至使用scipy.optimize公司(尽管后者可能会慢一点)。在
下面是一些示例scipy.optimize公司接近。我去掉了intercept,简化了问题
输出:
^{pr2}$相关问题 更多 >
编程相关推荐