# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

from sklearn.metrics import accuracy_score
from sklearn.metrics import roc_auc_score
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import f1_score
import matplotlib.pyplot as plt
from sklearn import svm
import pandas as pd


data = pd.read_csv("./telecom.csv")

data

X = data.iloc[:,6:20].values
Y=data.iloc[:,20].values

from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.20,random_state=101)

# +
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)

X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
# -

clf = svm.SVC(probability=True)
clf.fit(X_train,Y_train)

clf.predict(X_test)

# get support vectors
clf.support_vectors_

# get indices of support vectors
clf.support_

# get number of support vectors for each class
clf.n_support_

predicted_test = clf.predict(X_test)

accuracy_test = accuracy_score(Y_test,predicted_test)

accuracy_test

from sklearn.metrics import classification_report, confusion_matrix
print(confusion_matrix(Y_test, predicted_test))
print(classification_report(Y_test, predicted_test))

y_probs = clf.predict_proba(X_test)

# keeping probabilities for the positive outcome only
y_probs = y_probs[:,1]

y_probs

auc = roc_auc_score(Y_test,y_probs)

print('Support vector: ROC AUC=%.3f' % (auc))

sv_fpr,sv_tpr,_ = roc_curve(Y_test,y_probs)

plt.plot(sv_fpr,sv_tpr,marker=".", label = "Support Vector")
# axis labels
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
# show the legend
plt.legend()
# show the plot
plt.show()

sv_precision, sv_recall, _ = precision_recall_curve(Y_test,y_probs)


# calculate f1 score
sv_f1 = f1_score(Y_test,predicted_test) 
print(sv_f1)

plt.plot(sv_recall, sv_precision, marker='.', label='Support Vector')
# axis labels
plt.xlabel('Recall')
plt.ylabel('Precision')
# show the legend
plt.legend()
# show the plot
plt.show()




StarcoderdataJupyterScriptsDedupFiltered