def violin_plot():
    df = get_mod_data_original()
    decoder = get_categorical_decoder_class()
    df = df.replace({'CLASS': decoder})
    df_columns = list(df.columns.values)
    del df_columns[-1]
    for col in df_columns:
        ax = plt.figure(figsize=(14, 7))
        ax = sns.violinplot(x='CLASS', y=df[col], data=df)
        plt.show
Ejemplo n.º 2
0
def violin_plot_kdtree(df, y):
    df['CLASS'] = y
    decoder = get_categorical_decoder_class()
    df = df.replace({'CLASS' : decoder})
    df_columns = list(df.columns.values)
    for col in df_columns:
        ax = plt.figure(figsize=(14,7))
        ax = sns.violinplot(x='CLASS', y=df[col], data=df)
        img_name = str(col) + '.png'
        plt.savefig(img_name, bbox_inches='tight')
def pca_2d(X, y, n_components=2):
    pca = PCA(n_components=n_components)
    pca_transform = pca.fit_transform(X)
    X['pca_first'] = pca_transform[:, 0]
    X['pca_second'] = pca_transform[:, 1]
    X['CLASS'] = y
    decoder = get_categorical_decoder_class()
    X = X.replace({'CLASS': decoder})
    print(pca.explained_variance_ratio_)
    plt.figure(figsize=(15, 10))
    sns.scatterplot(x="pca_first",
                    y="pca_second",
                    palette=sns.color_palette("hls", 7),
                    hue='CLASS',
                    data=X)
    plt.show()
def tsne(X, y, perplexity, comp):
    for perp in perplexity:
        tsne = TSNE(n_components=comp, verbose=0, perplexity=perp, n_iter=250)
        features = list(X.columns.values)
        tsne_results = tsne.fit_transform(X[features].values)
        X['tsne-2d-first'] = tsne_results[:, 0]
        X['tsne-2d-second'] = tsne_results[:, 1]
        X['CLASS'] = y
        #X = X[X['CLASS'] != 0]
        decoder = get_categorical_decoder_class()
        X = X.replace({'CLASS': decoder})
        print('Perplexity = ', perp)
        plt.figure(figsize=(14, 10))
        sns.scatterplot(x="tsne-2d-first",
                        y="tsne-2d-second",
                        hue='CLASS',
                        palette=sns.color_palette("hls", 7),
                        data=X,
                        legend="full",
                        alpha=0.3)
        plt.show()
Ejemplo n.º 5
0
    f1_avg += concensus[i]['f1']

    # Predicciones
    pos = len(X_estimar[0]) - 1
    predictions_aux = model.predict(X_estimar[:, :pos].astype('float32'))
    ids = get_estimar_ids()
    for i in range(len(ids)):
        if (ids[i] not in predictions):
            predictions[ids[i]] = [int(predictions_aux[i])]
        else:
            predictions[ids[i]].append(int(predictions_aux[i])) 

print('\nMÉTRICAS DEL MODELO (concenso)')
print('Accuracy: {}'.format(accuracy_avg / n))
print('Precision (macro): {}'.format(precision_avg / n))
print('Recall (macro): {}'.format(recall_avg / n))
print('F1 (macro): {}'.format(f1_avg / n))


# 6. Predicción final
# Diccionario para decodificar el nombre de las clases
categorical_decoder_class = get_categorical_decoder_class()

#Método que calcula la moda.
def most_frequent(lst): 
    return max(set(lst), key = lst.count) 

with open(r'UPV_Astralaria.txt', 'w') as write_file:
    write_file.write('ID|CLASE\n')
    for sample in get_estimar_ids():
        write_file.write('{}|{}\n'.format(sample, categorical_decoder_class[most_frequent(predictions[sample])]))