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

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

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