本文整理汇总了Java中weka.filters.supervised.attribute.AttributeSelection类的典型用法代码示例。如果您正苦于以下问题:Java AttributeSelection类的具体用法?Java AttributeSelection怎么用?Java AttributeSelection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeSelection类属于weka.filters.supervised.attribute包,在下文中一共展示了AttributeSelection类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: InfoGainAttributeEval
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public static AttributeSelection InfoGainAttributeEval(Instances data) throws Exception{
AttributeSelection filter = new AttributeSelection();
InfoGainAttributeEval evaluator = new InfoGainAttributeEval();
filter.setEvaluator(evaluator);
Ranker search = new Ranker();
search.setThreshold(0);
filter.setSearch(search);
filter.setInputFormat(data);
return filter;
}
开发者ID:amineabdaoui,项目名称:french-sentiment-classification,代码行数:12,代码来源:SelectionAttributs.java
示例2: createFilter
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public static AttributeSelection createFilter(int numAtts) {
AttributeSelection filter = new AttributeSelection();
try {
Ranker search = new Ranker();
//search.setSearchBackwards(true);
search.setNumToSelect(numAtts);
GainRatioAttributeEval eval = new GainRatioAttributeEval();
//InfoGainAttributeEval eval = new InfoGainAttributeEval();
//ReliefFAttributeEval eval = new ReliefFAttributeEval();
filter.setEvaluator(eval);
filter.setSearch(search);
//filter.setInputFormat(data);
} catch (Exception e) {
e.printStackTrace();
}
return filter;
}
开发者ID:socialsensor,项目名称:computational-verification,代码行数:23,代码来源:AttributeSelectionHandler.java
示例3: GainRatioAttributeEval
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public static AttributeSelection GainRatioAttributeEval(Instances data, int n) throws Exception{
AttributeSelection filter = new AttributeSelection();
GainRatioAttributeEval evaluator = new GainRatioAttributeEval();
filter.setEvaluator(evaluator);
Ranker search = new Ranker();
search.setNumToSelect(n);
filter.setSearch(search);
filter.setInputFormat(data);
return filter;
}
开发者ID:amineabdaoui,项目名称:french-sentiment-classification,代码行数:12,代码来源:SelectionAttributs.java
示例4: buildAttributeFilterFor
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
private static Filter buildAttributeFilterFor(AttributeFilter attributeFilter, Instances dataSet) throws Exception
{
ASEvaluation evaluator = attributeFilter.getEvalClazz().newInstance();
((OptionHandler) evaluator).setOptions(Utils.splitOptions(attributeFilter.getEvalConfig()));
ASSearch search = attributeFilter.getSearchClazz().newInstance();
((OptionHandler) search).setOptions(Utils.splitOptions(attributeFilter.getSearchConfig()));
Filter filter = new AttributeSelection();
filter.setInputFormat(dataSet);
((AttributeSelection) filter).setEvaluator(evaluator);
((AttributeSelection) filter).setSearch(search);
return filter;
}
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:16,代码来源:FilterConfiguration.java
示例5: configureCostSensitiveClassifier
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/**
* Sets a default CostSensitiveClassifier with SMO. The settings of this method must be modified if used for another project.
* @param data weka data containing instances and attributes
* @param costSensitiveClassifier unconfigured Cost Sensitive Classifier
* @param costMatrix Cost Matrix
* @return CostSensitiveClassifier fully configured Cost Sensitive Classifier
* @throws Exception
*/
protected static CostSensitiveClassifier configureCostSensitiveClassifier(CostSensitiveClassifier costSensitiveClassifier,
Instances data, String costMatrix) throws Exception {
String[] CscOptions = {"-cost-matrix", costMatrix, "-S", "1"};
String[] rankerOptions = {"-P",Integer.toString(data.numAttributes() - 1),"-T","-1.7976931348623157E308","-N","-1"};
String[] smoOptions = {"-C", "1.0", "-L", "0.0010", "-P", "1.0E-12", "-N", "0", "-V", "-1", "-W", "1", "-K",
PolyKernel.class.getName()+" -C 250007 -E 2.0"};
InfoGainAttributeEval igAttEval = new InfoGainAttributeEval();
Ranker ranker = new Ranker();
ranker.setOptions(rankerOptions);
AttributeSelection attSelect = new AttributeSelection();
attSelect.setEvaluator(igAttEval);
attSelect.setSearch(ranker);
SMO smo = new SMO();
smo.setOptions(smoOptions);
FilteredClassifier filteredClsfr = new FilteredClassifier();
filteredClsfr.setClassifier(smo);
filteredClsfr.setFilter(attSelect);
costSensitiveClassifier.setOptions(CscOptions);
costSensitiveClassifier.setClassifier(filteredClsfr);
costSensitiveClassifier.buildClassifier(data);
System.out.println("CostSensitiveClassifier built.");
return costSensitiveClassifier;
}
开发者ID:UKPLab,项目名称:jlcl2015-pythagoras,代码行数:39,代码来源:ListMisclassifiedInstances.java
示例6: InformationGain
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public InformationGain(Instances dataset) throws Exception{
data = dataset;
infoG = new InfoGainAttributeEval();
infoG.buildEvaluator(data);
filter = new AttributeSelection();
search = new Ranker();
search.setThreshold(0.0);
}
开发者ID:a-n-d-r-e-i,项目名称:seagull,代码行数:9,代码来源:InformationGain.java
示例7: useFilter
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/**
* uses the filter
*/
public Instances useFilter(Instances data, AttributeSelection filter) throws Exception {
System.out.println("\n2. Filter");
System.out.println(data.get(0));
Instances newData = Filter.useFilter(data, filter);
for (int i=0;i<newData.numAttributes();i++){
System.out.print(newData.attribute(i).name()+" ");
}
// write training set to file
/*BufferedWriter bw = null;
String filePath = "training_newdata.txt";
for (int i = 0; i < newData.size(); i++) {
try {
bw = new BufferedWriter(new FileWriter(filePath, true));
// if file doesn't exist, then create it
bw.append(newData.get(i).toString());
bw.newLine();
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}*/
//System.out.println(newData);
return newData;
}
开发者ID:socialsensor,项目名称:computational-verification,代码行数:33,代码来源:AttributeSelectionHandler.java
示例8: createFilter2
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public static AttributeSelection createFilter2(Instances data) throws Exception {
weka.filters.supervised.attribute.AttributeSelection filter = new weka.filters.supervised.attribute.AttributeSelection();
CfsSubsetEval eval = new CfsSubsetEval();
GreedyStepwise search = new GreedyStepwise();
search.setSearchBackwards(true);
search.setGenerateRanking(true);
search.setNumToSelect(15);
//System.out.println("threshold "+search.getThreshold());
filter.setEvaluator(eval);
filter.setSearch(search);
//filter.setInputFormat(data);
return filter;
}
开发者ID:socialsensor,项目名称:computational-verification,代码行数:16,代码来源:AttributeSelectionHandler.java
示例9: useLowLevel
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/**
* uses the low level approach
*/
public void useLowLevel(Instances data) throws Exception {
System.out.println("\n3. Low-level");
weka.attributeSelection.AttributeSelection attsel = new weka.attributeSelection.AttributeSelection ();
CfsSubsetEval eval = new CfsSubsetEval();
GreedyStepwise search = new GreedyStepwise();
search.setSearchBackwards(true);
attsel.setEvaluator(eval);
attsel.setSearch(search);
attsel.SelectAttributes(data);
int[] indices = attsel.selectedAttributes();
System.out.println("selected attribute indices (starting with 0):\n" + Utils.arrayToString(indices));
}
开发者ID:socialsensor,项目名称:computational-verification,代码行数:18,代码来源:AttributeSelectionHandler.java
示例10: WekaAttributeSelection
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public WekaAttributeSelection(ASEvaluation evaluator,
ASSearch searcher) {
this.attrsel = new AttributeSelection();
this.evaluator = evaluator;
this.Searcher = searcher;
this.attreval = (AttributeEvaluator) evaluator;
}
开发者ID:eracle,项目名称:gap,代码行数:8,代码来源:WekaAttributeSelection.java
示例11: getEvalResultbyChiSquare
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/***
* <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
* <p>Use C4.5 and <b>SMOTE</b>, combined with <b>Chi-Square</b> to classify the dataset.</p>
* @param path dataset path
* @throws Exception
*/
public static void getEvalResultbyChiSquare(String path, int index) throws Exception{
Instances ins = DataSource.read(path);
int numAttr = ins.numAttributes();
ins.setClassIndex(numAttr - 1);
/**chi-squared filter to process the whole dataset first*/
ChiSquaredAttributeEval evall = new ChiSquaredAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(ins);
ins = Filter.useFilter(ins, selector);
SMOTE smote = new SMOTE();
smote.setInputFormat(ins);
/** classifiers setting*/
J48 j48 = new J48();
// j48.setConfidenceFactor(0.4f);
j48.buildClassifier(ins);
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(j48);
fc.setFilter(smote);
Evaluation eval = new Evaluation(ins);
eval.crossValidateModel(fc, ins, 10, new Random(1));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
// System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
results[index][0] = eval.precision(0);
results[index][1] = eval.recall(0);
results[index][2] = eval.fMeasure(0);
results[index][3] = eval.precision(1);
results[index][4] = eval.recall(1);
results[index][5] = eval.fMeasure(1);
results[index][6] = 1-eval.errorRate();
}
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:50,代码来源:FeatureSelectionAve.java
示例12: getEvalResultbyInfoGain
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/***
* <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
* <p>Use C4.5 and <b>SMOTE</b>, combined with <b>Information Gain</b> to classify the dataset.</p>
* @param path dataset path
* @throws Exception
*/
public static void getEvalResultbyInfoGain(String path, int index) throws Exception{
Instances ins = DataSource.read(path);
int numAttr = ins.numAttributes();
ins.setClassIndex(numAttr - 1);
/**information gain filter to process the whole dataset first*/
InfoGainAttributeEval evall = new InfoGainAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(ins);
ins = Filter.useFilter(ins, selector);
SMOTE smote = new SMOTE();
smote.setInputFormat(ins);
/** classifiers setting*/
J48 j48 = new J48();
// j48.setConfidenceFactor(0.4f);
j48.buildClassifier(ins);
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(j48);
fc.setFilter(smote);
Evaluation eval = new Evaluation(ins);
eval.crossValidateModel(fc, ins, 10, new Random(1));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
// System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
results[index][0] = eval.precision(0);
results[index][1] = eval.recall(0);
results[index][2] = eval.fMeasure(0);
results[index][3] = eval.precision(1);
results[index][4] = eval.recall(1);
results[index][5] = eval.fMeasure(1);
results[index][6] = 1-eval.errorRate();
}
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:50,代码来源:FeatureSelectionAve.java
示例13: getEvalResultbyGainRatio
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/***
* <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
* <p>Use C4.5 and <b>SMOTE</b>, combined with <b>Information Gain Ratio</b> to classify the dataset.</p>
* @param path dataset path
* @throws Exception
*/
public static void getEvalResultbyGainRatio(String path, int index) throws Exception{
Instances ins = DataSource.read(path);
int numAttr = ins.numAttributes();
ins.setClassIndex(numAttr - 1);
/**information gain ratio filter to process the whole dataset first*/
GainRatioAttributeEval evall = new GainRatioAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(ins);
ins = Filter.useFilter(ins, selector);
SMOTE smote = new SMOTE();
smote.setInputFormat(ins);
/** classifiers setting*/
J48 j48 = new J48();
// j48.setConfidenceFactor(0.4f);
j48.buildClassifier(ins);
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(j48);
fc.setFilter(smote);
Evaluation eval = new Evaluation(ins);
eval.crossValidateModel(fc, ins, 10, new Random(1));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
// System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
results[index][0] = eval.precision(0);
results[index][1] = eval.recall(0);
results[index][2] = eval.fMeasure(0);
results[index][3] = eval.precision(1);
results[index][4] = eval.recall(1);
results[index][5] = eval.fMeasure(1);
results[index][6] = 1-eval.errorRate();
}
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:50,代码来源:FeatureSelectionAve.java
示例14: getEvalResultbyCorrelation
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/***
* <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
* <p>Use C4.5 and <b>SMOTE</b>, combined with <b>Correlation</b> to classify the dataset.</p>
* @param path dataset path
* @throws Exception
*/
public static void getEvalResultbyCorrelation(String path, int index) throws Exception{
Instances ins = DataSource.read(path);
int numAttr = ins.numAttributes();
ins.setClassIndex(numAttr - 1);
/** correlation filter to process the whole dataset first*/
CorrelationAttributeEval evall = new CorrelationAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(ins);
ins = Filter.useFilter(ins, selector);
SMOTE smote = new SMOTE();
smote.setInputFormat(ins);
/** classifiers setting*/
J48 j48 = new J48();
// j48.setConfidenceFactor(0.4f);
j48.buildClassifier(ins);
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(j48);
fc.setFilter(smote);
Evaluation eval = new Evaluation(ins);
eval.crossValidateModel(fc, ins, 10, new Random(1));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
// System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
results[index][0] = eval.precision(0);
results[index][1] = eval.recall(0);
results[index][2] = eval.fMeasure(0);
results[index][3] = eval.precision(1);
results[index][4] = eval.recall(1);
results[index][5] = eval.fMeasure(1);
results[index][6] = 1-eval.errorRate();
}
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:50,代码来源:FeatureSelectionAve.java
示例15: getEvalResultbyReliefF
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/***
* <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
* <p>Use C4.5 and <b>SMOTE</b>, combined with <b>ReliefF</b> to classify the dataset.</p>
* @param path dataset path
* @throws Exception
*/
public static void getEvalResultbyReliefF(String path, int index) throws Exception{
Instances ins = DataSource.read(path);
int numAttr = ins.numAttributes();
ins.setClassIndex(numAttr - 1);
/** correlation filter to process the whole dataset first*/
ReliefFAttributeEval evall = new ReliefFAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(ins);
ins = Filter.useFilter(ins, selector);
SMOTE smote = new SMOTE();
smote.setInputFormat(ins);
/** classifiers setting*/
J48 j48 = new J48();
// j48.setConfidenceFactor(0.4f);
j48.buildClassifier(ins);
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(j48);
fc.setFilter(smote);
Evaluation eval = new Evaluation(ins);
eval.crossValidateModel(fc, ins, 10, new Random(1));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
// System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
// System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
results[index][0] = eval.precision(0);
results[index][1] = eval.recall(0);
results[index][2] = eval.fMeasure(0);
results[index][3] = eval.precision(1);
results[index][4] = eval.recall(1);
results[index][5] = eval.fMeasure(1);
results[index][6] = 1-eval.errorRate();
}
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:50,代码来源:FeatureSelectionAve.java
示例16: showFolds
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
/***
* <p>Using Feature Selection method to get 10 folds results in the given project</p>
* @param path project path
* @param sel label means we use the Feature Selection method
* @throws Exception
*/
public static void showFolds(String path, int k, int flag) throws Exception{
Instances data1 = DataSource.read(path);
data1.setClassIndex(data1.numAttributes()-1);
if(!data1.classAttribute().isNominal()) // in case of noisy data, return
return;
/** Feature Selection: Correlation */
CorrelationAttributeEval evall = new CorrelationAttributeEval();
Ranker ranker = new Ranker();
AttributeSelection selector = new AttributeSelection();
selector.setEvaluator(evall);
selector.setSearch(ranker);
selector.setInputFormat(data1);
data1 = Filter.useFilter(data1, selector);
/** Randomize and stratify the dataset*/
data1.randomize(new Random(1));
data1.stratify(10); // 10 folds
double[][] matrix = new double[10][7];
for(int i=0; i<10; i++){ // To calculate the results in each fold
Instances test = data1.testCV(10, i);
Instances train = data1.trainCV(10, i);
/** SMOTE */
SMOTE smote = new SMOTE();
smote.setInputFormat(train);
train = Filter.useFilter(train, smote);
/** C4.5 */
J48 rf = new J48();
// RandomForest rf = new RandomForest();
// rf.setNumIterations(300);
rf.buildClassifier(train);
Evaluation eval = new Evaluation(train);
eval.evaluateModel(rf, test);
matrix[i][6] = 1-eval.errorRate();
matrix[i][0] = eval.precision(0);
matrix[i][1] = eval.recall(0);
matrix[i][2] = eval.fMeasure(0);
matrix[i][3] = eval.precision(1);
matrix[i][4] = eval.recall(1);
matrix[i][5] = eval.fMeasure(1);
}
for(int i=0;i<10;i++){
for(int j=0;j<7;j++){
System.out.printf("%15.8f", matrix[i][j]);
}
System.out.println("");
}
}
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:71,代码来源:FoldResultsAve.java
示例17: useFilter2
import weka.filters.supervised.attribute.AttributeSelection; //导入依赖的package包/类
public Instances useFilter2(Instances data,AttributeSelection filter) throws Exception {
System.out.println("\n2. Filter");
Instances newData = Filter.useFilter(data, filter);
//System.out.println(newData);
for (int i=0;i<newData.numAttributes();i++){
System.out.print(newData.attribute(i).name()+" ");
}
return newData;
}
开发者ID:socialsensor,项目名称:computational-verification,代码行数:14,代码来源:AttributeSelectionHandler.java
注:本文中的weka.filters.supervised.attribute.AttributeSelection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论