classifiers.py
def xgboost(X_train,X_test,y_train,y_test):
    '''
    Creates multiple XgBoost classifier models on X_train and y_train with different parameters.
    Runs the models on X_test and compare the results with y_test.
    
    Args:
        X_train: A Numpy array containing the dataset for training
        X_test: A Numpy array containing the dataset for testing
        y_train: A Numpy array consisting of the target values for training
        y_test: A Numpy array consisting of the target values for testing

    Returns:
        A DataFrame with all the paramaters used and confusion matrices of each model
    '''
    df = pd.DataFrame(columns=['Max_depth','N_estimators','Confusion Matrix'])
    rows = []

    rate = 0.05
    max_depth = [3,4,5,6,7]
    n_estimators= np.linspace(50, 450, 4, dtype=int)

    for depth in max_depth:
        for estimators in n_estimators:
            xgb = XGBClassifier(booster='gbtree',max_depth=depth,learning_rate=rate,n_estimators = estimators, use_label_encoder =False)
            xgb.fit(X_train, y_train)
            predicted_labels = xgb.predict(X_test)
            tn, fp, fn, tp = confusion_matrix(y_test, predicted_labels, labels=[0,1]).ravel()
            convert_matrix = [tn,fp,fn,tp]
            rows.append([depth,estimators,convert_matrix])

    for i in range(len(rows)):
        df = df.append({'Max_depth':rows[i][0],'N_estimators':rows[i][1],
                        'Confusion Matrix':rows[i][2]}, ignore_index=True)
    return df

    Creates multiple XgBoost classifier models on X_train and y_train with different parameters.
    Runs the models on X_test and compare the results with y_test.
    
    Args:
        X_train: A Numpy array containing the dataset for training
        X_test: A Numpy array containing the dataset for testing
        y_train: A Numpy array consisting of the target values for training
        y_test: A Numpy array consisting of the target values for testing

    Returns:
        A DataFrame with all the paramaters used and confusion matrices of each model
    
Creates multiple XgBoost classifier models on X_train and y_train with different parameters.
Runs the models on X_test and compare the results with y_test.
Creates multiple XgBoost classifier models on X_train and y_train with different parameters . Runs the models on X_test and compare the results with y_test .
def xgboost(X_train,X_test,y_train,y_test):
    df = pd.DataFrame(columns=['Max_depth','N_estimators','Confusion Matrix'])
    rows = []
    rate = 0.05
    max_depth = [3,4,5,6,7]
    n_estimators= np.linspace(50, 450, 4, dtype=int)
    for depth in max_depth:
        for estimators in n_estimators:
            xgb = XGBClassifier(booster='gbtree',max_depth=depth,learning_rate=rate,n_estimators = estimators, use_label_encoder =False)
            xgb.fit(X_train, y_train)
            predicted_labels = xgb.predict(X_test)
            tn, fp, fn, tp = confusion_matrix(y_test, predicted_labels, labels=[0,1]).ravel()
            convert_matrix = [tn,fp,fn,tp]
            rows.append([depth,estimators,convert_matrix])
    for i in range(len(rows)):
        df = df.append({'Max_depth':rows[i][0],'N_estimators':rows[i][1],
                        'Confusion Matrix':rows[i][2]}, ignore_index=True)
    return df
def xgboost ( X_train , X_test , y_train , y_test ) : df = pd . DataFrame ( columns = [ 'Max_depth' , 'N_estimators' , 'Confusion Matrix' ] ) rows = [ ] rate = 0.05 max_depth = [ 3 , 4 , 5 , 6 , 7 ] n_estimators = np . linspace ( 50 , 450 , 4 , dtype = int ) for depth in max_depth : for estimators in n_estimators : xgb = XGBClassifier ( booster = 'gbtree' , max_depth = depth , learning_rate = rate , n_estimators = estimators , use_label_encoder = False ) xgb . fit ( X_train , y_train ) predicted_labels = xgb . predict ( X_test ) tn , fp , fn , tp = confusion_matrix ( y_test , predicted_labels , labels = [ 0 , 1 ] ) . ravel ( ) convert_matrix = [ tn , fp , fn , tp ] rows . append ( [ depth , estimators , convert_matrix ] ) for i in range ( len ( rows ) ) : df = df . append ( { 'Max_depth' : rows [ i ] [ 0 ] , 'N_estimators' : rows [ i ] [ 1 ] , 'Confusion Matrix' : rows [ i ] [ 2 ] } , ignore_index = True ) return df
Creates multiple XgBoost classifier models on X_train and y_train with different parameters.
Creates multiple XgBoost classifier models on X_train and y_train with different parameters .
'''
    Creates multiple XgBoost classifier models on X_train and y_train with different parameters.
    Runs the models on X_test and compare the results with y_test.
    
    Args:
        X_train: A Numpy array containing the dataset for training
        X_test: A Numpy array containing the dataset for testing
        y_train: A Numpy array consisting of the target values for training
        y_test: A Numpy array consisting of the target values for testing

    Returns:
        A DataFrame with all the paramaters used and confusion matrices of each model
    '''
A DataFrame with all the paramaters used and confusion matrices of each model
A DataFrame with all the paramaters used and confusion matrices of each model
X_train
A Numpy array containing the dataset for training
A Numpy array containing the dataset for training
X_test
A Numpy array containing the dataset for testing
A Numpy array containing the dataset for testing
y_train
A Numpy array consisting of the target values for training
A Numpy array consisting of the target values for training
y_test
A Numpy array consisting of the target values for testing
A Numpy array consisting of the target values for testing