Guest User

Untitled

a guest
Jul 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. from imblearn.over_sampling import SMOTE, ADASYN
  2. from collections import Counter
  3. import pandas as pd
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. from itertools import cycle
  7. import sys
  8. from sklearn import svm, datasets
  9. from sklearn.metrics import roc_curve, auc
  10. from sklearn.model_selection import train_test_split
  11. from sklearn.preprocessing import label_binarize
  12. from sklearn.multiclass import OneVsRestClassifier
  13. from scipy import interp
  14. from sklearn.neighbors import KNeighborsClassifier
  15. from sklearn.naive_bayes import MultinomialNB
  16. from sklearn.tree import DecisionTreeClassifier
  17. # Import some data to play with
  18. df = pd.read_csv("E:\autodesk\Hourly and weather ml.csv")
  19. # X and y are different columns of the input data. Input X as numpy array
  20. X = df[['TTI','Max TemperatureF','Mean TemperatureF','Min TemperatureF',' Min Humidity']].values
  21. # # Reshape X. Do this if X has only one value per data point. In this case, TTI.
  22.  
  23. # # Input y as normal list
  24. y = df['TTI_Category'].as_matrix()
  25.  
  26. X_resampled, y_resampled = SMOTE().fit_sample(X, y)
  27.  
  28. y_resampled = label_binarize(y_resampled, classes=['Good','Bad','Ok'])
  29. n_classes = y_resampled.shape[1]
  30.  
  31. # shuffle and split training and test sets
  32. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,
  33. random_state=0)
  34.  
  35. # Learn to predict each class against the other
  36. classifier = OneVsRestClassifier(DecisionTreeClassifier(random_state=0))
  37. classifier.fit(X_resampled, y_resampled).predict_proba(X_test)
  38.  
  39. # Compute ROC curve and ROC area for each class
  40.  
  41. fpr = dict()
  42. tpr = dict()
  43.  
  44. roc_auc = dict()
  45. for i in range(n_classes):
  46. fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
  47. roc_auc[i] = auc(fpr[i], tpr[i])
  48.  
  49. # Compute micro-average ROC curve and ROC area
  50. fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel())
  51.  
  52. roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
  53.  
  54. plt.figure()
  55.  
  56. runfile('E:/autodesk/SMOTE with multiclass.py', wdir='E:/autodesk')
  57. Traceback (most recent call last):
  58.  
  59. File "<ipython-input-128-efb16ffc92ca>", line 1, in <module>
  60. runfile('E:/autodesk/SMOTE with multiclass.py', wdir='E:/autodesk')
  61.  
  62. File "C:UsersThinkAnaconda2libsite-packagesspyderutilssitesitecustomize.py", line 880, in runfile
  63. execfile(filename, namespace)
  64.  
  65. File "C:UsersThinkAnaconda2libsite-packagesspyderutilssitesitecustomize.py", line 87, in execfile
  66. exec(compile(scripttext, filename, 'exec'), glob, loc)
  67.  
  68. File "E:/autodesk/SMOTE with multiclass.py", line 51, in <module>
  69. fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
  70.  
  71. IndexError: too many indices for array
Add Comment
Please, Sign In to add comment