text_plain_output_1.png
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 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

print('accuracy: ', metrics.accuracy_score(y_test, predictions))
print('precision: ', metrics.precision_score(y_test, predictions))
print('recall: ', metrics.recall_score(y_test, predictions))
print('f1: ', metrics.f1_score(y_test, predictions))