@@ -0,0 +1,3353 @@
+package edu.neu.ccs.pyramid.experiment;%0A%0Aimport edu.neu.ccs.pyramid.classification.logistic_regression.ElasticNetLogisticTrainer;%0Aimport edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression;%0Aimport edu.neu.ccs.pyramid.dataset.ClfDataSet;%0Aimport edu.neu.ccs.pyramid.dataset.ClfDataSetBuilder;%0Aimport edu.neu.ccs.pyramid.eval.Accuracy;%0Aimport org.apache.mahout.math.DenseVector;%0Aimport org.apache.mahout.math.Vector;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Created by chengli on 4/15/15.%0A */%0Apublic class Exp82 %7B%0A    public static void main(String%5B%5D args) %7B%0A        test1();%0A%0A%0A    %7D%0A%0A    // standard ngram%0A    private static void test1()%7B%0A        String pos = %22I recommend it%22;%0A        String neg = %22I do not recommend it%22;%0A%0A        String feature0 = %22recommend%22;%0A        String feature1 = %22not recommend%22;%0A%0A        ClfDataSet dataSet = ClfDataSetBuilder.getBuilder()%0A                .numDataPoints(2).numFeatures(2).numClasses(2)%0A                .build();%0A        dataSet.setFeatureValue(0,0,1);%0A        dataSet.setFeatureValue(1,0,1);%0A        dataSet.setFeatureValue(1,1,1);%0A        dataSet.setLabel(0,1);%0A        dataSet.setLabel(1,0);%0A        LogisticRegression logisticRegression = new LogisticRegression(2,2);%0A        ElasticNetLogisticTrainer trainer = ElasticNetLogisticTrainer.newBuilder(logisticRegression,dataSet)%0A                .setRegularization(1.0E-2).setL1Ratio(0).build();%0A        trainer.train();%0A        System.out.println(logisticRegression.getWeights().getBiasForClass(0));%0A        System.out.println(logisticRegression.getWeights().getBiasForClass(1));%0A        System.out.println(logisticRegression.getWeights().getWeightsWithoutBiasForClass(0));%0A        System.out.println(logisticRegression.getWeights().getWeightsWithoutBiasForClass(1));%0A        Vector vector = new DenseVector(2);%0A        System.out.println(Arrays.toString(logisticRegression.predictClassProbs(vector)));%0A        System.out.println(Accuracy.accuracy(logisticRegression,dataSet));%0A    %7D%0A%0A%0A    // maximal ngram%0A    private static void test2()%7B%0A        String pos = %22I recommend it%22;%0A        String neg = %22I do not recommend it%22;%0A%0A        String feature0 = %22recommend%22;%0A        String feature1 = %22not recommend%22;%0A%0A        ClfDataSet dataSet = ClfDataSetBuilder.getBuilder()%0A                .numDataPoints(2).numFeatures(2).numClasses(2)%0A                .build();%0A        dataSet.setFeatureValue(0,0,1);%0A        dataSet.setFeatureValue(1,1,1);%0A        dataSet.setLabel(0,1);%0A        dataSet.setLabel(1,0);%0A        LogisticRegression logisticRegression = new LogisticRegression(2,2);%0A        ElasticNetLogisticTrainer trainer = ElasticNetLogisticTrainer.newBuilder(logisticRegression,dataSet)%0A                .setRegularization(1.0E-2).setL1Ratio(0).build();%0A        trainer.train();%0A        System.out.println(logisticRegression.getWeights().getBiasForClass(0));%0A        System.out.println(logisticRegression.getWeights().getBiasForClass(1));%0A        System.out.println(logisticRegression.getWeights().getWeightsWithoutBiasForClass(0));%0A        System.out.println(logisticRegression.getWeights().getWeightsWithoutBiasForClass(1));%0A        Vector vector = new DenseVector(2);%0A        System.out.println(Arrays.toString(logisticRegression.predictClassProbs(vector)));%0A        System.out.println(Accuracy.accuracy(logisticRegression,dataSet));%0A    %7D%0A%0A%7D%0A

add Exp82