Skip to content

Commit

Permalink
Merge pull request #3658 from geektoni/patch-7
Browse files Browse the repository at this point in the history
Port classifier_averaged_perceptron_modular.py to meta examples.
  • Loading branch information
karlnapf committed Feb 27, 2017
2 parents 1b95b89 + 1a1c6b9 commit 15b8463
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 43 deletions.
2 changes: 1 addition & 1 deletion data
35 changes: 35 additions & 0 deletions examples/meta/src/binary_classifier/averaged_perceptron.sg
@@ -0,0 +1,35 @@
CSVFile f_feats_train("../../data/classifier_binary_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_binary_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_binary_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_binary_2d_linear_labels_test.dat")

#![create_features]
RealFeatures features_train(f_feats_train)
RealFeatures features_test(f_feats_test)
BinaryLabels labels_train(f_labels_train)
BinaryLabels labels_test(f_labels_test)
#![create_features]

#![set_parameters]
real learn_rate=1.0
int max_iter=1000
AveragedPerceptron perceptron(features_train, labels_train)
perceptron.set_learn_rate(learn_rate)
perceptron.set_max_iter(max_iter)
#![set_parameters]

#![train_and_apply]
perceptron.train()
perceptron.set_features(features_test)
Labels labels_predict = perceptron.apply()
#![train_and_apply]

#![extract_weights]
RealVector weights = perceptron.get_w()
real bias = perceptron.get_bias()
#![extract_weights]

#![evaluate_accuracy]
AccuracyMeasure eval()
real accuracy = eval.evaluate(labels_predict, labels_test)
#![evaluate_accuracy]

This file was deleted.

0 comments on commit 15b8463

Please sign in to comment.