Mahout in Clojure

316 views
Skip to first unread message

klathrop

unread,
May 5, 2010, 8:40:16 AM5/5/10
to Clojure
I'm working through "Mahout in Action", but using Clojure instead of
Java,, and I'm having trouble using an interface in the Mahout
library. The example is as follows:

DataModel model = new FileDataModel(new File("intro.csv"));
RecommenderEvaluator evaluator =
new AverageAbsoluteDifferenceRecommenderEvaluator();
RecommenderBuilder builder = new RecommenderBuilder() {
@Override
public Recommender buildRecommender(DataModel model)
throws TasteException {
UserSimilarity similarity = new
PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(2, similarity, model);
return
new GenericUserBasedRecommender(model, neighborhood,
similarity);
}
}:
double score = evaluator.evaluate( builder, null, model, 0.7, 1.0);
System.out.println(score);

Its the RecommenderBuilder that's giving me trouble. I've tried using
proxy with no luck. Any suggestions?

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Krukow

unread,
May 6, 2010, 12:23:31 AM5/6/10
to Clojure
On May 5, 2:40 pm, klathrop <gamingscien...@gmail.com> wrote:
[snip]
> Its the RecommenderBuilder that's giving me trouble.  I've tried using
> proxy with no luck.  Any suggestions?

Can you post the code that fails?

/Karl

ataggart

unread,
May 6, 2010, 1:05:32 AM5/6/10
to Clojure
Wow! What hoops one has to jump through to fit things in an "OO" API,
eh?

Anyway, if you're using 1.2:

(reify RecommenderBuilder
(buildRecommender [this model]
(let [similarity (PearsonCorrelationSimilarity. model)
neighborhood (NearestNUserNeighborhood. 2 similarity
model)]
(GenericUserBasedRecommender. model neighborhood similarity))))

Or if the "model" used everywhere is the same, you can skip some
stuff:

(let [model (FileDataModel. (File. "intro.csv"))
similarity (PearsonCorrelationSimilarity. model)
neighborhood (NearestNUserNeighborhood 2 similarity model)
recommender (GenericUserBasedRecommender model neighborhood
similarity)
builder (reify RecommenderBuilder (buildRecommender [_ _]
recommender))
evaluator (AverageAbsoluteDifferenceRecommenderEvaluator.)]
(.evaluate evaluator nil model 0.7 1.0))

klathrop

unread,
May 6, 2010, 1:21:16 PM5/6/10
to Clojure
Hoops indeed! Thank you, the solution works great.
Reply all
Reply to author
Forward
0 new messages