def Make_3way(X, Xt,model,  y, seed, n, atleast):
    grand_auc = 0.0    
    kfolder=StratifiedKFold(y, n_folds= n,shuffle=True, random_state=seed)   
    encoder = preprocessing.OneHotEncoder()
    Xs = encoder.fit_transform(X)  # Returns a sparse matrix (see numpy.sparse)  
    i=0
    for train_index, test_index in kfolder: # for each train and test pair of indices in the kfolder object
        # creaning and validation sets
        X_train, X_cv = Xs[train_index], Xs[test_index]
        y_train, y_cv = np.array(y)[train_index], np.array(y)[test_index]
        preds=bagged_set(X_train,y_train,model, SEED , 1, X_cv, update_seed=True)   
        # compute AUC metric for this CV fold
        roc_auc = roc_auc_score(y_cv, preds)
        print "AUC (fold %d/%d): %f" % (i + 1, n, roc_auc)   
        grand_auc+=roc_auc
    grand_auc/=n

    print ("Total AUC is %f" % (grand_auc))
    columns_length=X.shape[1]
    for j in range (columns_length):
        for d in range (j+1,columns_length):  
            print("Adding columns' interraction %d and %d" % (j, d) )
            new_column_train=X[:,j]+X[:,d]
            new_column_test=Xt[:,j]+Xt[:,d]    
            X=np.column_stack((X,new_column_train))
            Xt=np.column_stack((Xt,new_column_test))
            encoder = preprocessing.OneHotEncoder()
            Xs = encoder.fit_transform(X)  # Returns a sparse matrix (see numpy.sparse)                      
            mean_auc = 0.0       
            i=0
            for train_index, test_index in kfolder: # for each train and test pair of indices in the kfolder object
                # creaning and validation sets
                X_train, X_cv = Xs[train_index], Xs[test_index]
                y_train, y_cv = np.array(y)[train_index], np.array(y)[test_index]
                preds=bagged_set(X_train,y_train,model, SEED , 1, X_cv, update_seed=True)   
                # compute AUC metric for this CV fold
                roc_auc = roc_auc_score(y_cv, preds)
                print "AUC (fold %d/%d): %f" % (i + 1, n, roc_auc)   
                mean_auc+=roc_auc   
            mean_auc/=n
            if mean_auc >grand_auc +atleast: # if Auc is best than previous + thresold
              print ("There is uplift by considering variables %d  and %d as new auc: %f with previous best: %f, difference of %f !" % (j,d, mean_auc,grand_auc ,mean_auc-grand_auc) )	            
              grand_auc= mean_auc
            else :# we remove the column sinc eit did not yield uplift
               X = np.delete(X,-1,1) 
               Xt= np.delete(Xt,-1,1)          
             
            
    for j in range (columns_length):
        for d in range (j+1,columns_length):  
            for m in range (d+1,columns_length):              
                print("Adding columns' interraction %d and %d and %d" % (j, d, m) )
                new_column_train=X[:,j]+X[:,d]+X[:,m]
                new_column_test=Xt[:,j]+Xt[:,d]+Xt[:,m]      
                X=np.column_stack((X,new_column_train))
                Xt=np.column_stack((Xt,new_column_test))            
                encoder = preprocessing.OneHotEncoder()
                Xs = encoder.fit_transform(X)  # Returns a sparse matrix (see numpy.sparse)                      
                mean_auc = 0.0       
                i=0
                for train_index, test_index in kfolder: # for each train and test pair of indices in the kfolder object
                    # creaning and validation sets
                    X_train, X_cv = Xs[train_index], Xs[test_index]
                    y_train, y_cv = np.array(y)[train_index], np.array(y)[test_index]
                    preds=bagged_set(X_train,y_train,model, SEED , 1, X_cv, update_seed=True)   
                    # compute AUC metric for this CV fold
                    roc_auc = roc_auc_score(y_cv, preds)
                    print "AUC (fold %d/%d): %f" % (i + 1, n, roc_auc)   
                    mean_auc+=roc_auc   
                mean_auc/=n
                if mean_auc >grand_auc +atleast: # if Auc is best than previous + thresold
                  print ("There is uplift by considering variables %d  and %d and %d as new auc: %f with previous best: %f, difference of %f !" % (j,d,m, mean_auc,grand_auc ,mean_auc-grand_auc) )	            
                  grand_auc= mean_auc
                else :# we remove the column sinc eit did not yield uplift
                   X = np.delete(X,-1,1) 
                   Xt= np.delete(Xt,-1,1)   

     
    return X, Xt
dataset/ETHPy150Open kaz-Anova/ensemble_amazon/amazon_main_logit_3way_best.py/Make_3way/original