I need to manually remove attributes using Remove after performing Attribute
Selection. I use the ReliefF method to create a ranking and then remove the
last attributes.
This is the code I am using for Attribute Selection:
/function attSel = wekaAttributeSelection( data, evaluator,
evaluator_options, search, search_options )
%%%some input checking here
evalObj = javaObject(evaluator);
if ~isempty(evaluator_options)
evalObj.setOptions(evaluator_options);
end
searchObj = javaObject(search);
if ~isempty(search_options)
searchObj.setOptions(search_options);
end
attSel = weka.attributeSelection.AttributeSelection();
attSel.setEvaluator(evalObj);
attSel.setSearch(searchObj);
attSel.SelectAttributes(data);
end/
And this is the code where I use Remove, and then try to classify the output
using RotationForest:
/function [AUC1,AUC2] = rocWeka(removidos,folds)
% ROC Curve
javaaddpath('C:\Program Files\Weka-3-6\weka.jar');
filename1='C:\Users\guilh_000\MyFile.arff';
if(~wekaPathCheck); return,end
% Some imports here
%% Loading arff file and creation of Instances object
filename = java.lang.String(filename1); % matlab string -> java string
loader = ArffLoader(); % loader constructor
loader.setFile(File(filename)); % loading arff
wekaOBJ = loader.getDataSet(); % Instances object from loader
wekaOBJ.setClassIndex(wekaOBJ.numAttributes - 1); % class is last attribute
wekaClassifier = weka.classifiers.meta.RotationForest;
options = Utils.splitOptions('-G 3 -H 3 -P 50 -F
"weka.filters.unsupervised.attribute.PrincipalComponents -R 1.0 -A 5 -M -1"
-S 1 -I 10 -W weka.classifiers.trees.J48 -- -C 0.25 -M 2');
wekaClassifier.setOptions(options)
%% Cross validation
evalWeka = Evaluation(wekaOBJ);
% Mandatory parameters to get it working (supposed optional)
ran = Random(1);
sb = StringBuffer(0);
range = Range();
bo = Boolean(false);
ob = [sb; range; bo];
wekaOBJ = wekaAttributeSelection(wekaOBJ,
'weka.attributeSelection.ReliefFAttributeEval', [], 'Ranker', []);
f = javaObject('weka.filters.unsupervised.attribute.Remove');
f.setAttributeIndices(removidos);
*f.setInputFormat(wekaOBJ);*
rD = javaMethod('useFilter', 'weka.filters.Filter', wekaOBJ, f);
evalWeka.crossValidateModel(wekaClassifier, rD, folds, ran, ob);
AUC1 = evalWeka.areaUnderROC(0);
AUC2 = evalWeka.areaUnderROC(1);
end/
The problem happens at this line:
*f.setInputFormat(wekaOBJ);*
I get it that it is a incompatility problem with the object type. But the
code works fine without using Attribute Selection.
Thanks in advance.
Regards,
Guilherme Freire
--
Sent from:
http://weka.8497.n7.nabble.com/_______________________________________________
Wekalist mailing list
Send posts to:
[hidden email]
To subscribe, unsubscribe, etc., visit
https://list.waikato.ac.nz/mailman/listinfo/wekalistList etiquette:
http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html