Exemple #1
0
def ceshiLR(filename):
    # 加载数据
    dataMat,labelMat = loadDataSet(filename)
    # 转换数据
    dataArr = mat(dataMat)
    labelMat = mat(labelMat).transpose()
    weights = stocGradAscent2(dataArr,labelMat)
    plotBestFit(dataArr,labelMat,weights)
Exemple #2
0
def standRegres(xArr, yArr):
    xMat = mat(xArr)
    yMat = mat(yArr).T
    xTx = xMat.T * xMat
    if np.linalg.det(xTx) == 0.0:
        print("This matrix is singular,cannot do inverse")
        return
    ws = xTx.T * (xMat.T * yMat)
    return ws
Exemple #3
0
def regression1(filename):
    xArr, yArr = loadDataSet(filename)
    xMat = mat(xArr)
    yMat = mat(yArr)
    ws = standRegres(xArr, yArr)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(xMat[:, 1].flatten(), yMat[:, 0].flatten().A[0])
    xCopy = xMat.sort(0)
    yHat = xCopy * ws
    ax.plot(xCopy[:, 1], yHat)
    plt.show()
Exemple #4
0
 def test_returntype(self):
     a = array([[0, 1], [0, 0]])
     assert type(matrix_power(a, 2)) is ndarray
     a = mat(a)
     assert type(matrix_power(a, 2)) is matrix
Exemple #5
0
 def test_returntype(self):
     a = np.array([[0, 1], [0, 0]])
     assert_(type(matrix_power(a, 2)) is np.ndarray)
     a = mat(a)
     assert_(type(matrix_power(a, 2)) is matrix)
Exemple #6
0
 def test_returntype(self):
     a = np.array([[0, 1], [0, 0]])
     assert_(type(matrix_power(a, 2)) is np.ndarray)
     a = mat(a)
     assert_(type(matrix_power(a, 2)) is matrix)
 def test_returntype(self):
     a = array([[0,1],[0,0]])
     assert type(matrix_power(a, 2)) is ndarray
     a = mat(a)
     assert type(matrix_power(a, 2)) is matrix