Skip to content

Instantly share code, notes, and snippets.

@pferrel
Created September 12, 2014 16:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pferrel/9cfee8b5723bb2e2a22c to your computer and use it in GitHub Desktop.
Save pferrel/9cfee8b5723bb2e2a22c to your computer and use it in GitHub Desktop.
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
}
}
@ChiouBen
Copy link

ChiouBen commented Jul 7, 2015

Can you give a sample about article_views.txt?

@srinijapotluri
Copy link

Can you please tell me what dependencies we need. I have tried multiple options but couldn't find cf.SimilarityAnalysis class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment