Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Rapid - Apache Mahout Clustering designs

You're reading from  Rapid - Apache Mahout Clustering designs

Product type Book
Published in Oct 2015
Publisher
ISBN-13 9781783284436
Pages 130 pages
Edition 1st Edition
Languages

Working with CSV files


Generally, a problem that arises while using Mahout algorithms is how to use files that are in CSV, TSV, or in a similar format. So, here, again, the main challenge is to convert the files into vector format. Once done, the rest of the process is the same as defined previously. Let's look at the code that takes a CSV file and writes the vector format that is usable by Mahout:

public String getSeqFile(String inputLocation) throws Exception {
  String outputPath="<output path>"; //Location where you want to save the output
  FileSystem fs = null;
  SequenceFile.Writer writer;
  fs = FileSystem.get(getConfiguration());
  Path vecoutput =new Path(outputPath);
  writer = new SequenceFile.Writer(fs, getConfiguration(), vecoutput, Text.class, VectorWritable.class);
  VectorWritable vec = new VectorWritable();
    try {
//File reader takes input location as an input.
      FileReader fr = new FileReader(inputLocation);
      BufferedReader br = new BufferedReader(fr)...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}