ML之PLiR之LARS:利用LARS算法求解ElasticNet回归类型问题(实数值评分预测)
【摘要】 ML之PLiR之LARS:利用LARS算法求解ElasticNet回归类型问题(实数值评分预测)
目录
设计思路
输出结果
1、LARS
2、10-fold cross validation
实现代码
设计思路
更新……
输出结果
['"alcohol"', '"volatile acidity"', '"sul...
ML之PLiR之LARS:利用LARS算法求解ElasticNet回归类型问题(实数值评分预测)
目录
设计思路
更新……
输出结果
['"alcohol"', '"volatile acidity"', '"sulphates"', '"total sulfur dioxide"', '"chlorides"', '"fixed acidity"', '"pH"', '"free sulfur dioxide"', '"citric acid"', '"residual sugar"', '"density"']
1、LARS
2、10-fold cross validation
Minimum Mean Square Error 0.5873018933136459
Index of Minimum Mean Square Error 311
实现代码
-
#initialize a vector of coefficients beta
-
beta = [0.0] * ncols
-
-
#initialize matrix of betas at each step
-
betaMat = []
-
betaMat.append(list(beta))
-
-
-
#number of steps to take
-
nSteps = 350
-
stepSize = 0.004
-
nzList = []
-
-
for i in range(nSteps):
-
#calculate residuals
-
residuals = [0.0] * nrows
-
for j in range(nrows):
-
labelsHat = sum([xNormalized[j][k] * beta[k] for k in range(ncols)])
-
residuals[j] = labelNormalized[j] - labelsHat
-
-
#calculate correlation between attribute columns from normalized wine and residual
-
corr = [0.0] * ncols
-
-
for j in range(ncols):
-
corr[j] = sum([xNormalized[k][j] * residuals[k] for k in range(nrows)]) / nrows
-
-
iStar = 0
-
corrStar = corr[0]
-
-
for j in range(1, (ncols)):
-
if abs(corrStar) < abs(corr[j]):
-
iStar = j; corrStar = corr[j]
-
-
beta[iStar] += stepSize * corrStar / abs(corrStar)
-
betaMat.append(list(beta))
-
-
-
nzBeta = [index for index in range(ncols) if beta[index] != 0.0]
-
for q in nzBeta:
-
if (q in nzList) == False:
-
nzList.append(q)
-
-
nameList = [names[nzList[i]] for i in range(len(nzList))]
-
-
print(nameList)
-
for i in range(ncols):
-
#plot range of beta values for each attribute
-
coefCurve = [betaMat[k][i] for k in range(nSteps)]
-
xaxis = range(nSteps)
-
plot.plot(xaxis, coefCurve)
文章来源: yunyaniu.blog.csdn.net,作者:一个处女座的程序猿,版权归原作者所有,如需转载,请联系作者。
原文链接:yunyaniu.blog.csdn.net/article/details/85041666
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)