Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3658 from geektoni/patch-7
Port classifier_averaged_perceptron_modular.py to meta examples.
- Loading branch information
Showing
3 changed files
with
36 additions
and
43 deletions.
There are no files selected for viewing
Submodule data
updated
1 files
+16 −0 | testsuite/meta/binary_classifier/averaged_perceptron.dat |
35 changes: 35 additions & 0 deletions
35
examples/meta/src/binary_classifier/averaged_perceptron.sg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
42 changes: 0 additions & 42 deletions
42
examples/undocumented/python_modular/classifier_averaged_perceptron_modular.py
This file was deleted.
Oops, something went wrong.