# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in 

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import math
from scipy.stats.mstats import gmean

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

import os
print(os.listdir("../input"))

# Any results you write to the current directory are saved as output.
math.pow(125, 0.33333333333333333333333333333333333333333333333333333)
print("Reading the data...\n")
df1 = pd.read_csv('../input/sub-log12/submission_log12.csv')
df2 = pd.read_csv('../input/lightgbm-lets-go/submission_from_kernal15.csv')
df3 = pd.read_csv('../input/submission-9780/submission_9780.csv')
df4 = pd.read_csv('../input/log-hm/submission_hm.csv')
df5 = pd.read_csv('../input/log-hm/submission_log.csv')

models = {
          'df2' : {
                    'name':'log12',
                    'score':97.92,
                    'df':df1 },
    
           'df2' : {
                    'name':'lightgbm86',
                    'score':97.86,
                    'df':df2 },
           'df3' : {
                    'name':'lightgbm80',
                    'score':97.80,
                    'df':df3 }
            
           
         }
         
         
df2.head()         

isa_lg = 0
isa_hm = 0
isa_geo_ = 0
power = 1/3

print("Blending...\n")
for df in models.keys() : 
    isa_lg += np.log(models[df]['df'].is_attributed)
    isa_hm += 1/(models[df]['df'].is_attributed)
    isa_geo_ += (models[df]['df'].is_attributed)
isa_lg = np.exp(isa_lg/3)
print("length\n")
print(len(isa_geo_))
isa_hm = 3/isa_hm
isa_geo = pow(isa_geo_, 0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333)
    


print("Isa log\n")
print(isa_lg[:5])
print("Isa harmo\n")
print(isa_hm[:5])
print("Isa geo\n")
print(isa_geo[:5])


sub_log = pd.DataFrame()
sub_log['click_id'] = df2['click_id']
sub_log['is_attributed'] = isa_lg
sub_log.head()

sub_hm = pd.DataFrame()
sub_hm['click_id'] = df2['click_id']
sub_hm['is_attributed'] = isa_hm
sub_hm.head()

sub_geo = pd.DataFrame()
sub_geo['click_id'] = df2['click_id']
sub_geo['is_attributed'] = isa_geo
sub_geo.head()

sub_avg = pd.DataFrame()
sub_avg['click_id'] = df2['click_id']
sub_avg['is_attributed'] = (isa_geo+isa_hm+isa_lg)/3
sub_avg.head()


print("Writing...")
#sub_log.to_csv('submission_log15.csv', index=False, float_format='%.9f')
#sub_hm.to_csv('submission_hm15.csv', index=False, float_format='%.9f')
sub_geo.to_csv('submission_geo.csv', index=False, float_format='%.9f')
sub_avg.to_csv('submission_avg.csv', index=False, float_format='%.9f')