Skip to content

Commit 80328dd

Browse files
更新 第8章 回归
1 parent 93159b5 commit 80328dd

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

docs/8.预测数值型数据:回归.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
![预测数值型数据回归首页](../images/8.Regression/预测数值型数据回归首页.png "回归Regression首页")
55

6-
## 回归(Regression) 概述
6+
## 回归(Regressiovn) 概述
77

88
`我们前边提到的分类的目标变量是标称型数据,而回归则是对连续型的数据做出处理,回归的目的是预测数值型数据的目标值。`
99

@@ -608,7 +608,7 @@ def regression4():
608608

609609
#### 4.4、小结
610610

611-
当应用缩减方法(如逐步线性回归或岭回归)时,模型也就增加了偏差(bias),与此同时却见笑了模型的方差
611+
当应用缩减方法(如逐步线性回归或岭回归)时,模型也就增加了偏差(bias),与此同时却减小了模型的方差
612612

613613
### 5、回归 项目案例
614614

src/python/8.PredictiveNumericalDataRegression/regression.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ def crossValidation(xArr,yArr,numVal=10):
369369
# python setup.py build
370370
# python setup.py install
371371
#
372+
'''
372373
from numpy import *
373374
from bs4 import BeautifulSoup
374375
@@ -481,7 +482,7 @@ def crossValidation(xArr,yArr,numVal=10):
481482
# 输出构建的模型
482483
print "the best model from Ridge Regression is:\n",unReg
483484
print "with constant term: ",-1*sum(multiply(meanX,unReg)) + mean(yMat)
484-
485+
'''
485486

486487

487488
#test for standRegression
@@ -491,9 +492,9 @@ def regression1():
491492
yMat = mat(yArr)
492493
ws = standRegres(xArr, yArr)
493494
fig = plt.figure()
494-
ax = fig.add_subplot(111) #add_subplot(349)函数的参数的意思是,将画布分成3行4列图像画在从左到右从上到下第9块
495-
ax.scatter(xMat[:, 1].flatten(), yMat.T[:, 0].flatten().A[0]) #scatter 的x是xMat中的第二列,y是yMat的第一列
496-
xCopy = xMat.copy()
495+
ax = fig.add_subplot(111) # add_subplot(349)函数的参数的意思是,将画布分成3行4列图像画在从左到右从上到下第9块
496+
ax.scatter([xMat[:, 1].flatten()], [yMat.T[:, 0].flatten().A[0]]) # scatter 的x是xMat中的第二列,y是yMat的第一列
497+
xCopy = xMat.copy()
497498
xCopy.sort(0)
498499
yHat = xCopy * ws
499500
ax.plot(xCopy[:, 1], yHat)
@@ -512,7 +513,7 @@ def regression2():
512513
fig = plt.figure()
513514
ax = fig.add_subplot(111)
514515
ax.plot(xSort[:,1], yHat[srtInd])
515-
ax.scatter(xMat[:,1].flatten().A[0], mat(yArr).T.flatten().A[0] , s=2, c='red')
516+
ax.scatter([xMat[:,1].flatten().A[0]], [mat(yArr).T.flatten().A[0]] , s=2, c='red')
516517
plt.show()
517518

518519

@@ -576,17 +577,17 @@ def regression4():
576577

577578
# predict for lego's price
578579
def regression5():
579-
lgX = []
580-
lgY = []
580+
lgX = []
581+
lgY = []
581582

582-
setDataCollect(lgX, lgY)
583-
crossValidation(lgX, lgY, 10)
583+
setDataCollect(lgX, lgY)
584+
crossValidation(lgX, lgY, 10)
584585

585586

586587
if __name__ == "__main__":
587-
regression1()
588+
# regression1()
588589
# regression2()
589-
# abaloneTest()
590+
abaloneTest()
590591
# regression3()
591592
# regression4()
592-
# regression5()
593+
# regression5()

0 commit comments

Comments
 (0)