def load_rest(): User.load_to_cache() # Load main models Popularity.load_to_cache() TensorCoFi.load_to_cache() if "recommendation.language" in settings.INSTALLED_APPS: from recommendation.language.models import Region Region.load_to_cache() if "recommendation.diversity" in settings.INSTALLED_APPS: from recommendation.diversity.models import ItemGenre, Genre Genre.load_to_cache() ItemGenre.load_to_cache()
def setup_class(cls, *args, **kwargs): """ Put elements in db """ for app in ITEMS: Item.objects.create(**app) for u in USERS: user = User.objects.create(external_id=u["external_id"]) for i in u["items"]: Inventory.objects.create(user=user, item=Item.get_item_by_external_id(i)) TensorCoFi.train_from_db() Popularity.train_from_db() TensorCoFi.load_to_cache() Popularity.load_to_cache()
def test_popularity_score_against_testfm(self): """ [recommendation.models.TensorCoFi] Test popularity scores with test.fm benchmark """ evaluator = Evaluator() training, testing = testfm.split.holdoutByRandom(self.df, 0.9) items = training.item.unique() tc = Popularity(len(items)) ptc = TFMPopularity() tc.fit(training) ptc.fit(training) tc_score = evaluator.evaluate_model(tc, testing, all_items=items)[0] ptc_score = evaluator.evaluate_model(ptc, testing, all_items=items)[0] assert abs(tc_score-ptc_score) < .1, \ "Popularity score is not close enough to testfm benchmark (%.3f != %.3f)" % (tc_score, ptc_score)
def setup_class(cls, *args, **kwargs): """ Put elements in db """ path = resource_filename(recommendation.__name__, "/") fill.FillTool({"items": True, "--mozilla": True, "prod": True}).load() fill.FillTool({"users": True, "--mozilla": True, "<path>": path+"data/user"}).load() modelcrafter.main("train", "popularity") modelcrafter.main("train", "tensorcofi") # Load user and items Item.load_to_cache() User.load_to_cache() # Load main models Popularity.load_to_cache() TensorCoFi.load_to_cache() cls.client = Client()
def get_alternative_recommendation(self, user): """ Return the popular items :return: list """ return Popularity.get_model().recommendation
import os if "DJANGO_SETTINGS_MODULE" not in os.environ: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recommendation.default_settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() from django.conf import settings from recommendation.models import Item, User, TensorCoFi, Popularity # Load user and items Item.load_to_cache() User.load_to_cache() # Load main models Popularity.load_to_cache() TensorCoFi.load_to_cache() if "recommendation.language" in settings.INSTALLED_APPS: from recommendation.language.models import Locale, Region Locale.load_to_cache() Region.load_to_cache() #if "recommendation.simple_logging" in recommendation.settings.INSTALLED_APPS: # print("Loading logs to cache...") # from recommendation.simple_logging.models import LogEntry # LogEntry.load_to_cache() # print("done!")
if "DJANGO_SETTINGS_MODULE" not in os.environ: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recommendation.default_settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() from django.conf import settings from recommendation.models import Item, User, TensorCoFi, Popularity # Load user and items Item.load_to_cache() User.load_to_cache() # Load main models Popularity.load_to_cache() TensorCoFi.load_to_cache() if "recommendation.language" in settings.INSTALLED_APPS: from recommendation.language.models import Locale, Region Locale.load_to_cache() Region.load_to_cache() #if "recommendation.simple_logging" in recommendation.settings.INSTALLED_APPS: # print("Loading logs to cache...") # from recommendation.simple_logging.models import LogEntry # LogEntry.load_to_cache() # print("done!") if "recommendation.diversity" in settings.INSTALLED_APPS: