Created
December 22, 2011 06:42
-
-
Save pmbauer/1509270 to your computer and use it in GitHub Desktop.
Mahout playground buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; :dependencies [[org.apache.mahout/mahout-core "0.5"]] | |
;; :dev-dependencies [[slamhound "1.2.0"]] | |
(ns mia.mahout | |
(:import | |
(java.io File) | |
(org.apache.mahout.cf.taste.eval RecommenderBuilder) | |
(org.apache.mahout.cf.taste.impl.eval | |
AverageAbsoluteDifferenceRecommenderEvaluator | |
GenericRecommenderIRStatsEvaluator) | |
(org.apache.mahout.cf.taste.impl.model.file FileDataModel) | |
(org.apache.mahout.cf.taste.impl.neighborhood | |
NearestNUserNeighborhood) | |
(org.apache.mahout.cf.taste.impl.recommender | |
GenericUserBasedRecommender) | |
(org.apache.mahout.cf.taste.impl.similarity | |
PearsonCorrelationSimilarity))) | |
(def model (FileDataModel. (File. "intro.csv"))) | |
(def builder | |
(reify RecommenderBuilder | |
(buildRecommender [_ model] | |
(let [similarity (PearsonCorrelationSimilarity. model) | |
neighborhood (NearestNUserNeighborhood. 2 similarity model)] | |
(GenericUserBasedRecommender. model neighborhood similarity))))) | |
; Listing 2.2 | |
(doseq [recommendation (.recommend (.buildRecommender builder model) 1 1)] | |
(println (str recommendation))) | |
; Listing 2.3 | |
(def evaluator (AverageAbsoluteDifferenceRecommenderEvaluator.)) | |
(.evaluate evaluator builder nil model 0.7 1.0) | |
; Listing 2.4.1 | |
(def evaluator (GenericRecommenderIRStatsEvaluator.)) | |
(def stats (.evaluate evaluator builder nil model nil 2 GenericRecommenderIRStatsEvaluator/CHOOSE_THRESHOLD 1.0)) | |
(println (.getPrecision stats)) | |
(println (.getRecall stats)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment