Example usage for org.apache.mahout.classifier.sgd OnlineLogisticRegression OnlineLogisticRegression

List of usage examples for org.apache.mahout.classifier.sgd OnlineLogisticRegression OnlineLogisticRegression

Introduction

In this page you can find the example usage for org.apache.mahout.classifier.sgd OnlineLogisticRegression OnlineLogisticRegression.

Prototype

public OnlineLogisticRegression() 

Source Link

Usage

From source file:chapter4.src.logistic.LogisticModelParametersPredict.java

License:Apache License

public void readFields(DataInput in) throws IOException {
    targetVariable = in.readUTF();//from ww w  .  j av a 2 s . c om
    int typeMapSize = in.readInt();
    typeMap = Maps.newHashMapWithExpectedSize(typeMapSize);
    for (int i = 0; i < typeMapSize; i++) {
        String key = in.readUTF();
        String value = in.readUTF();
        typeMap.put(key, value);
    }
    numFeatures = in.readInt();
    useBias = in.readBoolean();
    maxTargetCategories = in.readInt();
    int targetCategoriesSize = in.readInt();
    targetCategories = Lists.newArrayListWithCapacity(targetCategoriesSize);
    for (int i = 0; i < targetCategoriesSize; i++) {
        targetCategories.add(in.readUTF());
    }
    lambda = in.readDouble();
    learningRate = in.readDouble();
    csv = null;
    lr = new OnlineLogisticRegression();
    lr.readFields(in);
}

From source file:com.ml.ira.algos.LogisticModelParameters.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    fieldNames = in.readUTF();/*from w  w w.  ja  va 2s .com*/
    targetVariable = in.readUTF();
    int typeMapSize = in.readInt();
    typeMap = Maps.newHashMapWithExpectedSize(typeMapSize);
    for (int i = 0; i < typeMapSize; i++) {
        String key = in.readUTF();
        String value = in.readUTF();
        typeMap.put(key, value);
    }
    numFeatures = in.readInt();
    useBias = in.readBoolean();
    maxTargetCategories = in.readInt();
    int targetCategoriesSize = in.readInt();
    targetCategories = Lists.newArrayListWithCapacity(targetCategoriesSize);
    for (int i = 0; i < targetCategoriesSize; i++) {
        targetCategories.add(in.readUTF());
    }
    lambda = in.readDouble();
    learningRate = in.readDouble();
    csv = null;
    lr = new OnlineLogisticRegression();
    lr.readFields(in);
}

From source file:com.sixgroup.samplerecommender.Point.java

public static void main(String[] args) {

    Map<Point, Integer> points = new HashMap<Point, Integer>();

    points.put(new Point(0, 0), 0);
    points.put(new Point(1, 1), 0);
    points.put(new Point(1, 0), 0);
    points.put(new Point(0, 1), 0);
    points.put(new Point(2, 2), 0);

    points.put(new Point(8, 8), 1);
    points.put(new Point(8, 9), 1);
    points.put(new Point(9, 8), 1);
    points.put(new Point(9, 9), 1);

    OnlineLogisticRegression learningAlgo = new OnlineLogisticRegression();
    learningAlgo = new OnlineLogisticRegression(2, 3, new L1());
    learningAlgo.lambda(0.1);// ww w  .jav  a  2s.c  o m
    learningAlgo.learningRate(10);

    System.out.println("training model  \n");

    for (Point point : points.keySet()) {

        Vector v = getVector(point);
        System.out.println(point + " belongs to " + points.get(point));
        learningAlgo.train(points.get(point), v);
    }

    learningAlgo.close();

    Vector v = new RandomAccessSparseVector(3);
    v.set(0, 0.5);
    v.set(1, 0.5);
    v.set(2, 1);

    Vector r = learningAlgo.classifyFull(v);
    System.out.println(r);

    System.out.println("ans = ");
    System.out.println("no of categories = " + learningAlgo.numCategories());
    System.out.println("no of features = " + learningAlgo.numFeatures());
    System.out.println("Probability of cluster 0 = " + r.get(0));
    System.out.println("Probability of cluster 1 = " + r.get(1));

}

From source file:edu.isi.karma.cleaning.features.LogisticModelParameters.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    targetVariable = in.readUTF();/*  w  w w  .j  av a2 s .co m*/
    int typeMapSize = in.readInt();
    typeMap = Maps.newHashMapWithExpectedSize(typeMapSize);
    for (int i = 0; i < typeMapSize; i++) {
        String key = in.readUTF();
        String value = in.readUTF();
        typeMap.put(key, value);
    }
    numFeatures = in.readInt();
    useBias = in.readBoolean();
    maxTargetCategories = in.readInt();
    int targetCategoriesSize = in.readInt();
    targetCategories = Lists.newArrayListWithCapacity(targetCategoriesSize);
    for (int i = 0; i < targetCategoriesSize; i++) {
        targetCategories.add(in.readUTF());
    }
    lambda = in.readDouble();
    learningRate = in.readDouble();
    csv = null;
    lr = new OnlineLogisticRegression();
    lr.readFields(in);
}