Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from imblearn.over_sampling import SMOTE, ADASYN
- from collections import Counter
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- from itertools import cycle
- import sys
- from sklearn import svm, datasets
- from sklearn.metrics import roc_curve, auc
- from sklearn.model_selection import train_test_split
- from sklearn.preprocessing import label_binarize
- from sklearn.multiclass import OneVsRestClassifier
- from scipy import interp
- from sklearn.neighbors import KNeighborsClassifier
- from sklearn.naive_bayes import MultinomialNB
- from sklearn.tree import DecisionTreeClassifier
- # Import some data to play with
- df = pd.read_csv("E:\autodesk\Hourly and weather ml.csv")
- # X and y are different columns of the input data. Input X as numpy array
- X = df[['TTI','Max TemperatureF','Mean TemperatureF','Min TemperatureF',' Min Humidity']].values
- # # Reshape X. Do this if X has only one value per data point. In this case, TTI.
- # # Input y as normal list
- y = df['TTI_Category'].as_matrix()
- X_resampled, y_resampled = SMOTE().fit_sample(X, y)
- y_resampled = label_binarize(y_resampled, classes=['Good','Bad','Ok'])
- n_classes = y_resampled.shape[1]
- # shuffle and split training and test sets
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,
- random_state=0)
- # Learn to predict each class against the other
- classifier = OneVsRestClassifier(DecisionTreeClassifier(random_state=0))
- classifier.fit(X_resampled, y_resampled).predict_proba(X_test)
- # Compute ROC curve and ROC area for each class
- fpr = dict()
- tpr = dict()
- roc_auc = dict()
- for i in range(n_classes):
- fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
- roc_auc[i] = auc(fpr[i], tpr[i])
- # Compute micro-average ROC curve and ROC area
- fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel())
- roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
- plt.figure()
- runfile('E:/autodesk/SMOTE with multiclass.py', wdir='E:/autodesk')
- Traceback (most recent call last):
- File "<ipython-input-128-efb16ffc92ca>", line 1, in <module>
- runfile('E:/autodesk/SMOTE with multiclass.py', wdir='E:/autodesk')
- File "C:UsersThinkAnaconda2libsite-packagesspyderutilssitesitecustomize.py", line 880, in runfile
- execfile(filename, namespace)
- File "C:UsersThinkAnaconda2libsite-packagesspyderutilssitesitecustomize.py", line 87, in execfile
- exec(compile(scripttext, filename, 'exec'), glob, loc)
- File "E:/autodesk/SMOTE with multiclass.py", line 51, in <module>
- fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
- IndexError: too many indices for array
Add Comment
Please, Sign In to add comment