예제 #1
0
def run_all():

  from options import MultiOptions
  opt = MultiOptions()
  #opt.count_number_of_events()

  ### UNSUPERVISED METHOD ### 
  if opt.opdict['method'] == 'kmeans':
    from unsupervised import classifier
    classifier(opt)

  ### SUPERVISED METHODS ###
  elif opt.opdict['method'] in ['lr','svm','svm_nl','lrsk']:
    from do_classification import classifier
    classifier(opt)

    from results import AnalyseResults
    res = AnalyseResults()
    if res.opdict['plot_confusion']:
      res.plot_confusion()

  elif opt.opdict['method'] in ['ova','1b1']:
    from do_classification import classifier
    classifier(opt)

    from results import AnalyseResultsExtraction
    res = AnalyseResultsExtraction()
예제 #2
0
def compare_pdfs_reclass():
    """
  Affiche et compare les pdfs avant et après reclassification automatique.
  """
    from results import AnalyseResults
    opt = AnalyseResults()

    opt.opdict['stations'] = ['IJEN']
    opt.opdict['channels'] = ['Z']
    opt.opdict['Types'] = ['Tremor', 'VulkanikB', '?']
    opt.opdict['feat_list'] = [
        'Centroid_time', 'Dur', 'Ene0-5', 'F_up', 'Growth', 'Kurto',
        'RappMaxMean', 'RappMaxMeanTF', 'Skewness', 'TimeMaxSpec', 'Width'
    ]

    for sta in opt.opdict['stations']:
        for comp in opt.opdict['channels']:
            opt.opdict[
                'label_filename'] = '%s/Ijen_3class_all.csv' % opt.opdict[
                    'libdir']
            opt.x, opt.y = opt.features_onesta(sta, comp)
            opt.classname2number()
            opt.compute_pdfs()
            g1 = opt.gaussians

            opt.opdict[
                'label_filename'] = '%s/Ijen_3class_all_SVM.csv' % opt.opdict[
                    'libdir']
            opt.x, opt.y = opt.features_onesta(sta, comp)
            opt.classname2number()
            opt.compute_pdfs()
            g2 = opt.gaussians

            c = ['r', 'b', 'g']
            for feat in opt.opdict['feat_list']:
                fig = plt.figure()
                fig.set_facecolor('white')
                for it, t in enumerate(opt.types):
                    plt.plot(g1[feat]['vec'],
                             g1[feat][t],
                             ls='-',
                             color=c[it],
                             label=t)
                    plt.plot(g2[feat]['vec'],
                             g2[feat][t],
                             ls='--',
                             color=c[it])
                plt.title(feat)
                plt.legend()
                #plt.savefig('../results/Ijen/comp_BrutReclass_%s.png'%feat)
                plt.show()
예제 #3
0
def run_all():

    from options import MultiOptions
    opt = MultiOptions()
    #opt.count_number_of_events()

    from do_classification import classifier
    classifier(opt)

    if opt.opdict['method'] == 'lr' or opt.opdict[
            'method'] == 'svm' or opt.opdict['method'] == 'lrsk':
        from results import AnalyseResults
        res = AnalyseResults()
        if res.opdict['plot_confusion']:
            res.plot_confusion()

    else:
        from results import AnalyseResultsExtraction
        res = AnalyseResultsExtraction()
예제 #4
0
def compare_unsup_indet():
    """
  Essaie de faire un lien entre les événements indéterminés mal classés par 
  LR ou SVM avec classes non-supervisées.
  """
    from matplotlib.gridspec import GridSpec

    print "### COMPARE UNSUP AND SUP ###"
    from results import AnalyseResults
    opt = AnalyseResults()

    m = opt.man
    a = opt.auto
    unsup = read_binary_file(
        '../results/Ijen/KMEANS/results_kmeans_3c_11f_ini')

    nb_auto = [len(opt.auto[opt.auto.Type == t]) for t in opt.opdict['types']]
    NB_class = len(opt.opdict['types'])

    for cl in opt.opdict['types']:
        #for cl in ['?']:
        m = opt.man[opt.man.Type == cl]
        a = opt.auto.reindex(index=m.index)

        colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']

        opt.data_for_LR()
        opt.opdict['channels'] = 'Z'
        opt.opdict['stations'] = ['IJEN']
        for sta in opt.opdict['stations']:
            for comp in opt.opdict['channels']:
                u = pd.DataFrame(index=unsup[(sta, comp)][0]['list_ev'],
                                 columns=['Type', 'NumType'])
                u['Type'] = unsup[(sta, comp)][0]['StrClass']
                u['NumType'] = unsup[(sta, comp)][0]['NumClass']
                u = u.reindex(index=m.index)
                trad = unsup[(sta, comp)][0]['Equivalence']

                fig = plt.figure(figsize=(12, 8))
                fig.set_facecolor('white')
                nb_l, nb_c = 2, NB_class * 2
                grid = GridSpec(nb_l, nb_c)

                ax = fig.add_subplot(grid[0, :nb_c / 2])
                ax.pie(nb_auto,
                       labels=opt.opdict['types'],
                       autopct='%1.1f%%',
                       colors=colors)
                ax.text(.4,
                        -.1,
                        r'# events = %d' % np.sum(nb_auto),
                        transform=ax.transAxes)
                ax.axis("equal")

                nbs = [len(a[a.Type == t]) for t in opt.opdict['types']]
                ax = fig.add_subplot(grid[0, nb_c / 2:])
                ax.pie(nbs,
                       labels=opt.opdict['types'],
                       autopct='%1.1f%%',
                       colors=colors)
                ax.text(.4,
                        -.1,
                        r'# events = %d' % np.sum(nbs),
                        transform=ax.transAxes)
                ax.axis("equal")

                lab_c = np.array(trad).copy()
                for it, t in enumerate(opt.opdict['types']):
                    i = np.where(np.array(trad) == t)[0][0]
                    lab_c[it] = i

                for it, t in enumerate(opt.opdict['types']):
                    ared = a[a.Type == t]
                    ured = u.reindex(index=ared.index)
                    nbs = [
                        len(ured[ured.Type == ty])
                        for ty in opt.opdict['types']
                    ]
                    ax = fig.add_subplot(grid[1, 2 * it:2 * it + 2])
                    ax.pie(nbs, labels=lab_c, autopct='%1.1f%%', colors=colors)
                    ax.text(.3,
                            -.1,
                            r'# %s = %d' % (t, np.sum(nbs)),
                            transform=ax.transAxes)
                    #ax.set_title(t)

                plt.figtext(.1,
                            .92,
                            '(a) %s' % opt.opdict['method'].upper(),
                            fontsize=16)
                plt.figtext(.55,
                            .92,
                            '(b) Manual repartition of %s' % cl,
                            fontsize=16)
                plt.figtext(.1, .45, r'(c) $K$-means', fontsize=16)
                for it, t in enumerate(trad):
                    plt.figtext(.3 + it * .15, .45,
                                r'%s $\approx$ %s' % (it, trad[it]))
                plt.savefig(
                    '../results/Ijen/KMEANS/figures/unsup_compSVM_%s.png' % cl)

    plt.show()
예제 #5
0
        plt.plot(p_tr,
                 p_test,
                 marker=markers[k],
                 color=colors[k],
                 lw=0,
                 label=labels[k])
        k = k + 1
    plt.legend(numpoints=1, loc='upper left')
    plt.plot([0, 100], [0, 100], 'k--')
    plt.xlim([60, 100])
    plt.ylim([60, 100])
    plt.figtext(.7, .15, 'Sur-apprentissage')
    plt.xlabel('% training set')
    plt.ylabel('% test set')
    #plt.savefig('../results/Ijen/figures/SVM_training.png')
    plt.show()


if __name__ == '__main__':

    #plot_test_vs_train()

    from results import AnalyseResults
    res = AnalyseResults()

    #new_catalogue(res)
    plot_on_pdf(res)
    #plot_waveforms(res)
    #compare_pdfs_reclass()
    #compare_pdfs_train()