Beispiel #1
0
def save_data (outdir, prefix, dataname, otype, excluding, leave, feats, labels, exclfeats, exclulabels, dmin, dmax, scale, scale_min, scale_max, lthr, uthr, thrp, absolute):

    #setting output file name
    ofname = au.feats_str()

    if leave > -1:
        ofname += '.' + au.excluded_str() + str(leave)

    if absolute:  ofname += '.' + au.abs_str()
    if lthr:      ofname += '.lthr_' + str(lthr)
    if uthr:      ofname += '.uthr_' + str(uthr)
    if thrp:      ofname += '.thrP_' + str(thrp)
    if scale:     ofname += '.' + au.scaled_str()

    if excluding:
        excl_ofname  = au.excluded_str() + '_' + ofname
        exclfilename = get_filepath (outdir, excl_ofname , otype)

    if prefix:
        ofname = prefix + '_' + ofname
        excl_ofname = prefix + '_' + excl_ofname

    filename = get_filepath (outdir, ofname, otype)

    #writing in a text file the scaling values of this training set
    if scale:
        write_scalingrange_file (outdir + os.path.sep + ofname + '.scaling_range', dmin, dmax, scale_min, scale_max)

    #saving binary file depending on output type
    if otype == 'numpybin':
        np.save (filename, feats)

        if excluding:
            np.save (exclfilename, exclfeats)

    elif otype == 'octave':
        sio.savemat (filename, {au.feats_str(): feats, au.labels_str(): labels})
        if excluding:
            exclulabels[exclulabels == 0] = -1
            sio.savemat (exclfilename, {au.feats_str(): exclfeats, au.labels_str(): exclulabels})

    elif otype == 'svmperf':
        labels[labels == 0] = -1
        ae.write_svmperf_dat(filename, dataname, feats, labels)

        if excluding:
            exclulabels[exclulabels == 0] = -1
            ae.write_svmperf_dat(exclfilename, dataname, exclfeats, exclulabels)

    elif otype == 'arff':
        featnames = np.arange(nfeats) + 1
        ae.write_arff (filename, dataname, featnames, feats, labels)

        if excluding:
            ae.write_arff (exclfilename, dataname, featnames, exclfeats, exclulabels)

    else:
        err = 'Output method not recognised!'
        au.log.error(err)
        sys.exit(-1)

    return [filename, exclfilename]
        elif otype == 'octave':
            sio.savemat(filename, {
                au.feats_str(): feats,
                au.labels_str(): labels
            })
            if excluf:
                exclulabels[exclulabels == 0] = -1
                sio.savemat(exclfilename, {
                    au.feats_str(): exclfeats,
                    au.labels_str(): exclulabels
                })

        elif otype == 'svmperf':
            labels[labels == 0] = -1
            ae.write_svmperf_dat(filename, dataname, feats, labels)

            if excluf:
                exclulabels[exclulabels == 0] = -1
                ae.write_svmperf_dat(exclfilename, dataname, exclfeats,
                                     exclulabels)

        elif otype == 'arff':
            featnames = np.arange(nfeats) + 1
            ae.write_arff(filename, dataname, featnames, feats, labels)

        else:
            err = 'Output method not recognised!'
            raise IOError(err)
            return -1
        # saving binary file depending on output type
        if otype == "numpybin":
            np.save(filename, feats)

            if excluf:
                np.save(exclfilename, exclfeats)

        elif otype == "octave":
            sio.savemat(filename, {au.feats_str(): feats, au.labels_str(): labels})
            if excluf:
                exclulabels[exclulabels == 0] = -1
                sio.savemat(exclfilename, {au.feats_str(): exclfeats, au.labels_str(): exclulabels})

        elif otype == "svmperf":
            labels[labels == 0] = -1
            ae.write_svmperf_dat(filename, dataname, feats, labels)

            if excluf:
                exclulabels[exclulabels == 0] = -1
                ae.write_svmperf_dat(exclfilename, dataname, exclfeats, exclulabels)

        elif otype == "arff":
            featnames = np.arange(nfeats) + 1
            ae.write_arff(filename, dataname, featnames, feats, labels)

        else:
            err = "Output method not recognised!"
            raise IOError(err)
            return -1

    return 1