<jupyter_start><jupyter_text>Preprocessing<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
np.random.seed(1)
X_train = pd.read_csv('/Users/arpanganguli/Documents/Professional/Finance/ISLR/Khanxtrain.csv', index_col=0).dropna()
X_test = pd.read_csv('/Users/arpanganguli/Documents/Professional/Finance/ISLR/Khanxtest.csv', index_col=0).dropna()

y_train = pd.read_csv('/Users/arpanganguli/Documents/Professional/Finance/ISLR/Khanytrain.csv', index_col=0).dropna()
y_test = pd.read_csv('/Users/arpanganguli/Documents/Professional/Finance/ISLR/Khanytest.csv', index_col=0).dropna()<jupyter_output><empty_output><jupyter_text>Support vector classification<jupyter_code>from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix, classification_report

svmfit = SVC(kernel='linear', C=10).fit(X_train, np.ravel(y_train))
# confusion matrix for training data
conf_mat = pd.DataFrame(confusion_matrix(y_train, svmfit.predict(X_train)).T, index = svmfit.classes_, columns = svmfit.classes_)
conf_mat
# classification report for training data
class_mat = classification_report(y_train, svmfit.predict(X_train))
print(class_mat)<jupyter_output>precision    recall  f1-score   support

           1       1.00      1.00      1.00         8
           2       1.00      1.00      1.00        23
           3       1.00      1.00      1.00        12
           4       1.00      1.00      1.00        20

   micro avg       1.00      1.00      1.00        63
   macro avg       1.00      1.00      1.00        63
weighted avg       1.00      1.00      1.00        63<jupyter_text>**There are no training errors. This is because of the large number of predictors as opposed to the number of data. So, I will now fit the model on test data.**<jupyter_code># confusion matrix for test data
conf_mat = pd.DataFrame(confusion_matrix(y_test, svmfit.predict(X_test)).T, index = svmfit.classes_, columns = svmfit.classes_)
conf_mat
# classification report for test data
class_mat = classification_report(y_test, svmfit.predict(X_test))
print(class_mat)<jupyter_output>precision    recall  f1-score   support

           1       1.00      1.00      1.00         3
           2       0.75      1.00      0.86         6
           3       1.00      0.67      0.80         6
           4       1.00      1.00      1.00         5

   micro avg       0.90      0.90      0.90        20
   macro avg       0.94      0.92      0.91        20
weighted avg       0.93      0.90      0.90        20
{'fraction_non_alphanumeric': 0.08998435054773082, 'fraction_numerical': 0.0649452269170579, 'mean_word_length': 2.3294270833333335, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '517889', 'license': 'MIT', 'n_tokens_mistral': 937, 'n_tokens_neox': 852, 'n_words': 201, 'path': 'Chapter 9/R Lab/9.6.5 Application with Gene Expression Data.ipynb', 'repo_name': 'arpanganguli/ISLR-Python', 'size': '2556'}