text_html_output_1.png
from sklearn import metrics

from sklearn import metrics

from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer

from sklearn.model_selection import GridSearchCV

from sklearn.pipeline import Pipeline

from sklearn.svm import SVC

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

df = pd.read_csv('/kaggle/input/dementiapredictionnlp/Data.csv', sep=';')

pipeline = Pipeline(steps=[('vect', CountVectorizer()), ('cls', SVC())])
parameters = {'cls__C': (0.001, 0.01, 1, 10), 'cls__kernel': ['linear', 'poly', 'rbf'], 'cls__degree': (2, 3, 4), 'cls__gamma': [0.0001, 0.001, 0.01, 0.1, 1]}
grid_search = GridSearchCV(estimator=pipeline, param_grid=parameters, scoring='roc_auc', verbose=1, n_jobs=-1, cv=10)
grid_search.fit(X_train, y_train)

grid_search.best_params_

best_svm = grid_search.best_estimator_

from sklearn.metrics import accuracy_score
predictions = best_svm.predict(X_test)
confusion_matrix_model = metrics.confusion_matrix(y_test, predictions)
target = ['Control', 'Dementia']
confusion_matrix_df = pd.DataFrame(confusion_matrix_model, index=target, columns=target)
confusion_matrix_df.columns.name = 'Predicted'
confusion_matrix_df.index.name = 'Real'
confusion_matrix_df

pipeline_other = Pipeline(steps=[('vect', CountVectorizer()), ('cls', SVC())])
parameters_other = {'cls__C': [0.01], 'cls__kernel': ['linear'], 'cls__probability': [True], 'cls__class_weight': ['balanced']}
grid_search_other = GridSearchCV(estimator=pipeline_other, param_grid=parameters_other, scoring='roc_auc', verbose=1, n_jobs=-1, cv=10)
grid_search_other.fit(X_train_other, y_train_other)

best_svm_app = grid_search_other.best_estimator_

predictions_other = best_svm_app.predict(X_test_other)
confusion_matrix_model_other = metrics.confusion_matrix(y_test_other, predictions_other)
target_other = ['Control', 'Dementia']
confusion_matrix_df_other = pd.DataFrame(confusion_matrix_model_other, index=target_other, columns=target_other)
confusion_matrix_df_other.columns.name = 'Predicted'
confusion_matrix_df_other.index.name = 'Real'
confusion_matrix_df_other

from sklearn import metrics
fpr_lr, tpr_lr, thresholds_lr = metrics.roc_curve(y_test, predictions)
auc_lr = metrics.roc_auc_score(y_test, predictions)
fpr_svm, tpr_svm, thresholds_svm = metrics.roc_curve(y_test_other, predictions_other)
auc_svm = metrics.roc_auc_score(y_test_other, predictions_other)

import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7, 7))
plt.xticks(np.arange(0, 1, 0.1))
plt.yticks(np.arange(0, 1, 0.1))
plt.plot([0, 1], [0, 1], linestyle='--')
ax.plot(fpr_lr, tpr_lr, marker='.', color='b', label='LinearSVC_one, AUC = ' + str(round(auc_lr, 4)))
ax.plot(fpr_svm, tpr_svm, marker='o', color='r', label='LinearSVC, AUC = ' + str(round(auc_svm, 4)))
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.title('ROC Curve')
plt.grid(True)
legend = ax.legend(loc='lower right', shadow=True, fontsize='medium')