Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

fraud_svm_test.py 1.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  1. import pandas as pd
  2. import numpy as np
  3. from nltk.tokenize import word_tokenize
  4. from nltk import pos_tag
  5. from nltk.corpus import stopwords
  6. from nltk.stem import WordNetLemmatizer
  7. from sklearn.preprocessing import LabelEncoder
  8. from collections import defaultdict
  9. from nltk.corpus import wordnet as wn
  10. from sklearn.feature_extraction.text import TfidfVectorizer
  11. from sklearn import model_selection, naive_bayes, svm
  12. from sklearn.metrics import accuracy_score
  13. from sklearn.metrics import roc_curve, auc
  14. from sklearn.metrics import plot_confusion_matrix
  15. import matplotlib.pyplot as plt
  16. from sklearn.model_selection import GridSearchCV
  17. from sklearn.model_selection import train_test_split
  18. import pickle
  19. from sklearn.metrics import confusion_matrix
  20. x_test = pd.read_csv('Output/x_test.csv')
  21. x_test = x_test.iloc[1: , :]
  22. y_test = pd.read_csv('Output/y_test.csv')
  23. x_test = x_test.iloc[: , 1:]
  24. y_test=y_test.iloc[: , 1:]
  25. Pkl_Filename = "Model/svm_fraud.pkl"
  26. with open(Pkl_Filename, 'rb') as file:
  27. SVM = pickle.load(file)
  28. predictions_SVM = SVM.predict(x_test)
  29. test_fpr, test_tpr, te_thresholds = roc_curve(y_test, predictions_SVM)
  30. # Use accuracy_score function to get the accuracy
  31. print("SVM Accuracy Score -> ",accuracy_score(predictions_SVM, y_test)*100)
  32. import json
  33. with open('Output/Accuracy.json', 'w') as f:
  34. json.dump((accuracy_score(predictions_SVM, y_test)*100), f)
  35. '''
  36. plt.plot(test_fpr, test_tpr, label=" AUC TEST ="+str(auc(test_fpr, test_tpr)))
  37. plt.legend()
  38. plt.xlabel("True Positive Rate")
  39. plt.ylabel("False Positive Rate")
  40. plt.title("AUC(ROC curve)")
  41. plot_confusion_matrix(SVM, x_test, y_test, normalize='true')
  42. plt.show()
  43. '''
  44. a=confusion_matrix(y_test,predictions_SVM)
  45. b=a.tolist()
  46. with open('Output/Confusion_matrix.json', 'w') as f:
  47. json.dump(b, f)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...