Exemplo n.º 1
0
def scale(data_matrix):
    """returns the mean and standard deviation of each column"""
    num_rows, num_cols = shape(data_matrix)
    means = [mean(get_column(data_matrix,j)) for j in range(num_cols)]
    stdevs = [standard_deviation(get_column(data_matrix, j))
              for j in range(num_cols)]
    return means, stdevs
Exemplo n.º 2
0
def scale(data_matrix):
    num_rows, num_cols = shape(data_matrix)
    means = [mean(get_column(data_matrix, j)) for j in range(num_cols)]
    stdevs = [
        standard_deviation(get_column(data_matrix, j)) for j in range(num_cols)
    ]
    return means, stdevs
def scale(data_matrix):
    num_rows, num_cols = shape(data_matrix)
    means = [mean(get_column(data_matrix,j))
             for j in range(num_cols)]
    stdevs = [standard_deviation(get_column(data_matrix,j))
              for j in range(num_cols)]
    return means, stdevs
Exemplo n.º 4
0
def scale(data_matrix):
    """returns the mean and standard deviation of each column"""
    num_rows, num_cols = shape(data_matrix)
    means = [mean(get_column(data_matrix, j)) for j in range(num_cols)]
    stdevs = [
        standard_deviation(get_column(data_matrix, j)) for j in range(num_cols)
    ]
    return means, stdevs
Exemplo n.º 5
0
def make_scatterplot_matrix():

    # first, generate some random data
    #初始化点数量
    num_points = 100
    
    def random_row():
        row = [None, None, None, None]
        row[0] = random_normal()
        row[1] = -5 * row[0] + random_normal()
        row[2] = row[0] + row[1] + 5 * random_normal()
        row[3] = 6 if row[2] > -2 else 0
        return row
    random.seed(0)

    #生成上方函数的矩阵
    data = [random_row()
            for _ in range(num_points)]

    # then plot it

    _, num_columns = shape(data)

    #创建子图
    fig, ax = plt.subplots(num_columns, num_columns)

    for i in range(num_columns):
        for j in range(num_columns):

            # scatter column_j on the x-axis vs column_i on the y-axis
            #i,j不相等则绘制散点图
            if i != j: ax[i][j].scatter(get_column(data, j), get_column(data, i))

            # unless i == j, in which case show the series name
            else: ax[i][j].annotate("series " + str(i), (0.5, 0.5),
                                    xycoords='axes fraction',
                                    ha="center", va="center")

            # then hide axis labels except left and bottom charts

            #隐藏部分坐标轴
            if i < num_columns - 1: ax[i][j].xaxis.set_visible(False)
            if j > 0: ax[i][j].yaxis.set_visible(False)

    # fix the bottom right and top left axis labels, which are wrong because
    # their charts only have text in them

    #固化左上右下图像
    ax[-1][-1].set_xlim(ax[0][-1].get_xlim())
    ax[0][0].set_ylim(ax[0][1].get_ylim())

    plt.show()
Exemplo n.º 6
0
def make_scatterplot_matrix():
    # first, generate some random data

    num_points = 100

    def random_row():
        row = [None for _ in range(6)]
        row[0] = random_normal()
        row[1] = -5 * row[0] + random_normal()
        row[2] = row[0] + row[1] + 5 * random_normal()
        row[3] = 6 if row[2] > -2 else 0
        row[4] = row[0] + row[1] + -1 * random_normal()
        row[5] = 3 if row[2] < -2 else 0
        return row

    random.seed(0)
    data = [random_row()
            for _ in range(num_points)]

    # then plot it

    _, num_columns = shape(data)
    fig, ax = plt.subplots(num_columns, num_columns)

    for i in range(num_columns):
        for j in range(num_columns):

            # scatter column_j on the x-axis vs column_i on the y-axis
            if i != j:
                ax[i][j].scatter(get_column(data, j), get_column(data, i))

            # unless i == j, in which case show the series name
            else:
                ax[i][j].annotate("series " + str(i), (0.5, 0.5),
                                  xycoords='axes fraction',
                                  ha="center", va="center")

            # then hide axis labels except left and bottom charts
            if i < num_columns - 1: ax[i][j].xaxis.set_visible(False)
            if j > 0: ax[i][j].yaxis.set_visible(False)

    # fix the bottom right and top left axis labels, which are wrong because
    # their charts only have text in them
    ax[-1][-1].set_xlim(ax[0][-1].get_xlim())
    ax[0][0].set_ylim(ax[0][1].get_ylim())

    plt.show()
Exemplo n.º 7
0
def visual_approach():
    num_points = 100

    def random_row():
        row = [None, None, None, None]
        row[0] = random_normal()
        row[1] = -5 * row[0] + random_normal()
        row[2] = row[0] + row[1] + 5 * random_normal()
        row[3] = 6 if row[2] > -2 else 0
        return row

    random.seed(0)
    data = [random_row()
            for _ in range(num_points)]
    _, num_columns = shape(data)
    fig, ax = plt.subplots(num_columns, num_columns)

    for i in range(num_columns):
        for j in range(num_columns):

            # Scatter columm_j on the x-axis vs column_i on the y-axis
            if i != j:
                ax[i][j].scatter(get_column(data, j), get_column(data, i))

            # unlesss i == j, in which case show the series name
            else:
                ax[i][j].annotate("series {}".format(i), (0.5, 0.5),
                                  xycoords='axes fraction',
                                  ha="center", va="center")

            # then hide dxis labels except left and bottom charts
            if i < num_columns - 1: ax[i][j].xaxis.set_visible(False)
            if j > 0: ax[i][j].yaxis.set_visible(False)

    # fix the bottom right and top left except left and bottom charts
    ax[-1][-1].set_xlim(ax[0][-1].get_xlim())
    ax[1][1].set_xlim(ax[0][1].get_ylim())

    plt.show()
def matrix_product_entry(A, B, i, j):
    return dot(get_row(A, i), get_column(B, j))
def matrix_product_entry(A, B, i, j):
    return dot(get_row(A, i), get_column(B, j))
Exemplo n.º 10
0
 def matrix_entry(i, j):
     return correlation(get_column(data, i), get_column(data, j))
Exemplo n.º 11
0
C = la.distance(A, B)
print("A's distance = ", C)

print()
print("*** matrix ......")
M = [[1, 2, 3], [5, 6, 7], [3, 6, 9]]
print("M = ", M)

shape = la.shape(M)
print("M's shape = ", shape)

row_1 = la.get_row(M, 1)
print("M[1,:] = ", row_1)

col_1 = la.get_column(M, 1)
print("M[:1] = ", col_1)

I = la.make_matrix(5, 5, la.is_diagonal)
print("identity matrix = ", I)

print("\n\n")
print("*** Test Module <stats> ***")

A = [1, 3, 5, 7, 9, 2, 3, 4, 4, 4, 6, 8, 10, 13, 15, 17]

print("vector A = ", A)
print("sorted A = ", sorted(A))

mean = st.mean(A)
print("A's mean = ", mean)
 def matrix_entry(i, j):
     return correlation(get_column(data, i), get_column(data, j))
Exemplo n.º 13
0
    def matrix_entry(i, j):
        return correlation(get_column(data, i), get_column(data, j))

    return make_matrix(num_colums, num_colums, matrix_entry)


_, num_colums = shape(data)
fig, ax = plt.subplots(num_colums, num_colums)

for i in range(num_colums):
    for j in range(num_colums):

        #X軸のcolumns_j、Y軸のcolumns_iの位置に散布図を描画する
        if i != j:
            ax[i][j].scatter(get_column(data, j), get_column(data, i))

            #i == jであれば列名を表示する
        else:
            ax[i][j].annotate("series " + str(i), (0.5, 0.5),
                              xycoords='axes fraction',
                              ha="center",
                              va='center')

        #左端と一番下のサブプロット以外は軸ラベルを表示しない
        if i < num_colums - 1: ax[i][j].xaxis.set_visible(False)
        if j > 0: ax[i][j].yaxis.set_visible(False)

#右下と左上のサブプロットはテキストのみ表示しているため
#軸ラベルが誤っている
ax[-1][-1].set_xlim(ax[0][-1].get_xlim())
Exemplo n.º 14
0
 def matrix_entry(i, j):
     #得到相关系数(第i列和第j列)
     return correlation(get_column(data, i), get_column(data, j))