In [2]:
import os
import math
import pandas as pd
import numpy as np
from scipy import stats
# print stats.hmean([ -50.2 , 100.5 ])
In [52]:
path = '/home/zongyi/bimbo_data/submission/'
for f in os.listdir(path):
print f
In [69]:
df1 = pd.read_csv(path+'w9_n1000_45133.csv')
df2 = pd.read_csv(path+'w9_f25_n1500_c0.5_46191.csv')
df3 = pd.read_csv(path+'w9_full1200_47233.csv')
df4 = pd.read_csv(path+'w9_f14_2n1000_c0.7_mean_4539.csv')
df5 = pd.read_csv(path+'w9_f14_3xn500_c0.7_mean_45482.csv')
In [70]:
df1.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd1'}, inplace=True)
df2.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd2'}, inplace=True)
df3.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd3'}, inplace=True)
df4.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd4'}, inplace=True)
df5.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd5'}, inplace=True)
In [71]:
df = pd.merge(df1, df2, how='left', on=['id'])
df = pd.merge(df, df3, how='left', on=['id'])
df = pd.merge(df, df4, how='left', on=['id'])
df = pd.merge(df, df5, how='left', on=['id'])
In [74]:
print stats.pearsonr(df['d1'], df['d2'])
print stats.pearsonr(df['d1'], df['d3'])
print stats.pearsonr(df['d1'], df['d4'])
print stats.pearsonr(df['d1'], df['d5'])
print stats.pearsonr(df['d2'], df['d3'])
print stats.pearsonr(df['d2'], df['d4'])
print stats.pearsonr(df['d2'], df['d5'])
print stats.pearsonr(df['d3'], df['d4'])
print stats.pearsonr(df['d3'], df['d5'])
print stats.pearsonr(df['d4'], df['d5'])
In [77]:
df[:3]
Out[77]:
In [ ]:
def f(x):
return 0.3 * (0.7 * x['d1'] + 0.3 * x['d2']) + 0.7 * x['d3']
df['Demanda_uni_equil'] = df[['d1', 'd2','d3','d4','d5']].apply(f, axis=1)
In [84]:
df['Demanda_uni_equil'] = 0.5*df['d1'] + 0.25*(0.55*df['d4']+0.45*df['d5']) + 0.25*(0.65*df['d2']+0.35*df['d3'])
In [ ]:
In [ ]:
In [78]:
path = '/home/zongyi/bimbo_data/submission/'
for f in os.listdir(path):
print f
In [81]:
df6 = pd.read_csv(path+'w8_f14_n1000_c0.7_45736.csv')
df7 = pd.read_csv(path+'w8_f15_n1000_c0.7_mean_46121.csv')
df8 = pd.read_csv(path+'w8_f26_n1000_c0.5_46928.csv')
In [82]:
df6.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd6'}, inplace=True)
df7.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd7'}, inplace=True)
df8.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd8'}, inplace=True)
df = pd.merge(df, df6, how='left', on=['id'])
df = pd.merge(df, df7, how='left', on=['id'])
df = pd.merge(df, df8, how='left', on=['id'])
In [83]:
print stats.pearsonr(df['d6'], df['d7'])
print stats.pearsonr(df['d6'], df['d8'])
print stats.pearsonr(df['d7'], df['d8'])
In [85]:
df['Demanda_uni_equil1'] = 0.6*df['d6'] + 0.2*df['d7'] + 0.2*df['d8']
In [90]:
df[:3]
Out[90]:
In [ ]:
In [87]:
df10 = pd.read_csv(path+'ensemble-kele-0442.csv')
df10.rename(columns={'id': 'id', 'Demanda_uni_equil': 'd10'}, inplace=True)
df = pd.merge(df, df10, how='left', on=['id'])
In [89]:
df['Demanda_uni_equil'] = 0.4*(0.6*df['Demanda_uni_equil'] + 0.4*df['Demanda_uni_equil1']) + 0.6*df['d10']
In [ ]:
In [18]:
# result['d1'] = result['d1'].apply(lambda x: max(x,0.000000001))
# result['d2'] = result['d2'].apply(lambda x: max(x,0.000000001))
# result['d3'] = result['d3'].apply(lambda x: max(x,0.000000001))
In [19]:
def f(x):
return stats.hmean(x)
result['Demanda_uni_equil'] = result[['d1', 'd2', 'd3']].apply(f, axis=1)
In [11]:
def f(x):
return max(math.expm1(0.25 * math.log1p(x['d1']) + 0.5 * math.log1p(x['d2']) + 0.25 * math.log1p(x['d3'])),0)
result['Demanda_uni_equil'] = result[['d1', 'd2', 'd3']].apply(f, axis=1)
In [9]:
def f(x):
return 0.1 * x['d1'] + 0.6 * x['d2'] + 0.3 * x['d3']
result['Demanda_uni_equil'] = result[['d1', 'd2', 'd3']].apply(f, axis=1)
In [11]:
def f(x):
return 0.6 * x['d2'] + 0.4 * x['d3']
result['Demanda_uni_equil'] = result[['d2', 'd3']].apply(f, axis=1)
In [ ]:
In [91]:
sub = df[['id','Demanda_uni_equil']]
sub.to_csv(path+'ensemble_fulll.csv', index=False)