示例#1
0
    def multiTest(self):
        xArr, yArr = self.loadDataSet('data/reg/ex0.txt')

        reg = Regression()
        yHat = reg.lwlrTest(xArr, xArr, yArr, 0.01)
        xMat = mat(xArr)
        strInd = xMat[:, 1].argsort(0)
        xSort = xMat[strInd][:, 0, :]

        import matplotlib.pyplot as plt

        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.scatter(xMat[:, 1].flatten().A[0], mat(yArr).T[:, 0].flatten().A[0])
        ax.plot(array(xSort[:, 1]), array(yHat[strInd]))
        plt.show()
示例#2
0
    def simpleTest(self):
        xArr, yArr = self.loadDataSet('data/reg/ex0.txt')
        print xArr[0:2]

        reg = Regression()
        ws = reg.standRegres(xArr, yArr)
        print ws
        xMat = mat(xArr)
        yMat = mat(yArr)
        yHat = xMat * ws

        import matplotlib.pyplot as plt

        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.scatter(xMat[:, 1].flatten().A[0], yMat.T[:, 0].flatten().A[0])
        xCopy = xMat.copy()
        xCopy.sort(0)
        yHat = xCopy * ws
        m = xCopy[:, 1]
        ax.plot(array(m), array(yHat))
        plt.show()