classifiers.py
def rdforest(X_train,X_test,y_train,y_test):
    '''
    Creates multiple Random Forest 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=['N_Estimators','Max_Depth','Confusion Matrix'])
    rows = []

    estimators = [200,300,400,500]
    max_depths = [5,7,10]

    for estimator in estimators:
        for max_d in max_depths:
            rdf = RandomForestClassifier(n_estimators=estimator, max_depth=max_d,  random_state=0, n_jobs=-1)
            rdf.fit(X_train, y_train)
            predicted_labels = rdf.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([estimator, max_d, convert_matrix])

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

    Creates multiple Random Forest 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 Random Forest 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 Random Forest 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 rdforest(X_train,X_test,y_train,y_test):
    df = pd.DataFrame(columns=['N_Estimators','Max_Depth','Confusion Matrix'])
    rows = []
    estimators = [200,300,400,500]
    max_depths = [5,7,10]
    for estimator in estimators:
        for max_d in max_depths:
            rdf = RandomForestClassifier(n_estimators=estimator, max_depth=max_d,  random_state=0, n_jobs=-1)
            rdf.fit(X_train, y_train)
            predicted_labels = rdf.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([estimator, max_d, convert_matrix])
    for i in range(len(rows)):
        df = df.append({'N_Estimators':rows[i][0],'Max_Depth':rows[i][1],'Confusion Matrix':rows[i][2]}, ignore_index=True)
    return df
def rdforest ( X_train , X_test , y_train , y_test ) : df = pd . DataFrame ( columns = [ 'N_Estimators' , 'Max_Depth' , 'Confusion Matrix' ] ) rows = [ ] estimators = [ 200 , 300 , 400 , 500 ] max_depths = [ 5 , 7 , 10 ] for estimator in estimators : for max_d in max_depths : rdf = RandomForestClassifier ( n_estimators = estimator , max_depth = max_d , random_state = 0 , n_jobs = - 1 ) rdf . fit ( X_train , y_train ) predicted_labels = rdf . 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 ( [ estimator , max_d , convert_matrix ] ) for i in range ( len ( rows ) ) : df = df . append ( { 'N_Estimators' : rows [ i ] [ 0 ] , 'Max_Depth' : rows [ i ] [ 1 ] , 'Confusion Matrix' : rows [ i ] [ 2 ] } , ignore_index = True ) return df
Creates multiple Random Forest classifier models on X_train and y_train with different parameters.
Creates multiple Random Forest classifier models on X_train and y_train with different parameters .
'''
    Creates multiple Random Forest 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