(T)
T = 0
    folder = 'trainT-0'
T = 0
    folder = 'trainT-0'
T = 0 folder = trainT - 0
def make(T):
    """
    T = 0
    folder = 'trainT-0'
    """
    if T==-1:
        folder = 'test'
    else:
        folder = 'trainT-'+str(T)
    
    log_ = log[log.order_number_rev>T]
    log_['user_max_onb'] = log_.groupby('user_id').order_number.transform(np.max)
    log_ = log_.groupby(['user_id', 'product_id']).head(2)
    
    item_cnt    = defaultdict(int)
    item_chance = defaultdict(int)
    pid_bk = uid_bk = onb_bk = None
    
    for uid, pid, onb, max_onb in log_[['user_id', 'product_id', 'order_number', 'user_max_onb']].values:
        
        if uid==uid_bk and pid==pid_bk and (onb-onb_bk==1):
            item_cnt[pid] +=1
        if onb!=max_onb:
            item_chance[pid] +=1
    
        pid_bk = pid
        uid_bk = uid
        onb_bk = onb
    
    item_cnt = pd.DataFrame.from_dict(item_cnt, orient='index').reset_index()
    item_cnt.columns = ['product_id', 'item_first_cnt']
    item_chance = pd.DataFrame.from_dict(item_chance, orient='index').reset_index()
    item_chance.columns = ['product_id', 'item_first_chance']
    
    df = pd.merge(item_cnt, item_chance, on='product_id', how='outer').fillna(0)
    df['item_first_ratio'] = df.item_first_cnt/df.item_first_chance
    
    df.to_pickle('../feature/{}/f214_product.p'.format(folder))
def make ( T ) : if T == - 1 : folder = 'test' else : folder = 'trainT-' + str ( T ) log_ = log [ log . order_number_rev > T ] log_ [ 'user_max_onb' ] = log_ . groupby ( 'user_id' ) . order_number . transform ( np . max ) log_ = log_ . groupby ( [ 'user_id' , 'product_id' ] ) . head ( 2 ) item_cnt = defaultdict ( int ) item_chance = defaultdict ( int ) pid_bk = uid_bk = onb_bk = None for uid , pid , onb , max_onb in log_ [ [ 'user_id' , 'product_id' , 'order_number' , 'user_max_onb' ] ] . values : if uid == uid_bk and pid == pid_bk and ( onb - onb_bk == 1 ) : item_cnt [ pid ] += 1 if onb != max_onb : item_chance [ pid ] += 1 pid_bk = pid uid_bk = uid onb_bk = onb item_cnt = pd . DataFrame . from_dict ( item_cnt , orient = 'index' ) . reset_index ( ) item_cnt . columns = [ 'product_id' , 'item_first_cnt' ] item_chance = pd . DataFrame . from_dict ( item_chance , orient = 'index' ) . reset_index ( ) item_chance . columns = [ 'product_id' , 'item_first_chance' ] df = pd . merge ( item_cnt , item_chance , on = 'product_id' , how = 'outer' ) . fillna ( 0 ) df [ 'item_first_ratio' ] = df . item_first_cnt / df . item_first_chance df . to_pickle ( '../feature/{}/f214_product.p' . format ( folder ) )