@@ -369,6 +369,7 @@ def crossValidation(xArr,yArr,numVal=10):
369369# python setup.py build
370370# python setup.py install
371371#
372+ '''
372373from numpy import *
373374from 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
578579def 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
586587if __name__ == "__main__" :
587- regression1 ()
588+ # regression1()
588589 # regression2()
589- # abaloneTest()
590+ abaloneTest ()
590591 # regression3()
591592 # regression4()
592- # regression5()
593+ # regression5()
0 commit comments