Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ShareBoost python modular interface and example
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
examples/undocumented/python_modular/classifier_multiclass_shareboost.py
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,36 @@ | ||
import classifier_multiclass_shared | ||
|
||
[traindat, label_traindat, testdat, label_testdat] = classifier_multiclass_shared.prepare_data(False) | ||
|
||
parameter_list = [[traindat,testdat,label_traindat,label_testdat,2.1,1,1e-5],[traindat,testdat,label_traindat,label_testdat,2.2,1,1e-5]] | ||
|
||
def classifier_multiclass_shareboost (fm_train_real=traindat,fm_test_real=testdat,label_train_multiclass=label_traindat,label_test_multiclass=label_testdat,lawidth=2.1,C=1,epsilon=1e-5): | ||
from shogun.Features import RealFeatures, RealSubsetFeatures, MulticlassLabels | ||
from shogun.Classifier import ShareBoost | ||
|
||
feats_train = RealFeatures(fm_train_real) | ||
|
||
labels = MulticlassLabels(label_train_multiclass) | ||
|
||
shareboost = ShareBoost(feats_train, labels, min(fm_train_real.shape[0]-1, 10)) | ||
shareboost.train(); | ||
print(shareboost.get_activeset()) | ||
|
||
feats_test = RealSubsetFeatures(RealFeatures(fm_test_real), shareboost.get_activeset()) | ||
label_pred = shareboost.apply(feats_test) | ||
|
||
out = label_pred.get_labels() | ||
|
||
if label_test_multiclass is not None: | ||
from shogun.Evaluation import MulticlassAccuracy | ||
labels_test = MulticlassLabels(label_test_multiclass) | ||
evaluator = MulticlassAccuracy() | ||
acc = evaluator.evaluate(label_pred, labels_test) | ||
print('Accuracy = %.4f' % acc) | ||
|
||
return out | ||
|
||
if __name__=='__main__': | ||
print('MulticlassMachine') | ||
classifier_multiclass_shareboost(*parameter_list[0]) | ||
|
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