List of usage examples for weka.classifiers.functions MultilayerPerceptron MultilayerPerceptron
public MultilayerPerceptron()
From source file:licensedetect.Classify.java
public Classify(Classifier type, String options) { // this.classifier = type; this.multi = new MultilayerPerceptron(); try {/*w w w.j a v a 2 s. com*/ // classifier.setOptions(options); multi.setHiddenLayers(options); } catch (Exception e1) { System.out.println("Could not set options"); // return; } }
From source file:lu.lippmann.cdb.ext.hydviga.gaps.GapFillerFactory.java
License:Open Source License
public static GapFiller getGapFiller(final Algo algo) throws Exception { final GapFiller tsgp; if (algo == Algo.EM_WITH_DISCR_TIME) tsgp = new GapFillerEM(true); else if (algo == Algo.EM) tsgp = new GapFillerEM(false); else if (algo == Algo.Interpolation) tsgp = new GapFillerInterpolation(false); else if (algo == Algo.ZeroR) tsgp = new GapFillerClassifier(false, new ZeroR()); else if (algo == Algo.REG_WITH_DISCR_TIME) tsgp = new GapFillerRegressions(true); else if (algo == Algo.REG) tsgp = new GapFillerRegressions(false); else if (algo == Algo.M5P_WITH_DISCR_TIME) tsgp = new GapFillerClassifier(true, new M5P()); else if (algo == Algo.M5P) tsgp = new GapFillerClassifier(false, new M5P()); else if (algo == Algo.ANN_WITH_DISCR_TIME) tsgp = new GapFillerClassifier(true, new MultilayerPerceptron()); else if (algo == Algo.ANN) tsgp = new GapFillerClassifier(false, new MultilayerPerceptron()); else if (algo == Algo.NEARESTNEIGHBOUR_WITH_DISCR_TIME) tsgp = new GapFillerClassifier(true, new IBk()); else if (algo == Algo.NEARESTNEIGHBOUR) tsgp = new GapFillerClassifier(false, new IBk()); else// w w w.j a va2 s.co m throw new Exception("Algo not managed -> " + algo); return tsgp; }
From source file:lu.lippmann.cdb.ext.hydviga.gaps.GapFillerFactory.java
License:Open Source License
public static GapFiller getGapFiller(final String algoname, final boolean useDiscretizedTime) throws Exception { final GapFiller tsgp; if (algoname.equals("EM")) tsgp = new GapFillerEM(useDiscretizedTime); else if (algoname.equals("Interpolation")) tsgp = new GapFillerInterpolation(useDiscretizedTime); else if (algoname.equals("ZeroR")) tsgp = new GapFillerClassifier(useDiscretizedTime, new ZeroR()); else if (algoname.equals("REG")) tsgp = new GapFillerRegressions(useDiscretizedTime); else if (algoname.equals("M5P")) tsgp = new GapFillerClassifier(useDiscretizedTime, new M5P()); else if (algoname.equals("ANN")) tsgp = new GapFillerClassifier(useDiscretizedTime, new MultilayerPerceptron()); else if (algoname.equals("NEARESTNEIGHBOUR")) tsgp = new GapFillerClassifier(useDiscretizedTime, new IBk()); else/*from ww w.ja v a 2 s.c o m*/ throw new Exception("Algo name not managed -> " + algoname); return tsgp; }
From source file:machinelearningcw.MachineLearningCw.java
public static void main(String[] args) throws Exception { Instances data[] = getAllFiles();//from ww w . jav a 2s. c om //writes the data to excel writer = new FileWriter( "\\\\ueahome4\\stusci5\\ypf12pxu\\data\\Documents\\Machine Learning\\adamt94-machinelearning-da75565f2abe\\adamt94-machinelearning-da75565f2abe\\data.csv"); writer.append("DataName"); writer.append(",");//next column writer.append("Offline"); writer.append(","); writer.append("Online"); writer.append(","); writer.append("Offlinestd"); writer.append(","); writer.append("Onlinestd"); writer.append(","); writer.append("CrossValidation"); writer.append(","); writer.append("Ensemble"); writer.append(","); writer.append("WEKA1"); writer.append(","); writer.append("WEKA2"); writer.append("\n");//new row for (int i = 0; i < data.length; i++) { System.out.println("===============" + fileNames.get(i) + "============="); writer.append(fileNames.get(i)); writer.append(","); data[i].setClassIndex(data[i].numAttributes() - 1); //1. Is one learning algorithm better than the other? // compareAlgorithms(data[i]); /*2. Does standardising the data produce a more accurate classifier? You can test this on both learningalgorithms.*/ // standardiseData(data[i]); /*3. Does choosing the learning algorithm through cross validation produce a more accurate classifier?*/ // crossValidation(data[i]); // 4. Does using an ensemble produce a more accurate classifier? // ensemble(data[i]); /*5. Weka contains several related classifiers in the package weka.classifiers.functions. Comparetwo of your classifiers (including the ensemble) to at least two of the following*/ /*======================================= Weka Classifiers =========================================*/ // VotedPerceptron mp = new VotedPerceptron(); // Logistic l = new Logistic(); // SimpleLogistic sl = new SimpleLogistic(); // MultilayerPerceptron mp = new MultilayerPerceptron(); // VotedPerceptron vp = new VotedPerceptron(); // // int numFolds = 10; // EvaluationUtils eval = new EvaluationUtils(); // ArrayList<Prediction> preds // = eval.getCVPredictions(mp, data[i], numFolds); // int correct = 0; // int total = 0; // for (Prediction pred : preds) { // if (pred.predicted() == pred.actual()) { // correct++; // } // total++; // } // double acc = ((double) correct / total); // // System.out.println("Logistic Accuracy: " + acc); // writer.append(acc + ","); int j = data[i].numClasses(); writer.append(j + ","); writer.append("\n"); } /*======================================================= TIMING EXPIREMENT ========================================================= */ //create all the classifiers perceptronClassifier online = new perceptronClassifier(); EnhancedLinearPerceptron offline = new EnhancedLinearPerceptron(); EnhancedLinearPerceptron onlinestd = new EnhancedLinearPerceptron(); onlinestd.setStandardiseAttributes = true; EnhancedLinearPerceptron offlinestd = new EnhancedLinearPerceptron(); offlinestd.setStandardiseAttributes = true; EnhancedLinearPerceptron crossvalidate = new EnhancedLinearPerceptron(); crossvalidate.setStandardiseAttributes = true; RandomLinearPerceptron random = new RandomLinearPerceptron(); Logistic l = new Logistic(); SimpleLogistic sl = new SimpleLogistic(); MultilayerPerceptron mp = new MultilayerPerceptron(); VotedPerceptron vp = new VotedPerceptron(); // timingExperiment(online, data); // timingExperiment(offline, data); //timingExperiment(onlinestd, data); //timingExperiment(offlinestd, data); //timingExperiment(crossvalidate, data); timingExperiment(random, data); //timingExperiment(l, data); //timingExperiment(sl, data); // timingExperiment(mp, data); // timingExperiment(vp, data); writer.flush(); writer.close(); }
From source file:machinelearningcw.MachineLearningCw.java
public static void wekaClassifiers() { Logistic l = new Logistic(); SimpleLogistic sl = new SimpleLogistic(); MultilayerPerceptron mp = new MultilayerPerceptron(); VotedPerceptron vp = new VotedPerceptron(); }
From source file:mlp.MLP.java
/** * build a multilayer perceptron using the given parameters and the training * set//ww w .j a v a2 s . co m * * @param learningRate the learning rate for the training * @param numberEpochs number of training epochs * @param numberNeurons number of neurons in the hidden layer * @param trainingSet the training set * @return * @throws Exception */ public static MultilayerPerceptron buildMLP(double learningRate, int numberEpochs, int numberNeurons, Instances trainingSet) throws Exception { MultilayerPerceptron mlp = new MultilayerPerceptron(); //set parameters mlp.setLearningRate(learningRate); mlp.setTrainingTime(numberEpochs); mlp.setHiddenLayers("" + numberNeurons); //build multilayer perceptron mlp.buildClassifier(trainingSet); return mlp; }
From source file:nl.detoren.ijc.neural.Voorspeller.java
License:Open Source License
/** * Create a multi layer perceptron network, with the following parameters - * learning rate = 0.1/* w w w. j ava 2s.c o m*/ * momentum = 0.1 * training iterations = 4096 * hidden layers = t (equals number of attributes + number of classes) * * @return */ public void initialiseerStandaard() { // Instance of NN mlp = new MultilayerPerceptron(); // Setting Parameters mlp.setLearningRate(0.1); mlp.setMomentum(0.1); mlp.setTrainingTime(4096); mlp.setHiddenLayers("t"); }
From source file:predictforex.ANN.java
static void TenFoldTrain_aNN() throws Exception { eval = new Evaluation(dataset); MultilayerPerceptron tree = new MultilayerPerceptron(); eval.crossValidateModel(tree, dataset, 10, new Random(1)); System.out.println(eval.toSummaryString("Results ANN tenfold \n", false)); // System.out.println(eval.toClassDetailsString()); // System.out.println(eval.fMeasure(1) + " "+eval.precision(1)+" "+eval.recall(1)); // System.out.println(eval.toMatrixString()); }
From source file:predictforex.ANN.java
static void FullTraining_aNN() throws Exception { Classifier cls = new MultilayerPerceptron(); cls.buildClassifier(dataset);// ww w .j a v a 2 s . c om eval = new Evaluation(dataset); eval.evaluateModel(cls, dataset); System.out.println(eval.toSummaryString("Results ANN full training \n", false)); System.out.println(eval.toClassDetailsString()); System.out.println(eval.fMeasure(1) + " " + eval.precision(1) + " " + eval.recall(1)); System.out.println(eval.toMatrixString()); }
From source file:predictor.Predictor.java
public static void multilayerPerceptron() throws Exception { DataSource train = new DataSource(configuration.getWorkspace() + "train_common.arff"); DataSource test = new DataSource(configuration.getWorkspace() + "test_common.arff"); Instances trainInstances = train.getDataSet(); Instances testInstances = test.getDataSet(); //last attribute classify trainInstances.setClassIndex(trainInstances.numAttributes() - 1); testInstances.setClassIndex(testInstances.numAttributes() - 1); // /*from ww w.j av a 2s. c o m*/ // Classifier cModel = (Classifier)new MultilayerPerceptron(); // cModel.buildClassifier(trainInstances); // // weka.core.SerializationHelper.write("/some/where/nBayes.model", cModel); // // Classifier cls = (Classifier) weka.core.SerializationHelper.read("/some/where/nBayes.model"); // // // Test the model // Evaluation eTest = new Evaluation(trainInstances); // eTest.evaluateModel(cls, testInstances); MultilayerPerceptron mlp = new MultilayerPerceptron(); mlp.buildClassifier(trainInstances); mlp.setHiddenLayers(configuration.getHiddenLayers()); mlp.setLearningRate(configuration.getLearningRate()); mlp.setTrainingTime(configuration.getEpocs()); mlp.setMomentum(configuration.getMomentum()); // train classifier Classifier cls = new MultilayerPerceptron(); cls.buildClassifier(trainInstances); // evaluate classifier and print some statistics Evaluation eval = new Evaluation(trainInstances); eval.evaluateModel(cls, testInstances); System.out.println(eval.toSummaryString()); }