import pandas as pd
import numpy as np
from model_Voting import model
from searchtype import choice, uniform, loguniform
from sklearn.impute import SimpleImputer
from sklearn.ensemble import VotingClassifier

if __name__=='__main__':

 
    model_list=['VotingClassifier']
#    model_list=model_list[1:2]
    
    param_dict={}
#should be less than or equal to 2^(max_depth)
    param_dict['VotingClassifier']={

            'weights':[uniform,0,1],

            }
  
    
    model_dict={}
    model_dict['VotingClassifier']=VotingClassifier

    
    for model_name in model_list:
        
        data_train=pd.read_csv('X_train_featured_filled_nofilled.csv')
        data_test=pd.read_csv('X_test_featured_filled_nofilled.csv')
        
        X_train=data_train.values
        y_train=pd.read_csv('y_train.csv').values.ravel()
        X_test=data_test.values
            
        col_name=data_train.columns.values        
        
        index=np.random.permutation(len(data_train.index))
        X_train=X_train[index]
        y_train=y_train[index]
        
        clf_model=model()
        clf_model.train(X_train,y_train,model_dict[model_name],param_dict[model_name])
        clf_model.predict(X_test)        
#        mask=clf_model.feature()
#        
#        feature_name=list(col_name[mask])
#        data_train_featured=data_train[feature_name]
#        data_train_featured.to_csv('X_train_featured_nofilled.csv', index=False)
#        data_test_featured=data_test[feature_name]
#        data_test_featured.to_csv('X_test_featured_nofilled.csv',index=False)
#        pd.Series(feature_name).to_csv('feature_selected_{}.csv'.format(model_name))
#        
#        X_train_featured=data_train_featured.values
#        X_test_featured=data_test_featured.values
#        y_train_featured=pd.read_csv('y_train.csv').values.ravel()
#        
#        index=np.random.permutation(len(data_train.index))
#        X_train_featured=X_train_featured[index]
#        y_train_featured=y_train_featured[index]
#        
#        clf_model=model()
#        clf_model.train(X_train_featured,y_train_featured,model_dict[model_name],param_dict[model_name])
#        clf_model.predict(X_test_featured)

#    print(np.any(np.isnan(y_train)))
#    print(np.any(np.isinf(y_train)))        
#    imp=SimpleImputer(strategy='constant',fill_value=-1)
#    X_train_imputed=imp.fit_transform(X_train)
#    print(np.any(np.isnan(X_train_imputed)))
#    print(np.any(np.isinf(X_train_imputed)))
#    print(np.any(X_train_imputed>10**9))
#    print(np.argwhere(X_train_imputed>10**9))
#    print(np.argwhere(X_train_imputed>10**9).shape)
#    print(X_train_imputed[0,14])
    
import pandas as pd
import numpy as np
from model_Voting import model
from searchtype import choice, uniform, loguniform
from sklearn.impute import SimpleImputer
from sklearn.ensemble import VotingClassifier

if __name__=='__main__':

 
    model_list=['VotingClassifier']
#    model_list=model_list[1:2]
    
    param_dict={}
#should be less than or equal to 2^(max_depth)
    param_dict['VotingClassifier']={

            'weights':[uniform,0,1],

            }
  
    
    model_dict={}
    model_dict['VotingClassifier']=VotingClassifier

    
    for model_name in model_list:
        
        data_train=pd.read_csv('X_train_featured_filled_nofilled.csv')
        data_test=pd.read_csv('X_test_featured_filled_nofilled.csv')
        
        X_train=data_train.values
        y_train=pd.read_csv('y_train.csv').values.ravel()
        X_test=data_test.values
            
        col_name=data_train.columns.values        
        
        index=np.random.permutation(len(data_train.index))
        X_train=X_train[index]
        y_train=y_train[index]
        
        clf_model=model()
        clf_model.train(X_train,y_train,model_dict[model_name],param_dict[model_name])
        clf_model.predict(X_test)        
#        mask=clf_model.feature()
#        
#        feature_name=list(col_name[mask])
#        data_train_featured=data_train[feature_name]
#        data_train_featured.to_csv('X_train_featured_nofilled.csv', index=False)
#        data_test_featured=data_test[feature_name]
#        data_test_featured.to_csv('X_test_featured_nofilled.csv',index=False)
#        pd.Series(feature_name).to_csv('feature_selected_{}.csv'.format(model_name))
#        
#        X_train_featured=data_train_featured.values
#        X_test_featured=data_test_featured.values
#        y_train_featured=pd.read_csv('y_train.csv').values.ravel()
#        
#        index=np.random.permutation(len(data_train.index))
#        X_train_featured=X_train_featured[index]
#        y_train_featured=y_train_featured[index]
#        
#        clf_model=model()
#        clf_model.train(X_train_featured,y_train_featured,model_dict[model_name],param_dict[model_name])
#        clf_model.predict(X_test_featured)

#    print(np.any(np.isnan(y_train)))
#    print(np.any(np.isinf(y_train)))        
#    imp=SimpleImputer(strategy='constant',fill_value=-1)
#    X_train_imputed=imp.fit_transform(X_train)
#    print(np.any(np.isnan(X_train_imputed)))
#    print(np.any(np.isinf(X_train_imputed)))
#    print(np.any(X_train_imputed>10**9))
#    print(np.argwhere(X_train_imputed>10**9))
#    print(np.argwhere(X_train_imputed>10**9).shape)
#    print(X_train_imputed[0,14])
    
#    model_list=model_list[1:2] #should be less than or equal to 2^(max_depth) #        mask=clf_model.feature() # #        feature_name=list(col_name[mask]) #        data_train_featured=data_train[feature_name] #        data_train_featured.to_csv('X_train_featured_nofilled.csv', index=False) #        data_test_featured=data_test[feature_name] #        data_test_featured.to_csv('X_test_featured_nofilled.csv',index=False) #        pd.Series(feature_name).to_csv('feature_selected_{}.csv'.format(model_name)) # #        X_train_featured=data_train_featured.values #        X_test_featured=data_test_featured.values #        y_train_featured=pd.read_csv('y_train.csv').values.ravel() # #        index=np.random.permutation(len(data_train.index)) #        X_train_featured=X_train_featured[index] #        y_train_featured=y_train_featured[index] # #        clf_model=model() #        clf_model.train(X_train_featured,y_train_featured,model_dict[model_name],param_dict[model_name]) #        clf_model.predict(X_test_featured) #    print(np.any(np.isnan(y_train))) #    print(np.any(np.isinf(y_train))) #    imp=SimpleImputer(strategy='constant',fill_value=-1) #    X_train_imputed=imp.fit_transform(X_train) #    print(np.any(np.isnan(X_train_imputed))) #    print(np.any(np.isinf(X_train_imputed))) #    print(np.any(X_train_imputed>10**9)) #    print(np.argwhere(X_train_imputed>10**9)) #    print(np.argwhere(X_train_imputed>10**9).shape) #    print(X_train_imputed[0,14])