Skip to content

Instantly share code, notes, and snippets.

@pferrel
Created September 12, 2014 16:28
Show Gist options
  • Save pferrel/9cfee8b5723bb2e2a22c to your computer and use it in GitHub Desktop.
Save pferrel/9cfee8b5723bb2e2a22c to your computer and use it in GitHub Desktop.

Revisions

  1. Pat Ferrel created this gist Sep 12, 2014.
    34 changes: 34 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    package org.apache.mahout.examples

    import org.apache.mahout.drivers._
    import org.apache.mahout.math.cf.SimilarityAnalysis

    object RecommenderDriver extends MahoutDriver {
    /**
    * @param args Command line args, if empty a help message is printed.
    */
    override def main(args: Array[String]): Unit = {
    process
    }

    override def process: Unit = {
    start("local", "spark-recommender")


    // Read user / item data
    val readSchema = new DefaultElementReadSchema()
    val reader = new TextDelimitedIndexedDatasetReader(readSchema)
    val indexedDatasetA = reader.readElementsFrom("data/article_views.txt")

    // Run cooccurrence analysis
    val cooccurrences = SimilarityAnalysis.cooccurrences(indexedDatasetA.matrix, 0xdeadbeef, Int.MaxValue, Int.MaxValue)
    val indicatorDataset = IndexedDataset(cooccurrences(0), indexedDatasetA.columnIDs, indexedDatasetA.columnIDs)

    // Print results
    val writeSchema = new DefaultDRMWriteSchema()
    val writer = new TextDelimitedIndexedDatasetWriter(writeSchema)
    writer.writeTo(indicatorDataset, "data/indicators")

    stop
    }
    }