コード例 #1
0
def predictMan(res):
    try:
        X, _ = load_svmlight_file(res.data_file, n_features=res.nfeat)
    except Exception:
        X, _ = load_svmlight_file(res.data_file)

    X = X.toarray()

    if res.meth[0] == 'Classification':
        ens = EnsembleSelectionClassifier(db_file=res.db_file, models=None)
    elif res.meth[0] == 'Regression':
        ens = EnsembleSelectionRegressor(db_file=res.db_file, models=None)
    else:
        msg = "Invalid method passed (-T does not conform to ['Regression','Classification']"
        raise ValueError(msg)

    if (res.pred_src == 'best'):
        preds = ens.best_model_predict_proba(X)
    else:
        preds = ens.predict_proba(X)

    if res.meth[0] == 'Classification':
        if (not res.return_probs):
            preds = np.argmax(preds, axis=1)

    for p in preds:
        if (res.return_probs):
            mesg = " ".join(["%.5f" % v for v in p])
        else:
            mesg = p
        print(str(mesg))
    return preds
コード例 #2
0
ファイル: ensemble_predict.py プロジェクト: tilii/pyensemble
                        action='store_true',
                        default=False,
                        help='predict probabilities')

    return parser.parse_args()


if (__name__ == '__main__'):
    res = parse_args()

    X, _ = load_svmlight_file(res.data_file)
    X = X.toarray()

    ens = EnsembleSelectionClassifier(db_file=res.db_file, models=None)

    if (res.pred_src == 'best'):
        preds = ens.best_model_predict_proba(X)
    else:
        preds = ens.predict_proba(X)

    if (not res.return_probs):
        preds = np.argmax(preds, axis=1)

    for p in preds:
        if (res.return_probs):
            mesg = " ".join(["%.8f" % v for v in p])
        else:
            mesg = p

        print(mesg)
コード例 #3
0
    parser.add_argument('-p', dest='return_probs',
                        action='store_true', default=False,
                        help='predict probabilities')

    return parser.parse_args()


if (__name__ == '__main__'):
    res = parse_args()

    X, _ = load_svmlight_file(res.data_file)
    X = X.toarray()

    ens = EnsembleSelectionClassifier(db_file=res.db_file, models=None)

    if (res.pred_src == 'best'):
        preds = ens.best_model_predict_proba(X)
    else:
        preds = ens.predict_proba(X)

    if (not res.return_probs):
        preds = np.argmax(preds, axis=1)

    for p in preds:
        if (res.return_probs):
            mesg = " ".join(["%.5f" % v for v in p])
        else:
            mesg = p

        print(mesg)