Search in sources :

Example 1 with ConjugateGradientDescent

use of edu.neu.ccs.pyramid.optimization.ConjugateGradientDescent in project pyramid by cheng-li.

the class LogisticRegressionTest method test2.

private static void test2() throws Exception {
    ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/train.trec"), DataSetType.CLF_SPARSE, true);
    ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/test.trec"), DataSetType.CLF_SPARSE, true);
    System.out.println(dataSet.getMetaInfo());
    LogisticRegression logisticRegression = new LogisticRegression(dataSet.getNumClasses(), dataSet.getNumFeatures());
    LogisticLoss function = new LogisticLoss(logisticRegression, dataSet, 0.1, true);
    ConjugateGradientDescent conjugateGradientDescent = new ConjugateGradientDescent(function);
    conjugateGradientDescent.getLineSearcher().setInitialStepLength(0.01);
    conjugateGradientDescent.optimize();
    System.out.println("train: " + Accuracy.accuracy(logisticRegression, dataSet));
    System.out.println("test: " + Accuracy.accuracy(logisticRegression, testSet));
}
Also used : ClfDataSet(edu.neu.ccs.pyramid.dataset.ClfDataSet) ConjugateGradientDescent(edu.neu.ccs.pyramid.optimization.ConjugateGradientDescent) File(java.io.File)

Aggregations

ClfDataSet (edu.neu.ccs.pyramid.dataset.ClfDataSet)1 ConjugateGradientDescent (edu.neu.ccs.pyramid.optimization.ConjugateGradientDescent)1 File (java.io.File)1