import pandas as pd
import numpy as np
import os
from sklearn.ensemble import GradientBoostingRegressor,AdaBoostRegressor,BaggingRegressor,ExtraTreesRegressor,RandomForestRegressor
from sklearn.model_selection import GridSearchCV

train_data=pd.read_csv('train_data.csv')
test_data=pd.read_csv('test_data.csv')

IDs=test_data['ID']

#get the featuresets generated by imputing missing values
tr1=pd.read_csv('featuresset/tr1.csv')
tr2=pd.read_csv('featuresset/tr2.csv')
tr3=pd.read_csv('featuresset/tr3.csv')
tr4=pd.read_csv('featuresset/tr4.csv')
tr5=pd.read_csv('featuresset/tr5.csv')
tr6=pd.read_csv('featuresset/tr6.csv')

ts1=pd.read_csv('featuresset/ts1.csv')
ts2=pd.read_csv('featuresset/ts2.csv')
ts3=pd.read_csv('featuresset/ts3.csv')
ts4=pd.read_csv('featuresset/ts4.csv')
ts5=pd.read_csv('featuresset/ts5.csv')
ts6=pd.read_csv('featuresset/ts6.csv')


def get_train_test_set(tr,ts):
    ytrain=tr['Footfall']
    xtrain=tr.drop(['Footfall','Unnamed: 0'],1)
    xtest=ts.drop(['Unnamed: 0'],1)
    return(xtrain,ytrain,xtest)


xtrain1,ytrain1,xtest1=get_train_test_set(tr1,ts1)
xtrain2,ytrain2,xtest2=get_train_test_set(tr2,ts2)
xtrain3,ytrain3,xtest3=get_train_test_set(tr3,ts3)
xtrain4,ytrain4,xtest4=get_train_test_set(tr4,ts4)
xtrain5,ytrain5,xtest5=get_train_test_set(tr5,ts5)
xtrain6,ytrain6,xtest6=get_train_test_set(tr6,ts6)



#initialize parameters for gbm using grid search
params_gbm=[{'min_samples_split':list(range(100,1000,100)),'max_depth':list(range(3,10,1))}]

#grid search 
gsearch=GridSearchCV(estimator=GradientBoostingRegressor(n_estimators=250,learning_rate=0.1,max_depth=4,
                                                         subsample=0.8,random_state=10),
                     param_grid=params_gbm,scoring='neg_mean_squared_error',n_jobs=4,cv=5,verbose=10)


#fit the gbm using grid search on all the approaches to get best fit

#1st
gsearch.fit(xtrain1,ytrain1)
print('Best parameter',gsearch.best_params_)
print('Grid scores on development set',gsearch.grid_scores_)


#2nd
gsearch.fit(xtrain2,ytrain2)
print('Best parameter',gsearch.best_params_)
print('Grid scores on development set',gsearch.grid_scores_)

#3rd
gsearch.fit(xtrain3,ytrain3)
print('Best parameter',gsearch.best_params_)
print('Grid scores on development set',gsearch.grid_scores_)

#4th
gsearch.fit(xtrain4,ytrain4)
print('Best parameter',gsearch.best_params_)
print('Grid scores on development set',gsearch.grid_scores_)

#5th
gsearch.fit(xtrain5,ytrain5)
print('Best parameter',gsearch.best_params_)
print('Grid scores on development set',gsearch.grid_scores_)

#6th
gsearch.fit(xtrain6,ytrain6)
print('Best parameter',gsearch.best_params_)
print('Grid scores on development set',gsearch.grid_scores_)

