Merge pull request #163 from jiangzhonglian/master

更新 第8章 回归
This commit is contained in:
Joy yx
2017-09-19 22:22:35 +08:00
committed by GitHub
2 changed files with 15 additions and 14 deletions

View File

@@ -3,7 +3,7 @@
![预测数值型数据回归首页](../images/8.Regression/预测数值型数据回归首页.png "回归Regression首页")
## 回归Regression 概述
## 回归Regressiovn 概述
`我们前边提到的分类的目标变量是标称型数据,而回归则是对连续型的数据做出处理,回归的目的是预测数值型数据的目标值。`
@@ -608,7 +608,7 @@ def regression4():
#### 4.4、小结
当应用缩减方法如逐步线性回归或岭回归模型也就增加了偏差bias与此同时却见笑了模型的方差。
当应用缩减方法如逐步线性回归或岭回归模型也就增加了偏差bias与此同时却减小了模型的方差。
### 5、回归 项目案例

View File

@@ -369,6 +369,7 @@ gt56 trainY.append(yArr[indexList[j]])
# python setup.py build
# python setup.py install
#
'''
from numpy import *
from bs4 import BeautifulSoup
@@ -481,7 +482,7 @@ def crossValidation(xArr,yArr,numVal=10):
# 输出构建的模型
print "the best model from Ridge Regression is:\n",unReg
print "with constant term: ",-1*sum(multiply(meanX,unReg)) + mean(yMat)
'''
#test for standRegression
@@ -491,9 +492,9 @@ def regression1():
yMat = mat(yArr)
ws = standRegres(xArr, yArr)
fig = plt.figure()
ax = fig.add_subplot(111) #add_subplot(349)函数的参数的意思是将画布分成3行4列图像画在从左到右从上到下第9块
ax.scatter(xMat[:, 1].flatten(), yMat.T[:, 0].flatten().A[0]) #scatter 的x是xMat中的第二列y是yMat的第一列
xCopy = xMat.copy()
ax = fig.add_subplot(111) # add_subplot(349)函数的参数的意思是将画布分成3行4列图像画在从左到右从上到下第9块
ax.scatter([xMat[:, 1].flatten()], [yMat.T[:, 0].flatten().A[0]]) # scatter 的x是xMat中的第二列y是yMat的第一列
xCopy = xMat.copy()
xCopy.sort(0)
yHat = xCopy * ws
ax.plot(xCopy[:, 1], yHat)
@@ -512,7 +513,7 @@ def regression2():
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(xSort[:,1], yHat[srtInd])
ax.scatter(xMat[:,1].flatten().A[0], mat(yArr).T.flatten().A[0] , s=2, c='red')
ax.scatter([xMat[:,1].flatten().A[0]], [mat(yArr).T.flatten().A[0]] , s=2, c='red')
plt.show()
@@ -576,17 +577,17 @@ def regression4():
# predict for lego's price
def regression5():
lgX = []
lgY = []
lgX = []
lgY = []
setDataCollect(lgX, lgY)
crossValidation(lgX, lgY, 10)
setDataCollect(lgX, lgY)
crossValidation(lgX, lgY, 10)
if __name__ == "__main__":
regression1()
# regression1()
# regression2()
# abaloneTest()
abaloneTest()
# regression3()
# regression4()
# regression5()
# regression5()