Skip to content

Commit

Permalink
shogun-toolbox#3555 add meta_example for classifier_perceptron undocu…
Browse files Browse the repository at this point in the history
…mented-sample (shogun-toolbox#4140)
  • Loading branch information
Francisco Navarro authored and ktiefe committed Jul 26, 2019
1 parent bd2950d commit e75f5bd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data
35 changes: 35 additions & 0 deletions examples/meta/src/neural_nets/classification_perceptron.sg
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]

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

#![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]

0 comments on commit e75f5bd

Please sign in to comment.