def test_cross_validation(self): cfg = Config() axi = xapian.Database(cfg.axi) packages = ["gimp","aaphoto","eog","emacs","dia","ferret", "festival","file","inkscape","xpdf"] path = "test_data/.sample_axi" sample_axi = SampleAptXapianIndex(packages,axi,path) rec = Recommender(cfg) rec.items_repository = sample_axi user = User({"gimp":1,"aaphoto":1,"eog":1,"emacs":1}) metrics = [] metrics.append(Precision()) metrics.append(Recall()) metrics.append(F1()) validation = CrossValidation(0.3,5,rec,metrics,0.5) validation.run(user) print validation
from user import RandomPopcon,LocalSystem,PopconSystem if __name__ == '__main__': cfg = Config() rec = Recommender(cfg) #user = LocalSystem() #user = RandomPopcon(cfg.popcon_dir) #user = RandomPopcon(cfg.popcon_dir,os.path.join(cfg.filters_dir,"desktopapps")) user = PopconSystem(os.path.expanduser("~/.app-recommender/popcon-entries/00/0001166d0737c6dffb083071e5ee69f5")) user.filter_pkg_profile(os.path.join(cfg.filters_dir,"desktopapps")) user.maximal_pkg_profile() begin_time = datetime.datetime.now() metrics = [] metrics.append(Precision()) metrics.append(Recall()) metrics.append(F_score(0.5)) metrics.append(Accuracy()) metrics.append(FPR()) validation = CrossValidation(0.9,20,rec,metrics,0.005) validation.run(user) print validation end_time = datetime.datetime.now() delta = end_time - begin_time logging.info("Cross-validation for user %s" % user.user_id) logging.info("Recommender strategy: %s" % rec.strategy.description) logging.debug("Cross-validation started at %s" % begin_time) logging.debug("Cross-validation completed at %s" % end_time) logging.info("Time elapsed: %d seconds." % delta.seconds)