<jupyter_start><jupyter_text>SVM<jupyter_code>X_train, y_train, X_test, y_test = load_datasets()

scaler = StandardScaler()
scaler.fit(X_train)
X_train_stand = scaler.transform(X_train)
X_test_stand = scaler.transform(X_test)

pca = PCA(n_components=7)
pca.fit(X_train_stand)
pca_X_train = pca.transform(X_train_stand)
pca_X_test = pca.transform(X_test_stand)

clf = svm.SVC(kernel='rbf', gamma=1, C=100)
clf.fit(pca_X_train, y_train)
predictions_svm = clf.predict(pca_X_test)
confusion_matrix = metrics.confusion_matrix(y_test, predictions_svm)
TP, FP, FN, TN = confusion_matrix.ravel()

specificity = TN / (TN + FP) # True Negative Rate

plt.figure(figsize=(5,5))
sns.heatmap(confusion_matrix, annot=True, fmt=".3f", linewidths=.5, square = True, cmap = plt.cm.coolwarm);
plt.ylabel('Actual label');
plt.xlabel('Predicted label');
all_sample_title = 'Accuracy Score: {0:.3f}'.format(metrics.accuracy_score(y_test, predictions_svm))
plt.title(all_sample_title, size = 15);

print('Accuracy: {0:.3f}'.format(metrics.accuracy_score(y_test, predictions_svm)))
print('Matthews CC: {0:.3f}'.format(metrics.matthews_corrcoef(y_test, predictions_svm)))
print('F1 Score: {0:.3f}'.format(metrics.f1_score(y_test, predictions_svm)))
print('Sensitivity: {0:.3f}'.format(metrics.recall_score(y_test, predictions_svm)))
print('Specificity: {0:.3f}'.format(specificity))

from sklearn.metrics import roc_curve
from sklearn.metrics import auc
fpr_keras, tpr_keras, thresholds = roc_curve(y_test.ravel(), predictions_svm.ravel())
auc_keras = auc(fpr_keras, tpr_keras)



def plot_roc_curve(fpr, tpr):
    plt.plot(fpr, tpr, color='orange', label='ROC')
    plt.plot([0, 1], [0, 1], color='darkblue', linestyle='--')
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('Receiver Operating Characteristic (ROC) Curve')
    plt.legend()
    plt.show()


plot_roc_curve(fpr_keras, tpr_keras)<jupyter_output><empty_output><jupyter_text>KNN<jupyter_code>X_train, y_train, X_test, y_test = load_datasets()

scaler = StandardScaler()
scaler.fit(X_train)
X_train_stand = scaler.transform(X_train)
X_test_stand = scaler.transform(X_test)

pca = PCA(n_components=7)
pca.fit(X_train_stand)
pca_X_train = pca.transform(X_train_stand)
pca_X_test = pca.transform(X_test_stand)

b = KNeighborsClassifier(n_neighbors = 2).fit(X_train,y_train) # Fitting the model.

predictions_knn = b.predict(X_test) # Test set is predicted.
print(accuracy_score(y_test,predictions)) # Accuracy score is calculated.
print(classification_report(y_test,predictions)) # Classification report is generated.
confusion_matrix = metrics.confusion_matrix(y_test, predictions_knn)
TP, FP, FN, TN = confusion_matrix.ravel()

specificity = TN / (TN + FP) # True Negative Rate

plt.figure(figsize=(5,5))
sns.heatmap(confusion_matrix, annot=True, fmt=".3f", linewidths=.5, square = True, cmap = plt.cm.coolwarm);
plt.ylabel('Actual label');
plt.xlabel('Predicted label');
all_sample_title = 'Accuracy Score: {0:.3f}'.format(metrics.accuracy_score(y_test, predictions))
plt.title(all_sample_title, size = 15);

print('Accuracy: {0:.3f}'.format(metrics.accuracy_score(y_test, predictions_knn)))
print('Matthews CC: {0:.3f}'.format(metrics.matthews_corrcoef(y_test, predictions_knn)))
print('F1 Score: {0:.3f}'.format(metrics.f1_score(y_test, predictions_knn)))
print('Sensitivity: {0:.3f}'.format(metrics.recall_score(y_test, predictions_knn)))
print('Specificity: {0:.3f}'.format(specificity))
from sklearn.metrics import roc_curve
from sklearn.metrics import auc
fpr_keras, tpr_keras, thresholds = roc_curve(y_test.ravel(), predictions_knn.ravel())
auc_keras = auc(fpr_keras, tpr_keras)


def plot_roc_curve(fpr, tpr):
    plt.plot(fpr, tpr, color='orange', label='ROC')
    plt.plot([0, 1], [0, 1], color='darkblue', linestyle='--')
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('Receiver Operating Characteristic (ROC) Curve')
    plt.legend()
    plt.show()

plot_roc_curve(fpr_keras, tpr_keras)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14949345193970842, 'fraction_numerical': 0.013590313812700766, 'mean_word_length': 7.2781186094069525, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '51145', 'license': 'MIT', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1559, 'n_words': 259, 'path': 'malaria_diagnosis_KNN_&_SVM.ipynb', 'repo_name': 'chiranjeevbitm/Predicting-disease-using-microscopic-image', 'size': '4047'}