ML之PLiR之LARS:利用LARS算法求解ElasticNet回归类型问题(实数值评分预测)
目录
设计思路
输出结果
1、LARS
2、10-fold cross validation
实现代码
设计思路
更新……
输出结果
['"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 betabeta = [0.0] * ncols#initialize matrix of betas at each stepbetaMat = []betaMat.append(list(beta))#number of steps to takenSteps = 350stepSize = 0.004nzList = []for i in range(nSteps):#calculate residualsresiduals = [0.0] * nrowsfor 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 residualcorr = [0.0] * ncolsfor j in range(ncols):corr[j] = sum([xNormalized[k][j] * residuals[k] for k in range(nrows)]) / nrowsiStar = 0corrStar = 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 attributecoefCurve = [betaMat[k][i] for k in range(nSteps)]xaxis = range(nSteps)plot.plot(xaxis, coefCurve)
如果觉得《ML之PLiR之LARS:利用LARS算法求解ElasticNet回归类型问题(实数值评分预测)》对你有帮助,请点赞、收藏,并留下你的观点哦!