<jupyter_start><jupyter_text>以上数据导入完成 ————————————————————————————————————<jupyter_code>train_day=product_quantity.groupby(['product_id','product_date']).sum()['ciiquantity'].unstack()#.mean(axis=1)
train_day.head()
train_day.sum().plot(figsize=(15,6))
for i in range(2):
    train_day[train_day.index==i+1].sum().plot(figsize=(15,6))
product_quantity['product_month']=product_quantity['product_date'].apply(lambda x: x[0:7])
train_month=product_quantity.groupby(['product_id','product_month']).sum()['ciiquantity'].unstack()
train_month.ix[:,0:12]
train_month.sum().plot(figsize=(15,6))
for i in range(1):
    train_month[train_month.index==i+1].sum().plot(figsize=(15,6))

def produce2015(index):
    product_id=evaluation['product_id'][index]
    product_month=evaluation['product_month'][index]    
    try:  
        return train_month['2015-'+product_month[5:7]][product_id]*1.1
    except Exception as err:    
        return 0
evaluation.ciiquantity_month=evaluation.index.map(produce2015)
def produce2014(index):
    product_id=evaluation['product_id'][index]
    product_month=evaluation['product_month'][index]    
    try:  
        return train_month['2014-'+product_month[5:7]][product_id]*1.2
    except Exception as err:    
        return 0
evaluation[0:4000].ciiquantity_month=evaluation[0:4000].index.map(produce2014)
evaluation.to_csv('my_ansower.csv',index=False)
evaluation.head()
evaluation<jupyter_output><empty_output><jupyter_text>以上通过月份简单预测 ————————————————————————————————————<jupyter_code>#train_day=product_quantity
train_day=pd.DataFrame({'product_id':product_quantity.product_id,'ciiquantity':product_quantity.ciiquantity,'product_date':product_quantity.product_date,})
train_day=train_day.sort_values(by =['product_id','product_date'])
train_day[0:10]
for i in range(2):
    train_day[train_day['product_id']==i+1].plot(x='product_date', y='ciiquantity',figsize=(15,6))
Ttrain_day=train_day[0:5]
Ttrain_day
from datetime import datetime
pd.options.mode.chained_assignment = None #禁止SettingWithCopyWarning 警告
Ttrain_day=train_day[0:5]
def getweek(product_date):
    yyyy=int(product_date[0:4])
    mm=int(product_date[5:7])
    dd=int(product_date[8:10])
    return datetime(yyyy,mm,dd).weekday()+1

def addweekday(table):
    table['week']=table['product_date'].apply(getweek)
    dummies = pd.get_dummies(Ttrain_day['week'], prefix='week', drop_first=False)
    table = pd.concat([Ttrain_day, dummies], axis=1)
    table = table.drop('week', axis=1)
    return table
Ttrain_day=addweekday(Ttrain_day)
Ttrain_day
Ttrain_day=train_day[0:5]
Ttrain_day=addweekday(Ttrain_day)
def addfeature(table,features):
    for feature in features:
        table[feature]=table['product_id'].apply(lambda x: product_info[product_info.product_id==x][feature])
    table=table.drop('product_id', 1)
    return table
features=['eval','eval2','eval3','eval4','voters','maxstock']
Ttrain_day=addfeature(Ttrain_day,features)
Ttrain_day
Ttrain_day=train_day[0:5]
Ttrain_day=addweekday(Ttrain_day)
Ttrain_day=addfeature(Ttrain_day,features)
def Scalingfeature(table,features):
    for feature in features:
        mean, std = product_info[feature].mean(), product_info[feature].std()
        table.loc[:, feature] = (table[feature] - mean)/std
    return table
features=['eval','eval2','eval3','eval4','voters','maxstock']
Ttrain_day=Scalingfeature(Ttrain_day,features)
Ttrain_day
features=['eval','eval2','eval3','eval4','voters','maxstock']
Ttrain_day=train_day[0:500]
Ttrain_day=addweekday(Ttrain_day)
Ttrain_day=addfeature(Ttrain_day,features)
Ttrain_day=Scalingfeature(Ttrain_day,features)
Ttrain_day.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17332968236582694, 'fraction_numerical': 0.029025191675794086, 'mean_word_length': 8.488311688311688, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '491047', 'license': 'MIT', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1330, 'n_words': 144, 'path': 'ctrip.ipynb', 'repo_name': 'zchq88/kesci_ctrip', 'size': '3652'}