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 #217 from sploving/master
add some more lua examples
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
examples/undocumented/lua_modular/evaluation_contingencytableevaluation_modular.lua
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,53 @@ | ||
require 'shogun' | ||
require 'load' | ||
|
||
ground_truth = load_labels('../data/label_train_twoclass.dat') | ||
math.randomseed(17) | ||
|
||
predicted = {} | ||
for i = 1, #ground_truth do | ||
table.insert(predicted, math.random()) | ||
end | ||
parameter_list = {{ground_truth,predicted}} | ||
|
||
function evaluation_contingencytableevaluation_modular(ground_truth, predicted) | ||
|
||
ground_truth_labels = Labels(ground_truth) | ||
predicted_labels = Labels(predicted) | ||
|
||
base_evaluator = ContingencyTableEvaluation() | ||
base_evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = AccuracyMeasure() | ||
accuracy = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = ErrorRateMeasure() | ||
errorrate = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = BALMeasure() | ||
bal = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = WRACCMeasure() | ||
wracc = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = F1Measure() | ||
f1 = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = CrossCorrelationMeasure() | ||
crosscorrelation = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = RecallMeasure() | ||
recall = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = PrecisionMeasure() | ||
precision = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
evaluator = SpecificityMeasure() | ||
specificity = evaluator:evaluate(predicted_labels,ground_truth_labels) | ||
|
||
return accuracy, errorrate, bal, wracc, f1, crosscorrelation, recall, precision, specificity | ||
end | ||
|
||
print 'ContingencyTableEvaluation' | ||
evaluation_contingencytableevaluation_modular(unpack(parameter_list[1])) | ||
|
17 changes: 17 additions & 0 deletions
17
examples/undocumented/lua_modular/features_simple_real_modular.lua
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,17 @@ | ||
require 'shogun' | ||
|
||
matrix = {{1,2,3},{4,0,0},{0,0,0},{0,5,0},{0,0,6},{9,9,9}} | ||
|
||
parameter_list = {{matrix}} | ||
|
||
function features_simple_real_modular(A) | ||
a=RealFeatures(A) | ||
a:set_feature_vector({1,4,0,0,0,9}, 0) | ||
|
||
a_out = a:get_feature_matrix() | ||
|
||
return a_out | ||
end | ||
|
||
print 'simple_real' | ||
features_simple_real_modular(unpack(parameter_list[1])) |
20 changes: 20 additions & 0 deletions
20
examples/undocumented/lua_modular/preprocessor_classicisomap_modular.lua
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,20 @@ | ||
require 'shogun' | ||
require 'load' | ||
|
||
data = load_numbers('../data/fm_train_real.dat') | ||
|
||
parameter_list = {{data}} | ||
|
||
function preprocessor_classicisomap_modular(data) | ||
features = RealFeatures(data) | ||
|
||
preprocessor = ClassicIsomap() | ||
preprocessor:set_target_dim(1) | ||
preprocessor:apply_to_feature_matrix(features) | ||
|
||
return features | ||
end | ||
|
||
print 'ClassicIsomap' | ||
preprocessor_classicisomap_modular(unpack(parameter_list[1])) | ||
|
28 changes: 28 additions & 0 deletions
28
examples/undocumented/lua_modular/regression_krr_modular.lua
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,28 @@ | ||
require 'shogun' | ||
require 'load' | ||
|
||
traindat = load_numbers('../data/fm_train_real.dat') | ||
testdat = load_numbers('../data/fm_test_real.dat') | ||
label_traindat = load_labels('../data/label_train_twoclass.dat') | ||
|
||
|
||
parameter_list = {{traindat,testdat,label_traindat,0.8,1e-6},{traindat,testdat,label_traindat,0.9,1e-7}} | ||
|
||
function regression_krr_modular (fm_train,fm_test,label_train,width,tau) | ||
feats_train=RealFeatures(fm_train) | ||
feats_test=RealFeatures(fm_test) | ||
|
||
kernel=GaussianKernel(feats_train, feats_train, width) | ||
|
||
labels=Labels(label_train) | ||
|
||
krr=KRR(tau, kernel, labels) | ||
krr:train(feats_train) | ||
|
||
kernel:init(feats_train, feats_test) | ||
out = krr:apply():get_labels() | ||
return out,kernel,krr | ||
end | ||
|
||
print 'KRR' | ||
regression_krr_modular(unpack(parameter_list[1])) |
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