classifiers.py
def KNN(X_train,X_test,y_train,y_test):
    '''
    Creates multiple KNearestNeighbors 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
    '''
    neighbors = [5,10,12,14,16,20]
    df = pd.DataFrame(columns=['Neighbors','Confusion Matrix'])
    rows = []

    for n in neighbors:
        knn = KNeighborsClassifier(n_neighbors=n,n_jobs=-1)
        knn.fit(X_train,y_train)
        predicted_labels = knn.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([n, convert_matrix])

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

    return df

    Creates multiple KNearestNeighbors 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 KNearestNeighbors 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 KNearestNeighbors 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 KNN(X_train,X_test,y_train,y_test):
    neighbors = [5,10,12,14,16,20]
    df = pd.DataFrame(columns=['Neighbors','Confusion Matrix'])
    rows = []
    for n in neighbors:
        knn = KNeighborsClassifier(n_neighbors=n,n_jobs=-1)
        knn.fit(X_train,y_train)
        predicted_labels = knn.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([n, convert_matrix])
    for i in range(len(rows)):
        df = df.append({'Neighbors':rows[i][0],'Confusion Matrix':rows[i][1]}, ignore_index=True)
    return df
def KNN ( X_train , X_test , y_train , y_test ) : neighbors = [ 5 , 10 , 12 , 14 , 16 , 20 ] df = pd . DataFrame ( columns = [ 'Neighbors' , 'Confusion Matrix' ] ) rows = [ ] for n in neighbors : knn = KNeighborsClassifier ( n_neighbors = n , n_jobs = - 1 ) knn . fit ( X_train , y_train ) predicted_labels = knn . 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 ( [ n , convert_matrix ] ) for i in range ( len ( rows ) ) : df = df . append ( { 'Neighbors' : rows [ i ] [ 0 ] , 'Confusion Matrix' : rows [ i ] [ 1 ] } , ignore_index = True ) return df
Creates multiple KNearestNeighbors classifier models on X_train and y_train with different parameters.
Creates multiple KNearestNeighbors classifier models on X_train and y_train with different parameters .
'''
    Creates multiple KNearestNeighbors 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