def getGraph():
    for i, clf in enumerate((svm, rbf_svc, rbf_svc_tunning)):
        # Se grafican las fronteras
        plt.subplot(2, 2, i + 1)
        plt.subplots_adjust(wspace=0.4, hspace=0.4)

        Z = clf.predict(np.c_[x_matrizSetEntrenamientoVect, y_clases])

        #Color en las gráficas
        Z = Z.reshape(x_matrizSetEntrenamientoVect.shape)
        plt.contourf(x_matrizSetEntrenamientoVect,
                     y_clases,
                     Z,
                     cmap=plt.cm.Paired,
                     alpha=0.8)

        #Puntos de entrenamiento
        plt.scatter(x_matrizSetEntrenamientoVect[:, 0],
                    x_matrizSetEntrenamientoVect[:, 1],
                    c=y_clases,
                    cmap=plt.cm.Paired)
        plt.xlabel('Longitud Sepal')
        plt.ylabel('Peso Sepal')
        plt.xlim(x_matrizSetEntrenamientoVect.min(),
                 x_matrizSetEntrenamientoVect.max())
        plt.ylim(y_clases.min(), y_clases.max())
        plt.xticks(())
        plt.yticks(())
        plt.title(titles[i])

    plt.show()
Exemple #2
0
def tmp(cm, acts):
    import matplotlib.pyplot as plt
    import numpy as np

    plt.imshow(cm, interpolation='nearest')
    plt.xticks(np.arange(0, len(acts)), acts)
    plt.yticks(np.arange(0, len(acts)), acts)
def plot():
    plt.figure(figsize=(20, 10))
    width = 0.5
    index = np.arange(26)

    print 'SUM PLOT 1', sum(row[0] for row in data)
    print 'SUM PLOT 2', sum(row[1] for row in data)
    print 'SUM PLOT 3', sum(row[2] for row in data)

    print data[0]
    
    p0 = plt.bar(index, data[0], width, color='y')  # people
    p1 = plt.bar(index, data[1], width, color='g')  # nature
    p2 = plt.bar(index, data[2], width, color='r')  # activity
    p3 = plt.bar(index, data[3], width, color='b')  # food
    p4 = plt.bar(index, data[4], width, color='c')  # symbols
    p5 = plt.bar(index, data[5], width, color='m')  # objects
    p6 = plt.bar(index, data[6], width, color='k')  # flags
    p7 = plt.bar(index, data[7], width, color='w')  # uncategorized


    plt.ylabel('Usage')
    plt.title('Emoji category usage per city')
    plt.xticks(index + width/2.0, cities)
    plt.yticks(np.arange(0, 1, 0.1))
    plt.legend((p0[0], p1[0], p2[0], p3[0], p4[0], p5[0], p6[0], p7[0]), categories_names)

    plt.show()
def plot_gallery(images, titles, h, w, n_row=3,n_col=4):
    plt.figure(figsize=(1.8*n_col, 2.4*n_row))
    plt.subplots_adjust(bottom=0,left=.01,right=.99,top=.90,hspace=.35)
    for i in range(n_row * n_col):
        plt.subplot(n_row,n_col,i+1)
        plt.imshow(images[i].reshape(h,w),cmap=plt.cm.gray)
        plt.title(titles[i],size=12)
        plt.xticks(())
        plt.yticks(())
def plot_average(collected_results, versions, args, plot_std=True):
    test_type = args.test_type
    model_name = args.model

    means, stds = [], []
    for version in versions:
        data = collected_results[version]
        if (plot_std):
            means.append(np.mean(data))
            stds.append(np.std(data))
        else:
            means.append(data)

    means = np.array(means)
    stds = np.array(stds)
    if (test_type == "size" or test_type == "allsize"):
        x = ["0%", "20%", "40%", "60%", "80%", "100%"]
    elif (test_type == "accdomain" or test_type == "moredomain"):
        x = [0, 1, 2, 3, 4]
    else:
        x = versions

    color = 'blue'
    plt.plot(x, means, color=color)
    if (plot_std):
        plt.fill_between(x,
                         means - stds,
                         means + stds,
                         alpha=0.1,
                         edgecolor=color,
                         facecolor=color,
                         linewidth=1,
                         antialiased=True)

    plt.xticks(np.arange(len(x)), x, fontsize=18)
    plt.yticks(fontsize=18)
    plt.xlabel(XLABELS[test_type], fontsize=18)
    plt.ylabel('average absolute effect size', fontsize=18)
    plt.title("Influence of {} on bias removal \nfor {}".format(
        TITLES[test_type], MODEL_FORMAL_NAMES[model_name]),
              fontsize=18)
    plt.tight_layout()

    plot_path = os.path.join(
        args.eval_results_dir, "plots",
        "{}-{}-avg{}.png".format(model_name, test_type,
                                 "-std" if plot_std else ""))
    plt.savefig(plot_path)
Exemple #6
0
def f3():
    xs = [0, 1, 2, 5]
    ys = [0, 0, 1, 1]
    fig, ax = plt.subplots()
    ax.set_yticklabels([])
    ax.set_xticklabels([])
    plt.plot(xs, ys, label="$f_n(x)$")

    plt.xticks(xs, ['', r'$n-1$', r'$n$', ''])
    plt.yticks([1], ['$1$'])

    plt.legend()
    ax.spines['left'].set_position('zero')
    ax.spines['right'].set_color('none')
    ax.spines['bottom'].set_position('zero')
    ax.spines['top'].set_color('none')
    ax.axis('equal')
    plt.show()
Exemple #7
0
 def plot(self, ax=None):
     x = [*self.times, self.times[-1] + self.values[-1][1]]
     y = [*(v for v, d in self.values), self.values[-1][0]]
     from matplotlib.pylab import plt
     if ax is None:
         ax = plt.gca()
     ax.step(x, y, where='post')
     ax.set_xlabel('Time (seconds)')
     y_ticks = list(map(int, plt.yticks()[0]))
     ax.set_yticks(y_ticks, list(map(self.format_value.format, y_ticks)))
Exemple #8
0
def tmp2(cm, acts):
    import numpy as np
    import matplotlib.pyplot as plt

    conf_arr = cm

    norm_conf = []
    for i in conf_arr:
        a = 0
        tmp_arr = []
        a = sum(i, 0)
        for j in i:
            tmp_arr.append(0 if a == 0 else float(j) / float(a))
        norm_conf.append(tmp_arr)

    fig = plt.figure(figsize=(8, 8))
    plt.clf()
    ax = fig.add_subplot(111)
    ax.set_aspect(1)
    res = ax.imshow(np.array(norm_conf),
                    cmap=plt.cm.jet,
                    interpolation='nearest')

    width, height = conf_arr.shape

    # for x in range(width):
    # 	for y in range(height):
    # 		ax.annotate(str(conf_arr[x][y]), xy=(y, x),
    # 					horizontalalignment='center',
    # 					verticalalignment='center')

    cb = fig.colorbar(res)
    ax.set_xlim(-.5, len(acts) - .5)
    ax.set_ylim(-.5, len(acts) - .5)

    # alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    plt.xticks(range(width), acts, rotation=-90)
    plt.yticks(range(height), acts)
def getGraph():
    for i, clf in enumerate((svm, rbf_svc, rbf_svc_tunning)):
     # Se grafican las fronteras 
     plt.subplot(2, 2, i + 1)
     plt.subplots_adjust(wspace=0.4, hspace=0.4)
    
     Z = clf.predict(np.c_[x_matrizSetEntrenamientoVect, y_clases])
    
     #Color en las gráficas
     Z = Z.reshape(x_matrizSetEntrenamientoVect.shape)
     plt.contourf(x_matrizSetEntrenamientoVect, y_clases, Z, cmap=plt.cm.Paired, alpha=0.8)
    
     #Puntos de entrenamiento
     plt.scatter(x_matrizSetEntrenamientoVect[:, 0], x_matrizSetEntrenamientoVect[:, 1], c=y_clases, cmap=plt.cm.Paired)
     plt.xlabel('Longitud Sepal')
     plt.ylabel('Peso Sepal')
     plt.xlim(x_matrizSetEntrenamientoVect.min(), x_matrizSetEntrenamientoVect.max())
     plt.ylim(y_clases.min(), y_clases.max())
     plt.xticks(())
     plt.yticks(())
     plt.title(titles[i])
    
    plt.show()
Exemple #10
0
get_ipython().run_cell_magic(
    'latex', '',
    '$\\textbf{Visualize the Correlations}: $\n$\\text{Cor}(X_i,Y_j) = \\frac{\\text{Cov}(X_i,Y_j)}{\\sigma_{X_i}\\sigma_{Y_j}}$'
)

# In[101]:

R = np.corrcoef(data.T)
plt.figure(figsize=(10, 8))
plt.pcolor(R)
plt.colorbar()
plt.xlim([0, len(headers)])
plt.ylim([0, len(headers)])
plt.xticks(np.arange(32) + 0.5, np.array(headers), rotation='vertical')
plt.yticks(np.arange(32) + 0.5, np.array(headers))
plt.show()

# In[108]:

#Lets fit both the models using PCA/FA down to two dimensions.

#construct a function implementing the factor analysis which returns a vector of n_components largest
# variances and the corresponding components (as column vectors in a matrix). You can
# check your work by using decomposition.FactorAnalysis from sklearn


#### ~THIS FUNCTION IS WAS A STAB, NEW CODE HERE: ###########
def FactorAnalysis(data, n_components):
    ni = 20
    data = data - data.mean(axis=0)