From fa839d22f6aa8099e4660991d17b5b5210008e14 Mon Sep 17 00:00:00 2001 From: Aleksey Cheusov Date: Thu, 8 Aug 2019 00:53:26 +0300 Subject: [PATCH] predict: add support for -b2 (softmax probs) and -b3 (raw scores) --- linear.cpp | 18 ++++++++++++++++++ linear.h | 1 + predict.c | 23 +++++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/linear.cpp b/linear.cpp index 063e01c..67fbcb8 100644 --- a/linear.cpp +++ b/linear.cpp @@ -2855,6 +2855,24 @@ double predict_probability(const struct model *model_, const struct feature_node return 0; } +double predict_softmax_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates) +{ + int i; + int nr_class=model_->nr_class; + + double label=predict_values(model_, x, prob_estimates); + double sum = 0.0; + for(i=0;inr_class;j++) fprintf(output," %g",prob_estimates[j]); @@ -168,7 +179,7 @@ void do_predict(FILE *input, FILE *output) } else info("Accuracy = %g%% (%d/%d)\n",(double) correct/total*100,correct,total); - if(flag_predict_probability) + if(prob_estimates) free(prob_estimates); } @@ -177,7 +188,11 @@ void exit_with_help() printf( "Usage: predict [options] test_file model_file output_file\n" "options:\n" - "-b probability_estimates: whether to output probability estimates, 0 or 1 (default 0); currently for logistic regression only\n" + "-b probability_estimates:\n" + " 0: output only best label;\n" + " 1: output probabilities for logistic regression solver;\n" + " 2: output softmax probabilities;\n" + " 3: output raw scores.\n" "-q : quiet mode (no outputs)\n" ); exit(1);