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 #4279 from karlnapf/feature/custom_kernel_meta
port custom kernel meta example
- Loading branch information
Showing
6 changed files
with
63 additions
and
30 deletions.
There are no files selected for viewing
Submodule data
updated
1 files
+16 −0 | testsuite/meta/kernel/custom_kernel_machine.dat |
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
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,39 @@ | ||
File f_feats_train = csv_file("../../data/classifier_binary_2d_nonlinear_features_train.dat") | ||
File f_feats_test = csv_file("../../data/classifier_binary_2d_nonlinear_features_test.dat") | ||
File f_labels_train = csv_file("../../data/classifier_binary_2d_nonlinear_labels_train.dat") | ||
File f_labels_test = csv_file("../../data/classifier_binary_2d_nonlinear_labels_test.dat") | ||
|
||
#![create_features] | ||
Features features_train = features(f_feats_train) | ||
Features features_test = features(f_feats_test) | ||
Labels labels_train = labels(f_labels_train) | ||
Labels labels_test = labels(f_labels_test) | ||
#![create_features] | ||
|
||
#![create_kernel] | ||
Kernel k_obj = kernel("GaussianKernel", log_width=1.0) | ||
k_obj.init(features_train, features_train) | ||
RealMatrix km_train = k_obj.get_kernel_matrix() | ||
k_obj.init(features_train, features_test) | ||
RealMatrix km_test = k_obj.get_kernel_matrix() | ||
Kernel k_train = kernel(km_train) | ||
Kernel k_test = kernel(km_test) | ||
#![create_kernel] | ||
|
||
#![create_machine] | ||
Machine svm = machine("LibSVM", C1=1.0, C2=1.0, kernel=k_train, labels=labels_train, epsilon=0.001) | ||
#![create_machine] | ||
|
||
#![train_and_apply] | ||
svm.train() | ||
svm.put("kernel", k_test) | ||
Labels labels_predict = svm.apply() | ||
RealVector labels = labels_predict.get_real_vector("labels") | ||
#![train_and_apply] | ||
|
||
#![evaluate_accuracy] | ||
Evaluation eval = evaluation("AccuracyMeasure") | ||
real accuracy = eval.evaluate(labels_predict, labels_test) | ||
#![evaluate_accuracy] | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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
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