classifiers.py
def SVM(X_train,X_test,y_train,y_test):
    '''
    Creates Support Vector Machine 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=['Kernel','C','Gamma','Degree','Confusion Matrix'])
    rows = []

    Cs = [1e-1, 1, 1e1, 1e2, 1e3]
    gammas = [1,1e1]
    degrees = [2,3]

    for c in Cs:
        linear = LinearSVC(C=c, random_state=0, max_iter=100000, dual=False)
        linear.fit(X_train, y_train)
        predicted_labels = linear.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(['linear', c, '', '', convert_matrix])

        for gamma in gammas:
            rbf = SVC(kernel = 'rbf', C=c, gamma=gamma, random_state=0, max_iter=100000)
            rbf.fit(X_train, y_train)
            predicted_labels = rbf.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(['rbf', c, gamma, '', convert_matrix])

            for degree in degrees:
                poly = SVC(kernel='poly', C=c, gamma=gamma, degree=degree, random_state=0, max_iter=10000000)
                poly.fit(X_train,y_train)
                predicted_labels = poly.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(['poly', c, gamma, degree, convert_matrix])

    for i in range(len(rows)):
        df = df.append({'Kernel':rows[i][0],'C':rows[i][1],'Gamma':rows[i][2], 'Degree':rows[i][3],
        'Confusion Matrix':rows[i][4]}, ignore_index=True)

    return df

    Creates Support Vector Machine 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 Support Vector Machine 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 Support Vector Machine 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 SVM(X_train,X_test,y_train,y_test):
    df = pd.DataFrame(columns=['Kernel','C','Gamma','Degree','Confusion Matrix'])
    rows = []
    Cs = [1e-1, 1, 1e1, 1e2, 1e3]
    gammas = [1,1e1]
    degrees = [2,3]
    for c in Cs:
        linear = LinearSVC(C=c, random_state=0, max_iter=100000, dual=False)
        linear.fit(X_train, y_train)
        predicted_labels = linear.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(['linear', c, '', '', convert_matrix])
        for gamma in gammas:
            rbf = SVC(kernel = 'rbf', C=c, gamma=gamma, random_state=0, max_iter=100000)
            rbf.fit(X_train, y_train)
            predicted_labels = rbf.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(['rbf', c, gamma, '', convert_matrix])
            for degree in degrees:
                poly = SVC(kernel='poly', C=c, gamma=gamma, degree=degree, random_state=0, max_iter=10000000)
                poly.fit(X_train,y_train)
                predicted_labels = poly.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(['poly', c, gamma, degree, convert_matrix])
    for i in range(len(rows)):
        df = df.append({'Kernel':rows[i][0],'C':rows[i][1],'Gamma':rows[i][2], 'Degree':rows[i][3],
        'Confusion Matrix':rows[i][4]}, ignore_index=True)
    return df
def SVM ( X_train , X_test , y_train , y_test ) : df = pd . DataFrame ( columns = [ 'Kernel' , 'C' , 'Gamma' , 'Degree' , 'Confusion Matrix' ] ) rows = [ ] Cs = [ 1e-1 , 1 , 1e1 , 1e2 , 1e3 ] gammas = [ 1 , 1e1 ] degrees = [ 2 , 3 ] for c in Cs : linear = LinearSVC ( C = c , random_state = 0 , max_iter = 100000 , dual = False ) linear . fit ( X_train , y_train ) predicted_labels = linear . 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 ( [ 'linear' , c , '' , '' , convert_matrix ] ) for gamma in gammas : rbf = SVC ( kernel = 'rbf' , C = c , gamma = gamma , random_state = 0 , max_iter = 100000 ) rbf . fit ( X_train , y_train ) predicted_labels = rbf . 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 ( [ 'rbf' , c , gamma , '' , convert_matrix ] ) for degree in degrees : poly = SVC ( kernel = 'poly' , C = c , gamma = gamma , degree = degree , random_state = 0 , max_iter = 10000000 ) poly . fit ( X_train , y_train ) predicted_labels = poly . 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 ( [ 'poly' , c , gamma , degree , convert_matrix ] ) for i in range ( len ( rows ) ) : df = df . append ( { 'Kernel' : rows [ i ] [ 0 ] , 'C' : rows [ i ] [ 1 ] , 'Gamma' : rows [ i ] [ 2 ] , 'Degree' : rows [ i ] [ 3 ] , 'Confusion Matrix' : rows [ i ] [ 4 ] } , ignore_index = True ) return df
Creates Support Vector Machine classifier models on X_train and y_train with different parameters.
Creates Support Vector Machine classifier models on X_train and y_train with different parameters .
'''
    Creates Support Vector Machine 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