O'Reilly logo

Learning Apache Mahout by Chandramani Tiwary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required