(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]

    cnt = log_.groupby(['user_id', 'product_id']).size()
    cnt.name = 'cnt'
    cnt = cnt.reset_index()
    
    # chance
    user_onb_max = log_.groupby('user_id').order_number.max().reset_index()
    user_onb_max.columns = ['user_id', 'onb_max']
    
    user_item_min = log_.groupby(['user_id', 'product_id']).order_number.min().reset_index()
    user_item_min.columns = ['user_id', 'product_id', 'onb_min']
    
    chance = pd.merge(user_item_min, user_onb_max, on='user_id', how='left')
    chance['chance'] = chance.onb_max - chance.onb_min +1
    
    df = pd.merge(cnt, chance, on=['user_id', 'product_id'], how='left')
    
    df['order_ratio_bychance'] = df.cnt / df.chance
    
    col = ['user_id', 'product_id', 'chance', 'order_ratio_bychance']
    df[col].to_pickle('../feature/{}/f309_user-product.p'.format(folder))
    
    # === near5 ===
    log_ = log[log.order_number_rev>T][log.order_number_rev<=(T+5)]

    cnt = log_.groupby(['user_id', 'product_id']).size()
    cnt.name = 'cnt'
    cnt = cnt.reset_index()
    
    # chance
    user_onb_max = log_.groupby('user_id').order_number.max().reset_index()
    user_onb_max.columns = ['user_id', 'onb_max']
    
    user_item_min = log_.groupby(['user_id', 'product_id']).order_number.min().reset_index()
    user_item_min.columns = ['user_id', 'product_id', 'onb_min']
    
    chance = pd.merge(user_item_min, user_onb_max, on='user_id', how='left')
    chance['chance_n5'] = chance.onb_max - chance.onb_min +1
    
    df = pd.merge(cnt, chance, on=['user_id', 'product_id'], how='left')
    
    df['order_ratio_bychance_n5'] = df.cnt / df.chance_n5
    
    col = ['user_id', 'product_id', 'chance_n5', 'order_ratio_bychance_n5']
    df[col].to_pickle('../feature/{}/f309_user-product_n5.p'.format(folder))
def make ( T ) : if T == - 1 : folder = 'test' else : folder = 'trainT-' + str ( T ) log_ = log [ log . order_number_rev > T ] cnt = log_ . groupby ( [ 'user_id' , 'product_id' ] ) . size ( ) cnt . name = 'cnt' cnt = cnt . reset_index ( ) # chance user_onb_max = log_ . groupby ( 'user_id' ) . order_number . max ( ) . reset_index ( ) user_onb_max . columns = [ 'user_id' , 'onb_max' ] user_item_min = log_ . groupby ( [ 'user_id' , 'product_id' ] ) . order_number . min ( ) . reset_index ( ) user_item_min . columns = [ 'user_id' , 'product_id' , 'onb_min' ] chance = pd . merge ( user_item_min , user_onb_max , on = 'user_id' , how = 'left' ) chance [ 'chance' ] = chance . onb_max - chance . onb_min + 1 df = pd . merge ( cnt , chance , on = [ 'user_id' , 'product_id' ] , how = 'left' ) df [ 'order_ratio_bychance' ] = df . cnt / df . chance col = [ 'user_id' , 'product_id' , 'chance' , 'order_ratio_bychance' ] df [ col ] . to_pickle ( '../feature/{}/f309_user-product.p' . format ( folder ) ) # === near5 === log_ = log [ log . order_number_rev > T ] [ log . order_number_rev <= ( T + 5 ) ] cnt = log_ . groupby ( [ 'user_id' , 'product_id' ] ) . size ( ) cnt . name = 'cnt' cnt = cnt . reset_index ( ) # chance user_onb_max = log_ . groupby ( 'user_id' ) . order_number . max ( ) . reset_index ( ) user_onb_max . columns = [ 'user_id' , 'onb_max' ] user_item_min = log_ . groupby ( [ 'user_id' , 'product_id' ] ) . order_number . min ( ) . reset_index ( ) user_item_min . columns = [ 'user_id' , 'product_id' , 'onb_min' ] chance = pd . merge ( user_item_min , user_onb_max , on = 'user_id' , how = 'left' ) chance [ 'chance_n5' ] = chance . onb_max - chance . onb_min + 1 df = pd . merge ( cnt , chance , on = [ 'user_id' , 'product_id' ] , how = 'left' ) df [ 'order_ratio_bychance_n5' ] = df . cnt / df . chance_n5 col = [ 'user_id' , 'product_id' , 'chance_n5' , 'order_ratio_bychance_n5' ] df [ col ] . to_pickle ( '../feature/{}/f309_user-product_n5.p' . format ( folder ) )