mirror of
https://github.com/apachecn/ailearning.git
synced 2026-02-13 15:26:28 +08:00
更新文件路径
This commit is contained in:
@@ -129,7 +129,7 @@ def plotBestFit(dataArr, labelMat, weights):
|
||||
|
||||
def main():
|
||||
# 1.收集并准备数据
|
||||
dataMat, labelMat = loadDataSet("input/05.Logistic/TestSet.txt")
|
||||
dataMat, labelMat = loadDataSet("input/5.Logistic/TestSet.txt")
|
||||
|
||||
# print dataMat, '---\n', labelMat
|
||||
# 2.训练模型, f(x)=a1*x1+b2*x2+..+nn*xn中 (a1,b2, .., nn).T的矩阵值
|
||||
|
||||
@@ -290,13 +290,13 @@ if __name__ == "__main__":
|
||||
|
||||
# # 马疝病数据集
|
||||
# # 训练集合
|
||||
# dataArr, labelArr = loadDataSet("input/07.AdaBoost/horseColicTraining2.txt")
|
||||
# dataArr, labelArr = loadDataSet("input/7.AdaBoost/horseColicTraining2.txt")
|
||||
# weakClassArr, aggClassEst = adaBoostTrainDS(dataArr, labelArr, 40)
|
||||
# print weakClassArr, '\n-----\n', aggClassEst.T
|
||||
# # 计算ROC下面的AUC的面积大小
|
||||
# plotROC(aggClassEst.T, labelArr)
|
||||
# # 测试集合
|
||||
# dataArrTest, labelArrTest = loadDataSet("input/07.AdaBoost/horseColicTest2.txt")
|
||||
# dataArrTest, labelArrTest = loadDataSet("input/7.AdaBoost/horseColicTest2.txt")
|
||||
# m = shape(dataArrTest)[0]
|
||||
# predicting10 = adaClassify(dataArrTest, weakClassArr)
|
||||
# errArr = mat(ones((m, 1)))
|
||||
|
||||
@@ -233,7 +233,7 @@ def crossValidation(xArr,yArr,numVal=10):
|
||||
|
||||
#test for standRegression
|
||||
def regression1():
|
||||
xArr, yArr = loadDataSet("testData/Regression_data.txt")
|
||||
xArr, yArr = loadDataSet("input/8.Regression/data.txt")
|
||||
xMat = mat(xArr)
|
||||
yMat = mat(yArr)
|
||||
ws = standRegres(xArr, yArr)
|
||||
@@ -251,7 +251,7 @@ def regression1():
|
||||
|
||||
#test for LWLR
|
||||
def regression2():
|
||||
xArr, yArr = loadDataSet("input/08.Regression/data.txt")
|
||||
xArr, yArr = loadDataSet("input/8.Regression/data.txt")
|
||||
yHat = lwlrTest(xArr, xArr, yArr, 0.003)
|
||||
xMat = mat(xArr)
|
||||
srtInd = xMat[:,1].argsort(0) #argsort()函数是将x中的元素从小到大排列,提取其对应的index(索引),然后输出
|
||||
@@ -265,7 +265,7 @@ def regression2():
|
||||
|
||||
#test for ridgeRegression
|
||||
def regression3():
|
||||
abX,abY = loadDataSet("input/08.Regression/abalone.txt")
|
||||
abX,abY = loadDataSet("input/8.Regression/abalone.txt")
|
||||
ridgeWeights = ridgeTest(abX, abY)
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
@@ -275,7 +275,7 @@ def regression3():
|
||||
|
||||
#test for stageWise
|
||||
def regression4():
|
||||
xArr,yArr=loadDataSet("input/08.Regression/abalone.txt")
|
||||
xArr,yArr=loadDataSet("input/8.Regression/abalone.txt")
|
||||
stageWise(xArr,yArr,0.01,200)
|
||||
xMat = mat(xArr)
|
||||
yMat = mat(yArr).T
|
||||
|
||||
@@ -290,8 +290,8 @@ if __name__ == "__main__":
|
||||
# print mat0, '\n-----------\n', mat1
|
||||
|
||||
# # 回归树
|
||||
# myDat = loadDataSet('input/09.RegTrees/data1.txt')
|
||||
# # myDat = loadDataSet('input/09.RegTrees/data2.txt')
|
||||
# myDat = loadDataSet('input/9.RegTrees/data1.txt')
|
||||
# # myDat = loadDataSet('input/9.RegTrees/data2.txt')
|
||||
# # print 'myDat=', myDat
|
||||
# myMat = mat(myDat)
|
||||
# # print 'myMat=', myMat
|
||||
@@ -299,13 +299,13 @@ if __name__ == "__main__":
|
||||
# print myTree
|
||||
|
||||
# # 1. 预剪枝就是:提起设置最大误差数和最少元素数
|
||||
# myDat = loadDataSet('input/09.RegTrees/data3.txt')
|
||||
# myDat = loadDataSet('input/9.RegTrees/data3.txt')
|
||||
# myMat = mat(myDat)
|
||||
# myTree = createTree(myMat, ops=(0, 1))
|
||||
# print myTree
|
||||
|
||||
# # 2. 后剪枝就是:通过测试数据,对预测模型进行合并判断
|
||||
# myDatTest = loadDataSet('input/09.RegTrees/data3test.txt')
|
||||
# myDatTest = loadDataSet('input/9.RegTrees/data3test.txt')
|
||||
# myMat2Test = mat(myDatTest)
|
||||
# myFinalTree = prune(myTree, myMat2Test)
|
||||
# print '\n\n\n-------------------'
|
||||
@@ -313,14 +313,14 @@ if __name__ == "__main__":
|
||||
|
||||
# # --------
|
||||
# # 模型树求解
|
||||
# myDat = loadDataSet('input/09.RegTrees/data4.txt')
|
||||
# myDat = loadDataSet('input/9.RegTrees/data4.txt')
|
||||
# myMat = mat(myDat)
|
||||
# myTree = createTree(myMat, modelLeaf, modelErr)
|
||||
# print myTree
|
||||
|
||||
# 回归树 VS 模型树 VS 线性回归
|
||||
trainMat = mat(loadDataSet('input/09.RegTrees/bikeSpeedVsIq_train.txt'))
|
||||
testMat = mat(loadDataSet('input/09.RegTrees/bikeSpeedVsIq_test.txt'))
|
||||
trainMat = mat(loadDataSet('input/9.RegTrees/bikeSpeedVsIq_train.txt'))
|
||||
testMat = mat(loadDataSet('input/9.RegTrees/bikeSpeedVsIq_test.txt'))
|
||||
# 回归树
|
||||
myTree1 = createTree(trainMat, ops=(1, 20))
|
||||
print myTree1
|
||||
|
||||
Reference in New Issue
Block a user