def test_original():
    data_mat = file_utils.load_all_dataset(constants.FILE_TREE_EX00_PATH)
    tree_regres.plot_ex00_dataset(data_mat)

    data_mat = file_utils.load_all_dataset(constants.FILE_TREE_EX0_PATH)
    tree_regres.plot_ex0_dataset(data_mat)

    data_mat = file_utils.load_all_dataset(constants.FILE_TREE_EX2_PATH)
    tree_regres.plot_ex00_dataset(data_mat)
def test_diff_tree():
    test_arr = file_utils.load_all_dataset(constants.FILE_TREE_BIKE_TEST_PATH)
    train_arr = file_utils.load_all_dataset(
        constants.FILE_TREE_BIKE_TRAIN_PATH)
    tree = tree_regres.create_tree(np.mat(train_arr), ops=(1, 20))
    yhat = tree_regres.create_forecast(tree, np.mat(test_arr)[:, 0])
    ret = np.corrcoef(yhat, np.mat(test_arr)[:, 1], rowvar=0)[0, 1]
    print("树回归的预测结果:", ret)

    ws, X, Y = tree_regres.linear_solve(np.mat(train_arr))
    for i in range(np.shape(np.mat(test_arr))[0]):
        yhat[i] = np.mat(test_arr)[i, 0] * ws[1, 0] + ws[0, 0]
    ret = np.corrcoef(yhat, np.mat(test_arr)[:, 1], rowvar=0)[0, 1]
    print("线性回归的预测结果:", ret)
def test_tree():
    data_mat = file_utils.load_all_dataset(constants.FILE_TREE_EX0_PATH)
    data_mat = np.mat(data_mat)
    result = tree_regres.create_tree(data_mat)
    print(result)

    data_mat = file_utils.load_all_dataset(constants.FILE_TREE_EX2_PATH)
    data_mat = np.mat(data_mat)
    tree = tree_regres.create_tree(data_mat)
    print(tree)
    test_data = file_utils.load_all_dataset(constants.FILE_TREE_EX2TEST_PATH)
    test_data = np.mat(test_data)
    new_tree = tree_regres.prune(tree, test_data)
    print("new_tree: \n", new_tree)
Example #4
0
 def __init__(self,root):
     self.f = Figure(figsize=(5, 4), dpi=100)  # create canvas
     self.canvas = FigureCanvasTkAgg(self.f, master=root)
     self.canvas.draw()
     self.canvas.get_tk_widget().grid(row=0, columnspan=3)
     self.raw_data = np.mat(file_utils.load_all_dataset('assets/sine.txt'))
     self.test_data = np.arange(np.min(self.raw_data[:, 0]), np.max(self.raw_data[:, 0]), 0.01)
def test_model_tree():
    data_arr = file_utils.load_all_dataset(constants.FILE_TREE_EXP2_PATH)

    data_mat = np.mat(data_arr)
    tree = tree_regres.create_tree(data_mat, tree_regres.model_leaf,
                                   tree_regres.model_error, (1, 10))
    print(tree)

    tree_regres.plot_model_tree(data_arr, tree)
def test_data2():
    data_mat = file_utils.load_all_dataset(constants.FILE_KMEAN_TEST2_PATH)
    centroids = mkmean.random_center(data_mat, 2)
    print(centroids)
    dis = mkmean.distance_eclud(data_mat[0], data_mat[1])
    print(dis)
    print("=============")

    centroids, clust_assing = mkmean.kmeans(data_mat, 3)
    print(centroids)

    mkmean.plot_kmeans(data_mat, centroids, clust_assing)
def test_binary_kmeans():
    data_mat = file_utils.load_all_dataset(constants.FILE_KMEAN_TEST2_PATH)
    cent_list, cluster_assment = mkmean.binary_kmeans(data_mat, 3)
    print(cent_list)
def test_data1():
    data_mat = file_utils.load_all_dataset(constants.FILE_KMEAN_TEST1_PATH)
    mkmean.plot_orginal_dataset(data_mat)