<jupyter_start><jupyter_text>SVM Loan Approver  There are a number of classification algorithms that can be used to determine loan elgibility. Some algorithms run better than others. Build a loan approver using the SVM algorithm and compare the accuracy and performance of the SVM model with the Logistic Regression model.<jupyter_code>from path import Path
import numpy as np
import pandas as pd
# Read in the data
# Note: The following data has been normalized between 0 and 1
data = Path('../Resources/loans.csv')
df = pd.read_csv(data)
df.head()<jupyter_output><empty_output><jupyter_text>Separate the Features (X) from the Target (y)<jupyter_code># Segment the features from the target
y = df["status"]
X = df.drop(columns="status")<jupyter_output><empty_output><jupyter_text>Split our data into training and testing<jupyter_code># Use the train_test_split function to create training and testing subsets
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, 
                                                    y, 
                                                    random_state=1, 
                                                    stratify=y)
X_train.shape<jupyter_output><empty_output><jupyter_text>Create a SVM Model<jupyter_code># Instantiate a linear SVM model
from sklearn.svm import SVC
model = SVC(kernel='linear')<jupyter_output><empty_output><jupyter_text>Fit (train) or model using the training data<jupyter_code># Fit the data
model.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Score the model using the test data   Make predictions<jupyter_code># Make predictions using the test data
y_pred = model.predict(X_test)
results = pd.DataFrame({
    "Prediction": y_pred, 
    "Actual": y_test
}).reset_index(drop=True)
results.head()
from sklearn.metrics import accuracy_score
accuracy_score(y_test, y_pred)<jupyter_output><empty_output><jupyter_text>Generate Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix
    confusion_matrix(y_test, y_pred)<jupyter_output><empty_output><jupyter_text>Generate Classification Report<jupyter_code>from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

     approve       0.58      0.58      0.58        12
        deny       0.62      0.62      0.62        13

    accuracy                           0.60        25
   macro avg       0.60      0.60      0.60        25
weighted avg       0.60      0.60      0.60        25
StarcoderdataJupyterStructuredCleanDedup