from numpy import *
import matplotlib.pyplot as plt
def loadDataSet(filename):
numFeat=len(open(filename).readline().split('\t'))-1
dataMat=[]
labelMat=[]
fr=open(filename)
for line in fr.readlines():
lineArr=[]
curLine=line.strip().split('\t')
for i in range(numFeat):
lineArr.append(float(curLine[i]))
dataMat.append(lineArr)
labelMat.append(float(curLine[-1]))
return dataMat,labelMat
def standRegres(xArr,yArr):
xMat=mat(xArr)
yMat=mat(yArr).T
xTx=xMat.T*xMat
if linalg.det(xTx)==0.0:
print('this matrix is singular,cannot do inverse')
return
ws=xTx.I*(xMat.T*yMat)
return ws
'''
#测试线性回归
xArr,yArr=loadDataSet('C:/Users/xuwei/Desktop/机器学习/机器学习实战(pdf版+源码)/machinelearninginaction/Ch08/ex0.txt')
print(xArr[0:2])
print(yArr)
ws=standRegres(
机器学习实战 树回归
最新推荐文章于 2022-09-19 21:13:54 发布