Code example with logistic regression

Any machine learning algorithm in Mahout requires a few steps.

For classification, the steps are as follows:

  1. Read the file, line by line.
  2. Encode the features into vectors by splitting the line on the delimiters.
  3. If running the MapReduce implementation, convert the vector to the sequence file.
  4. Train the model by passing the vector and target variable.
  5. Test the model.

Import the code folder, which comes with the book into Eclipse or your favorite editor. Go to the package chapter4.src.logistic and open the file OnlineLogisticRegressionTrain.java.

Train the model

Here, we are reading the file:

String inputFile = "data/chapter4/train_data/input_bank_data.csv";
String outputFile = "data/chapter4/logistic/model";

We create ...

Get Learning Apache Mahout now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.