Last active
August 29, 2015 14:02
-
-
Save vtomiris/dadf7d48afba91ce8ae3 to your computer and use it in GitHub Desktop.
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
import org.grouplens.lenskit.knn.item.* | |
import org.grouplens.lenskit.baseline.* | |
import org.grouplens.lenskit.transform.normalize.* | |
import org.grouplens.lenskit.eval.metrics.topn.*; | |
import org.grouplens.lenskit.ItemScorer | |
import org.grouplens.lenskit.baseline.ItemMeanRatingItemScorer | |
import org.grouplens.lenskit.core.Transient | |
import org.grouplens.lenskit.data.dao.EventDAO | |
import org.grouplens.lenskit.data.dao.UserDAO | |
import org.grouplens.lenskit.eval.data.traintest.QueryData | |
import org.grouplens.lenskit.eval.metrics.predict.* | |
import org.grouplens.lenskit.external.ExternalProcessItemScorerBuilder | |
import javax.inject.Inject | |
import javax.inject.Provider | |
/** | |
* Shim class to run item-mean.py to build an ItemScorer. | |
*/ | |
class ExternalItemMeanScorerBuilder implements Provider<ItemScorer>{ | |
EventDAO eventDAO | |
UserDAO userDAO | |
@Inject | |
public ExternalItemMeanScorerBuilder(@Transient EventDAO events, | |
@Transient @QueryData UserDAO users) { | |
eventDAO = events | |
userDAO = users | |
} | |
@Override | |
ItemScorer get() { | |
def wrk = new File("external-scratch") | |
wrk.mkdirs() | |
def builder = new ExternalProcessItemScorerBuilder() | |
// Note: don't use file names because it will interact badly with crossfolding | |
return builder.setWorkingDir(wrk) | |
.setExecutable("python") //can be "R", "matlab", "ruby" etc | |
.addArgument("../item_mean.py") //relative (or absolute) location of sample recommender | |
.addArgument("--for-users") | |
.addRatingFileArgument(eventDAO) | |
.addUserFileArgument(userDAO) | |
.build() | |
} | |
} | |
trainTest { | |
dataset crossfold("ml-100k") { | |
source csvfile("ml-100k/u.data") { //relative (or absolute) path to the dataset | |
delimiter "\t" | |
domain { | |
minimum 1.0 | |
maximum 5.0 | |
precision 1.0 | |
} | |
} | |
} | |
algorithm("PersMean") { | |
bind ItemScorer to UserMeanItemScorer | |
bind (UserMeanBaseline, ItemScorer) to ItemMeanRatingItemScorer | |
} | |
algorithm("ExternalAlgorithm") { | |
bind ItemScorer toProvider ExternalItemMeanScorerBuilder | |
} | |
metric RMSEPredictMetric | |
metric topNnDCG { | |
listSize 10 | |
candidates ItemSelectors.allItems() | |
exclude ItemSelectors.trainingItems() | |
} | |
output "eval-results.csv" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment