Skip to content

Commit

Permalink
fix predict output on cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
QinbinLi committed May 27, 2019
1 parent 6a62fdd commit 70b64f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions include/thundersvm/model/svmmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class SvmModel {

//return label
const vector<int> &get_label() const;

//return param.probability
const bool is_prob() const;
protected:

/**
Expand Down
5 changes: 5 additions & 0 deletions src/thundersvm/model/svmmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,15 @@ const SyncArray<float_type> &SvmModel::get_dec_value() const {
int SvmModel::get_n_binary_models() const{
return n_binary_models;
}

const vector<float> &SvmModel::get_prob_predict() const{
return prob_predict;
}

const bool SvmModel::is_prob() const{
return param.probability;
}

int SvmModel::get_working_set_size(int n_instances, int n_features) {
size_t free_mem = param.max_mem_size - SyncMem::get_total_memory_size();
int ws_size = min(max2power(n_instances),
Expand Down
34 changes: 21 additions & 13 deletions src/thundersvm/thundersvm-predict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,29 @@ int main(int argc, char **argv) {

vector<float_type> predict_y;
predict_y = model->predict(predict_dataset.instances(), -1);
vector<int> label;
label = model->get_label();
vector<float> prob_predict;
prob_predict = model->get_prob_predict();
file<<"labels ";
for (int i = 0; i < label.size(); i++){
file<<label[i]<<" ";
}
file<<std::endl;
for (int i = 0; i < predict_y.size(); i++) {
file << predict_y[i]<<" ";
for(int j = 0; j < label.size(); j++){
file<<prob_predict[label.size() * i + j]<<" ";

if(model->is_prob() == 1) {
vector<int> label;
label = model->get_label();
vector<float> prob_predict;
prob_predict = model->get_prob_predict();
file << "labels ";
for (int i = 0; i < label.size(); i++) {
file << label[i] << " ";
}
file << std::endl;
for (int i = 0; i < predict_y.size(); i++) {
file << predict_y[i] << " ";
for (int j = 0; j < label.size(); j++) {
file << prob_predict[label.size() * i + j] << " ";
}
file << std::endl;
}
}
else{
for (int i = 0; i < predict_y.size(); ++i) {
file << predict_y[i] << std::endl;
}
}
file.close();

Expand Down

0 comments on commit 70b64f2

Please sign in to comment.