Exemplo n.º 1
0
    def __init__( self, k, sample_size=5000, sampling='recent', remind=True, extend=False, similarity='cosine', lambda_spw=1.02, lambda_snh=5, lambda_inh=2.05, lambda_ipw=1.02, lambda_idf=5,
                  extend_session_length=None, extending_mode='lastViewed', refine_mode=True, boost_own_sessions=None,
                  reminders=False, remind_strategy='recency', remind_sessions_num=6, reminders_num=3, remind_mode='end', weight_base=1, weight_IRec=0, weight_SSim=0,
                  session_key = 'SessionId', item_key= 'ItemId', time_key= 'Time', user_key='UserId'):
       
        self.k = k
        self.sample_size = sample_size
        self.sampling = sampling
        
        self.similarity = similarity
        
        self.lambda_spw = lambda_spw
        self.lambda_snh = lambda_snh * 24 * 3600 #in days
        self.lambda_inh = lambda_inh
        
        self.lambda_ipw = lambda_ipw
        self.lambda_idf = lambda_idf
        
        self.session_key = session_key
        self.item_key = item_key
        self.time_key = time_key
        self.user_key = user_key  # user_based

        self.extend = extend
        self.extending_mode = extending_mode
        self.remind = remind

        # user_based
        self.extend_session_length = extend_session_length
        self.refine_mode = refine_mode
        self.boost_own_sessions = boost_own_sessions

        #updated while recommending
        self.session = -1
        self.session_items = []
        self.relevant_sessions = set()
        # user_based
        self.items_previous = []
        self.last_user_items = {}  # to extend the session model
        self.recent_user_items = {}  # to remind
        self.recent_user_sessions = {}  # to remind
        self.user_item_intensity = dict()  # to remind (for 'session_similarity')
        # reminders
        self.hasReminders = reminders
        if self.hasReminders:
            if remind_strategy == 'hybrid':
                self.reminder = Reminder(remind_strategy=remind_strategy, remind_sessions_num=remind_sessions_num,
                                         weight_base=weight_base, weight_IRec=weight_IRec, weight_SSim=weight_SSim)
            else:  # basic reminders
                self.reminder = Reminder(remind_strategy=remind_strategy, remind_sessions_num=remind_sessions_num,
                                         reminders_num=reminders_num, remind_mode=remind_mode)

        # cache relations once at startup
        self.session_item_map = dict() 
        self.item_session_map = dict()
        self.session_time = dict()
        self.min_time = -1
        self.session_user_map = dict()  # user_based
        
        self.sim_time = 0
Exemplo n.º 2
0
    def __init__(self,
                 factors=100,
                 hidden_units=100,
                 epochs=30,
                 lr=0.001,
                 extend_session_length=None,
                 reminders=False,
                 remind_strategy='recency',
                 remind_sessions_num=6,
                 reminders_num=3,
                 remind_mode='end',
                 weight_base=1,
                 weight_IRec=0,
                 session_key='SessionId',
                 item_key='ItemId',
                 time_key='Time',
                 user_key='UserId'):
        self.factors = factors
        self.hidden_units = hidden_units
        self.factors = factors
        self.epochs = epochs
        self.lr = lr

        self.session_key = session_key
        self.item_key = item_key

        self.session = -1
        self.session_items = list()

        self.floatX = theano.config.floatX

        # user_based
        self.time_key = time_key
        self.user_key = user_key
        self.extend_session_length = extend_session_length
        self.last_user_items = {}
        self.recent_user_items = {}
        self.recent_user_sessions = {}
        self.hasReminders = reminders
        self.hasReminders = reminders
        if self.hasReminders:
            if remind_strategy == 'hybrid':
                self.reminder = Reminder(
                    remind_strategy=remind_strategy,
                    remind_sessions_num=remind_sessions_num,
                    weight_base=weight_base,
                    weight_IRec=weight_IRec)
            else:  # basic reminders
                self.reminder = Reminder(
                    remind_strategy=remind_strategy,
                    remind_sessions_num=remind_sessions_num,
                    reminders_num=reminders_num,
                    remind_mode=remind_mode)
Exemplo n.º 3
0
    def __init__(self,
                 steps=10,
                 weighting='div',
                 pruning=20,
                 last_n_days=None,
                 idf_weight=False,
                 last_in_session=False,
                 session_weighting='div',
                 boost_own_sessions=None,
                 reminders=False,
                 remind_strategy='recency',
                 remind_sessions_num=6,
                 reminders_num=3,
                 remind_mode='end',
                 weight_base=1,
                 weight_IRec=0,
                 session_key='SessionId',
                 item_key='ItemId',
                 time_key='Time',
                 user_key='UserId'):
        self.steps = steps
        self.pruning = pruning
        self.weighting = weighting
        self.session_weighting = session_weighting
        self.last_n_days = last_n_days
        self.idf_weight = idf_weight
        self.last_in_session = last_in_session
        self.session_key = session_key
        self.item_key = item_key
        self.time_key = time_key
        self.session = -1
        self.session_items = []
        # user_based
        self.user_key = user_key
        self.boost_own_sessions = boost_own_sessions

        self.hasReminders = reminders
        if self.hasReminders:
            if remind_strategy == 'hybrid':
                self.reminder = Reminder(
                    remind_strategy=remind_strategy,
                    remind_sessions_num=remind_sessions_num,
                    weight_base=weight_base,
                    weight_IRec=weight_IRec)
            else:  # basic reminders
                self.reminder = Reminder(
                    remind_strategy=remind_strategy,
                    remind_sessions_num=remind_sessions_num,
                    reminders_num=reminders_num,
                    remind_mode=remind_mode)
Exemplo n.º 4
0
    def __init__(self,
                 k,
                 sample_size=1000,
                 sampling='recent',
                 similarity='cosine',
                 weighting='div',
                 dwelling_time=False,
                 last_n_days=None,
                 last_n_clicks=None,
                 weighting_score='div',
                 weighting_time=False,
                 normalize=True,
                 idf_weighting=False,
                 idf_weighting_session=False,
                 remind=True,
                 push_reminders=False,
                 add_reminders=False,
                 extend=False,
                 extending_mode='lastViewed',
                 extend_session_length=None,
                 refine_mode=True,
                 boost_own_sessions=None,
                 past_neighbors=False,
                 reminders=False,
                 remind_strategy='recency',
                 remind_sessions_num=6,
                 reminders_num=3,
                 remind_mode='end',
                 weight_base=1,
                 weight_IRec=0,
                 weight_SSim=0,
                 session_key='SessionId',
                 item_key='ItemId',
                 time_key='Time',
                 user_key='UserId'):

        self.k = k
        self.sample_size = sample_size
        self.sampling = sampling
        self.weighting = weighting
        self.dwelling_time = dwelling_time
        self.weighting_score = weighting_score
        self.weighting_time = weighting_time
        self.similarity = similarity
        self.session_key = session_key
        self.item_key = item_key
        self.time_key = time_key
        self.user_key = user_key  # user_based
        self.idf_weighting = idf_weighting
        self.idf_weighting_session = idf_weighting_session
        self.normalize = normalize
        self.last_n_days = last_n_days
        self.last_n_clicks = last_n_clicks
        self.remind = remind  # True/False. If False: items form the current session will be excluded
        self.push_reminders = push_reminders
        self.add_reminders = add_reminders
        self.extend = extend
        self.extending_mode = extending_mode
        # user_based
        self.extend_session_length = extend_session_length
        self.boost_own_sessions = boost_own_sessions
        self.past_neighbors = past_neighbors
        self.refine_mode = refine_mode
        # reminders
        self.hasReminders = reminders
        if self.hasReminders:
            if remind_strategy == 'hybrid':
                self.reminder = Reminder(
                    remind_strategy=remind_strategy,
                    remind_sessions_num=remind_sessions_num,
                    weight_base=weight_base,
                    weight_IRec=weight_IRec,
                    weight_SSim=weight_SSim)
            else:  # basic reminders
                self.reminder = Reminder(
                    remind_strategy=remind_strategy,
                    remind_sessions_num=remind_sessions_num,
                    reminders_num=reminders_num,
                    remind_mode=remind_mode)

        # updated while recommending
        self.session = -1
        self.session_items = []
        self.relevant_sessions = set()
        # user_based
        self.items_previous = []
        self.last_user_items = {}  # to extend the session model
        self.recent_user_items = {}  # to remind
        self.recent_user_sessions = {}  # to remind
        self.user_item_intensity = dict(
        )  # to remind (for 'session_similarity')

        # cache relations once at startup (in fit)
        self.session_item_map = dict()
        self.item_session_map = dict()
        self.session_time = dict()
        self.min_time = -1
        self.session_user_map = dict()  # user_based

        self.sim_time = 0