Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from itertools import cycle
  5. import sys
  6. from sklearn import svm, datasets
  7. from sklearn.metrics import roc_curve, auc
  8. from sklearn.model_selection import train_test_split
  9. from sklearn.preprocessing import label_binarize
  10. from sklearn.multiclass import OneVsRestClassifier
  11. from scipy import interp
  12. from sklearn.neighbors import KNeighborsClassifier
  13. from sklearn.naive_bayes import MultinomialNB
  14.  
  15. # Import some data to play with
  16. df = pd.read_csv("E:\autodesk\Hourly and weather categorized2.csv")
  17. X =df[['TTI','Max TemperatureF','Mean TemperatureF','Min TemperatureF',' Min Humidity']].values
  18. y = df['TTI_Category'].as_matrix()
  19. y=y.reshape(-1,1)
  20. # Binarize the output
  21. y = label_binarize(y, classes=['Good','Bad'])
  22. n_classes = y.shape[1]
  23.  
  24. # shuffle and split training and test sets
  25. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,
  26. random_state=0)
  27.  
  28. # Learn to predict each class against the other
  29. classifier = OneVsRestClassifier(KNeighborsClassifier())
  30. y_score = classifier.fit(X_train, y_train).predict_proba(X_test)
  31.  
  32. # Compute ROC curve and ROC area for each class
  33. fpr = dict()
  34. tpr = dict()
  35.  
  36. roc_auc = dict()
  37. for i in range(n_classes):
  38. fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
  39. roc_auc[i] = auc(fpr[i], tpr[i])
  40.  
  41. # Compute micro-average ROC curve and ROC area
  42. fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel())
  43. roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
  44. plt.figure()
  45. lw = 1
  46. plt.plot(fpr[0], tpr[0], color='darkorange', lw=lw, label='ROC curve (area = %0.2f)' % roc_auc[0])
  47. plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
  48. plt.xlim([0.0, 1.0])
  49. plt.ylim([0.0, 1.05])
  50. plt.xlabel('False Positive Rate')
  51. plt.ylabel('True Positive Rate')
  52. plt.title('Receiver operating characteristic example')
  53. plt.legend(loc="lower right")
  54. plt.show()
Add Comment
Please, Sign In to add comment