Example #1
0
    print 'Creating contingency table...'
    ct = tt.crosstab(truth.hard(), pred.hard())

    print
    print 'Contigency table [rows=truth, cols=prediction] contains {0} elements'.format(
        ct.shape[0] * ct.shape[1])
    print_table(ct)
    print

    if over_clustered(ct):
        add_padding_columns(ct)
        print 'Squaring table with dummy classes'
        print_table(ct)
        print

    # Write the table to stdout
    print 'Matching labels using Munkres, algorithm suffers from high polynomial order...'
    mct = match_labels(ct)
    print 'Aligned contigency table'
    print_table(mct)

    # Calculate measure
    score = {
        'f1': f1_score_macro(mct),
        'recall': recall_macro(mct),
        'prec': precision_macro(mct)
    }

    # Write measure to file
    pipeline_utils.write_to_stream(args.output, score)
Example #2
0
    print 'Reading prediction...'
    pred = tt.read_mcl(args.pred[0])

    print 'Creating contingency table...'
    ct = tt.crosstab(truth.hard(), pred.hard())

    print
    print 'Contigency table [rows=truth, cols=prediction] contains {0} elements'.format(ct.shape[0] * ct.shape[1])
    print_table(ct)
    print

    if over_clustered(ct):
        add_padding_columns(ct)
        print 'Squaring table with dummy classes'
        print_table(ct)
        print

    # Write the table to stdout
    print 'Matching labels using Munkres, algorithm suffers from high polynomial order...'
    mct = match_labels(ct)
    print 'Aligned contigency table'
    print_table(mct)

    # Calculate measure
    score = {'f1': f1_score_macro(mct),
             'recall': recall_macro(mct),
             'prec': precision_macro(mct)}

    # Write measure to file
    pipeline_utils.write_to_stream(args.output, score)
Example #3
0
            raise RuntimeWarning('Truth table contains no assignments: {0}'.format(args.truth[0]))

        # collect object weights if requested
        weights = truth.get_weights() if args.weighted else None

        if args.verbose:
            print 'Truth Statistics'
            truth.print_tally()

        if args.hard:
            truth = truth.hard(True)
        else:
            truth = truth.soft(True)

        # read clustering and convert to basic soft table
        clustering = tt.read_mcl(args.pred)
        if len(clustering) == 0:
            raise RuntimeWarning('Clustering contains no assignments: {0}'.format(args.pred[0]))

        if args.verbose:
            print 'Clustering Statistics'
            clustering.print_tally()
        clustering = clustering.soft(True)

    except RuntimeWarning as wn:
        write_msg(args.output, wn.message)
        sys.exit(0)

    result = bcubed_F(truth, clustering, weights)
    pipeline_utils.write_to_stream(args.output, result)