Skip to content

Commit

Permalink
Small additional improvements for AUC
Browse files Browse the repository at this point in the history
  • Loading branch information
srowen committed Nov 18, 2012
1 parent 7218ad9 commit 884fc53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGES.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

<h1>Version 0.9</h1>

<h2>Other</h2>

<ul>
<li>Faster display of self-organizing map visualization for moderate to large data sets.</li>
</ul>

<h1>Version 0.8</h1>

<p>November 16 2012</p>
Expand Down
4 changes: 2 additions & 2 deletions common/src/net/myrrix/common/ByValueAscComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
*
* @author Sean Owen
*/
final class ByValueAscComparator implements Comparator<RecommendedItem> {
public final class ByValueAscComparator implements Comparator<RecommendedItem> {

static final Comparator<RecommendedItem> INSTANCE = new ByValueAscComparator();
public static final Comparator<RecommendedItem> INSTANCE = new ByValueAscComparator();

private ByValueAscComparator() {
}
Expand Down
20 changes: 5 additions & 15 deletions online/src/net/myrrix/online/eval/AUCEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.mahout.cf.taste.common.NoSuchItemException;
import org.apache.mahout.cf.taste.common.NoSuchUserException;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -56,17 +55,19 @@ public EvaluationResult evaluate(MyrrixRecommender recommender,
int underCurve = 0;
int total = 0;

long[] allItemIDs = getAllItemIDs(recommender);
long[] allItemIDs = recommender.getAllItemIDs().toArray();
RandomGenerator random = RandomManager.getRandom();

FastIDSet testItemIDs = new FastIDSet();

for (long userID : testData.keySet()) {

List<RecommendedItem> testValues = Lists.newArrayList(testData.get(userID));
int numTest = testValues.size();
if (numTest == 0) {
continue;
}
FastIDSet testItemIDs = new FastIDSet();
testItemIDs.clear();
for (RecommendedItem testValue : testValues) {
testItemIDs.add(testValue.getItemID());
}
Expand Down Expand Up @@ -98,7 +99,7 @@ public EvaluationResult evaluate(MyrrixRecommender recommender,
total++;
}

if (++count % 10000 == 0) {
if (++count % 100000 == 0) {
log.info("AUC: {}", (double) underCurve / total);
}
}
Expand All @@ -108,15 +109,4 @@ public EvaluationResult evaluate(MyrrixRecommender recommender,
return new EvaluationResultImpl(score);
}

private static long[] getAllItemIDs(MyrrixRecommender recommender) throws TasteException {
FastIDSet allItemIDsSet = recommender.getAllItemIDs();
long[] allItemIDs = new long[allItemIDsSet.size()];
LongPrimitiveIterator it = allItemIDsSet.iterator();
int i = 0;
while (it.hasNext()) {
allItemIDs[i++] = it.nextLong();
}
return allItemIDs;
}

}
17 changes: 6 additions & 11 deletions online/src/net/myrrix/online/eval/AbstractEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

package net.myrrix.online.eval;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

import com.google.common.base.CharMatcher;
import com.google.common.base.Charsets;
Expand All @@ -47,6 +46,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.myrrix.common.ByValueAscComparator;
import net.myrrix.common.io.IOUtils;
import net.myrrix.common.LangUtils;
import net.myrrix.common.MyrrixRecommender;
Expand Down Expand Up @@ -101,7 +101,7 @@ public final EvaluationResult evaluate(File originalDataDir,

File trainingDataDir = Files.createTempDir();
trainingDataDir.deleteOnExit();
File trainingFile = new File(trainingDataDir, "training.csv");
File trainingFile = new File(trainingDataDir, "training.csv.gz");
trainingFile.deleteOnExit();

ServerRecommender recommender = null;
Expand Down Expand Up @@ -132,10 +132,10 @@ private Multimap<Long,RecommendedItem> split(File dataDir,

Multimap<Long,RecommendedItem> testData = ArrayListMultimap.create();
Writer trainingOut =
new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(trainingFile)), Charsets.UTF_8);
new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(trainingFile)), Charsets.UTF_8);
try {

Iterator<Map.Entry<Long, Collection<RecommendedItem>>> it = data.asMap().entrySet().iterator();
Iterator<Map.Entry<Long,Collection<RecommendedItem>>> it = data.asMap().entrySet().iterator();
while (it.hasNext()) {

Map.Entry<Long, Collection<RecommendedItem>> entry = it.next();
Expand All @@ -145,12 +145,7 @@ private Multimap<Long,RecommendedItem> split(File dataDir,

if (isSplitTestByPrefValue()) {
// Sort low to high, leaving high values at end for testing as "relevant" items
Collections.sort(userPrefs, new Comparator<RecommendedItem>() {
@Override
public int compare(RecommendedItem a, RecommendedItem b) {
return a.getValue() < b.getValue() ? -1 : a.getValue() > b.getValue() ? 1 : 0;
}
});
Collections.sort(userPrefs, ByValueAscComparator.INSTANCE);
}
// else leave sorted in time order

Expand Down

0 comments on commit 884fc53

Please sign in to comment.