本文整理汇总了Java中weka.classifiers.lazy.IBk类的典型用法代码示例。如果您正苦于以下问题:Java IBk类的具体用法?Java IBk怎么用?Java IBk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IBk类属于weka.classifiers.lazy包,在下文中一共展示了IBk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classify
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public void classify(){
super.confusionMatrix = new int[classPossibilities][classPossibilities];
IBk nereastNeighbor = new IBk(neighbors);
for (int i = 0; i < iterations; i++) {
Instances dataTrain = dataSource.trainCV(partitions,i);
Instances dataTest = dataSource.testCV(partitions, i);
int realClass = 0;
int resultClass = 0;
try {
nereastNeighbor.buildClassifier(dataTrain);
for (int j = 0; j < dataTest.numInstances(); j++) {
Instance example = dataTest.instance(j);
realClass = (int)example.value(classIndex);
example.setClassMissing();
resultClass = (int)nereastNeighbor.classifyInstance(example);
this.confusionMatrix[realClass][resultClass]++;
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
示例2: classify
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public void classify(){
IBk nereastNeighbor = new IBk();
int realClass = 0;
int resultClass = 0;
this.confusionMatrix = new int[classPossibilities][classPossibilities];
try {
nereastNeighbor.buildClassifier(this.dataSource);
for (int i = 0; i < this.dataSourceToClassify.numInstances(); i++) {
Instance example = this.dataSourceToClassify.instance(i);
realClass = (int)example.value(classIndex);
example.setClassMissing();
resultClass = (int)nereastNeighbor.classifyInstance(example);
this.confusionMatrix[realClass][resultClass]++;
}
} catch(Exception e) {
e.printStackTrace();
}
}
示例3: Classification
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public Classification(ArrayList<ClassifierType> cType) {
cls = new Classifier[cType.size()];
eval = new Evaluation[cType.size()];
for(int i = 0; i < cType.size();i++){
switch(cType.get(i)){
// TODO Will we use J48 or ID3 implementation of decision trees?
case J48:
cls[i] = new J48();
break;
case NAIVE_BAYES:
// If bType == Incremental then cls = new UpdateableNaiveBayes(); else
cls[i] = new NaiveBayes();
break;
case IBK:
cls[i] = new IBk();
break;
case COSINE:
cls[i] = useCosine();
// TODO Add other cases: Decision Rule, KNN and so on.
}
}
}
示例4: initializeMembers
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
/**
* performs initialization of members
*/
@Override
protected void initializeMembers() {
super.initializeMembers();
m_KNNdetermined = -1;
m_NeighborsTestset = null;
m_TrainsetNew = null;
m_TestsetNew = null;
m_UseNaiveSearch = false;
m_LabeledTestset = null;
m_Missing = new ReplaceMissingValues();
m_Classifier = new IBk();
m_Classifier.setKNN(10);
m_Classifier.setCrossValidate(true);
m_Classifier.setWindowSize(0);
m_Classifier.setMeanSquared(false);
m_KNN = m_Classifier.getKNN();
m_AdditionalMeasures.add("measureDeterminedKNN");
}
示例5: useCosine
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
private IBk useCosine() {
IBk ibk = new IBk();
Instances data = ClassificationModel.getInstance().getInstances();
Normalize normalizer = new Normalize();
try {
normalizer.setInputFormat(data);
// Euclidean Distance working over normalized instances = Cosine Similarity according to Foundations of Statistical Natural Processing Language p.301
// As long as attribute normalization is disabled.
Instances normalizedInstances;
normalizedInstances = Filter.useFilter(data, normalizer);
ClassificationModel.getInstance().setInstances(normalizedInstances);
DistanceFunction df = new EuclideanDistance();
((EuclideanDistance) df).setDontNormalize(true);
ibk.getNearestNeighbourSearchAlgorithm().setDistanceFunction(df);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ibk;
}
示例6: makeOnlineClassifier
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public static Classifier makeOnlineClassifier(String wekaClassifier, String[] options) throws Exception {
switch (WekaOnlineClassificationAlgorithms.valueOf(wekaClassifier)) {
case naiveBayes:
NaiveBayesUpdateable naiveBayesUpdateable = new NaiveBayesUpdateable();
setOptionsForWekaPredictor(options, naiveBayesUpdateable);
return naiveBayesUpdateable;
case locallyWeightedLearner:
LWL lwl = new LWL();
setOptionsForWekaPredictor(options, lwl);
return lwl;
case nearestNeighbors:
IBk ibk = new IBk();
setOptionsForWekaPredictor(options, ibk);
return ibk;
case onlineDecisionTree:
HoeffdingTree tree = new HoeffdingTree();
setOptionsForWekaPredictor(options, tree);
return tree;
case stochasticGradientDescent:
SGD sgd = new SGD();
setOptionsForWekaPredictor(options, sgd);
return sgd;
default:
return new NaiveBayesUpdateable();
}
}
示例7: getIBk
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
/**
* Weka implementation of kNN
*/
public Classifier getIBk() throws Exception {
Classifier model = new IBk();
model.buildClassifier(instances);
return model;
}
示例8: LearnKNN
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
@Override
public void LearnKNN() throws Exception {
trainedData.setClassIndex(trainedData.numAttributes()-1);
filter=new StringToWordVector();
classifier=new FilteredClassifier();
classifier.setFilter(filter);
classifier.setClassifier(new IBk());
classifier.buildClassifier(trainedData);
}
示例9: trainClassifier
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public void trainClassifier(Classifier classifier, File trainingDataset,
FileOutputStream trainingModel, Integer
crossValidationFoldNumber) throws Exception {
CSVLoader csvLoader = new CSVLoader();
csvLoader.setSource(trainingDataset);
Instances instances = csvLoader.getDataSet();
switch(classifier) {
case KNN:
int K = (int) Math.ceil(Math.sqrt(instances.numInstances()));
this.classifier = new IBk(K);
break;
case NB:
this.classifier = new NaiveBayes();
}
if(instances.classIndex() == -1) {
instances.setClassIndex(instances.numAttributes() - 1);
}
this.classifier.buildClassifier(instances);
if(crossValidationFoldNumber > 0) {
Evaluation evaluation = new Evaluation(instances);
evaluation.crossValidateModel(this.classifier, instances, crossValidationFoldNumber,
new Random(1));
kappa = evaluation.kappa();
fMeasure = evaluation.weightedFMeasure();
confusionMatrix = evaluation.toMatrixString("Confusion matrix: ");
}
ObjectOutputStream outputStream = new ObjectOutputStream(trainingModel);
outputStream.writeObject(this.classifier);
outputStream.flush();
outputStream.close();
}
示例10: evaluate_untrainedClassifier_throwClassifierPredictionException
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
@Test(expected = ClassifierPredictionException.class)
public void evaluate_untrainedClassifier_throwClassifierPredictionException() {
// Arrange
Instances validationSet = getTestCoupledInstances();
Classifier untrainedClassifier = new IBk();
// Act
EvaluationResult evaluation = evaluator.evaluate(untrainedClassifier, validationSet);
// Assert
assertEquals(1, evaluation.getMisclassifications().size());
}
示例11: getTrainedClassifier
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
private Classifier getTrainedClassifier(Instances validationSet) {
Classifier classifier = new IBk(); // IBk is k-nearest neighbor
try {
classifier.buildClassifier(validationSet);
} catch (Exception e) {
throw new RuntimeException(e);
}
return classifier;
}
示例12: KNNIBK
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
/** Constructor for the KNN, with the default number of neighbours. */
public KNNIBK() {
if(LogService.minVerbosityLevel>0)
System.out.println("For KNN, kk="+kk);
wekaCl = new IBk(kk);
learnerName = "KNN";
}
示例13: EvaluateKNN
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
@Override
public List<Classification> EvaluateKNN() throws Exception
{
List<Classification> lstEvaluationDetail=new ArrayList<>();
trainedData.setClassIndex(trainedData.numAttributes()-1);
filter=new StringToWordVector();
classifier=new FilteredClassifier();
classifier.setFilter(filter);
classifier.setClassifier(new IBk());
Evaluation eval=new Evaluation(trainedData);
eval.crossValidateModel(classifier, trainedData, 4, new Random(1));
/*try
{
for(int i=0;i<10000;i++)
{
cls.setPrecision(eval.precision(i));
cls.setRecall(eval.recall(i));
cls.setAuc(eval.areaUnderPRC(i));
cls.setFMeasure(eval.fMeasure(i));
cls.setFn(eval.falseNegativeRate(i));
cls.setFp(eval.falsePositiveRate(i));
cls.setTn(eval.trueNegativeRate(i));
cls.setTp(eval.truePositiveRate(i));
cls.setMeanAbsoluteError(eval.meanAbsoluteError());
cls.setRelativeAbsoluteError(eval.relativeAbsoluteError());
cls.setCorrect(eval.correct());
cls.setKappa(eval.kappa());
cls.setNumInstances(eval.numInstances());
cls.setInCorrect(eval.incorrect());
lstEvaluationDetail.add(new Classification(cls.getPrecision(),
cls.getRecall(),
cls.getAuc(),
cls.getCorrect(),
cls.getInCorrect(),
cls.getErrorRate(),
cls.getFn(),
cls.getFp(),
cls.getTn(),
cls.getTp(),
cls.getKappa(),
cls.getMeanAbsoluteError(),
cls.getNumInstances(),
cls.getRelativeAbsoluteError(),
cls.getFMeasure()));
}
}
catch(Exception ex)
{
}*/
return lstEvaluationDetail;
}
示例14: main
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public static void main(String[] args) {
try {
Instances instances = DataImport.getInstancesFromARFF(IONOSPHERE_FILEPATH);
instances.setClassIndex(instances.numAttributes() - 1);
/*
LibSVM svm = new LibSVM();
svm.setOptions(Utils.splitOptions("-k 0"));
*/
EstimatorClassifiersWrapper holdOutSet =
new EstimatorClassifiersWrapper(new HoldOut(instances, 0.66),
new J48(), new NaiveBayes(), new IBk(3)
);
System.out.println(holdOutSet.getClassifiersErrors());
EstimatorClassifiersWrapper crossValidationSet =
new EstimatorClassifiersWrapper(new CrossValidation(instances, 10),
new J48(), new NaiveBayes(), new IBk(3)
);
System.out.println(crossValidationSet.getClassifiersErrors());
EstimatorClassifiersWrapper leaveOneOutSet =
new EstimatorClassifiersWrapper(new LeaveOneOut(instances),
new J48(), new NaiveBayes(), new IBk(3)
);
System.out.println(leaveOneOutSet.getClassifiersErrors());
EstimatorClassifiersWrapper bootstrapSet =
new EstimatorClassifiersWrapper(new Bootstrap(instances),
new J48(), new NaiveBayes(), new IBk(3)
);
System.out.println(bootstrapSet.getClassifiersErrors());
ClassifierEstimatorsWrapper j48Set = new ClassifierEstimatorsWrapper(
new J48(),
new HoldOut(instances, 0.66),
new CrossValidation(instances, 10),
new LeaveOneOut(instances),
new Bootstrap(instances)
);
System.out.println(j48Set.getEstimatorsErrors());
ClassifierEstimatorsWrapper naiveBayerSet = new ClassifierEstimatorsWrapper(
new NaiveBayes(),
new HoldOut(instances, 0.66),
new CrossValidation(instances, 10),
new LeaveOneOut(instances),
new Bootstrap(instances)
);
System.out.println(naiveBayerSet.getEstimatorsErrors());
ClassifierEstimatorsWrapper ibk3Set = new ClassifierEstimatorsWrapper(
new IBk(3),
new HoldOut(instances, 0.66),
new CrossValidation(instances, 10),
new LeaveOneOut(instances),
new Bootstrap(instances)
);
System.out.println(ibk3Set.getEstimatorsErrors());
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: classifyIBk
import weka.classifiers.lazy.IBk; //导入依赖的package包/类
public IBk classifyIBk(Instances data) throws Exception {
IBk ibk = new IBk();
ibk.setKNN(10);
ibk.buildClassifier(data);
return ibk;
}