Регистрация | Вход
1 MLalg.train(x_train,y_train)2 y_predicted = MLalg.predict(x_real)3 MLalg.train(x_real,y_real)4 goto 2
//CDenseFeatures (here 64 bit floats aka RealFeatures) and CMulticlassLabels are //created from training and test data fileauto features_train = some<CDenseFeatures<float64_t>>(f_feats_train);auto features_test = some<CDenseFeatures<float64_t>>(f_feats_test);auto labels_train = some<CMulticlassLabels>(f_labels_train);auto labels_test = some<CMulticlassLabels>(f_labels_test);//Combination rules to be used for prediction are derived form the CCombinationRule class. Here we create a CMajorityVote class to be used as a combination rule.auto m_vote = some<CMajorityVote>();//Next an instance of CRandomForest is created. The parameters provided are the number //of attributes to be chosen randomly to select from and the number of trees.auto rand_forest = some<CRandomForest>(features_train, labels_train, 100);rand_forest->set_combination_rule(m_vote);//Then we run the train random forest and apply it to test data, which here gives CMulticlassLabels.rand_forest->train();auto labels_predict = rand_forest->apply_multiclass(features_test);//We can evaluate test performance via e.g. CMulticlassAccuracy as well as get the //“out of bag error”.auto acc = some<CMulticlassAccuracy>();auto oob = rand_forest->get_oob_error(acc);auto accuracy = acc->evaluate(labels_predict, labels_test);
auto features_train = some<CDenseFeatures<float64_t>>(f_feats_train);