This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mutest, sigma2test = estimateGaussian(Xtest) | |
| ptest = multivariateGaussian(Xtest, mutest, sigma2test) | |
| pvaltest = multivariateGaussian(Xvaltest, mutest, sigma2test) | |
| F1test, epsilontest = selectThreshHold(yvaltest, pvaltest) | |
| print('\nBest epsilon and F1 are\n',epsilontest, F1test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| outliersTest = ptest < epsilontest | |
| listOfOl = findIndices(outliersTest) | |
| print('\n\n Outliers are:\n',listOfOl) | |
| print('\n\nNumber of outliers are: ',len(listOfOl)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mutest, sigma2test = estimateGaussian(Xtest) | |
| ptest = multivariateGaussian(Xtest, mutest, sigma2test) | |
| pvaltest = multivariateGaussian(Xvaltest, mutest, sigma2test) | |
| F1test, epsilontest = selectThreshHold(yvaltest, pvaltest) | |
| print('\nBest epsilon and F1 are\n',epsilontest, F1test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| newDataset = sio.loadmat('anomalyDataTest.mat') | |
| Xtest = newDataset['X'] | |
| Xvaltest = newDataset['Xval'] | |
| yvaltest = newDataset['yval'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plt.scatter(X[:, 0], X[:, 1], marker = "x") | |
| plt.xlabel('Latency(ms)') | |
| plt.ylabel('Throughput(mb/s)') | |
| plt.scatter(X[listOfOutliers,0], X[listOfOutliers, 1], facecolors = 'none', edgecolors = 'r') | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| count_outliers = len(listOfOutliers) | |
| print('\n\nNumber of outliers:', count_outliers) | |
| print('\n',listOfOutliers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def findIndices(binVec): | |
| l = [] | |
| for i in range(len(binVec)): | |
| if binVec[i] == 1: | |
| l.append(i) | |
| return l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def selectThreshHold(yval, pval): | |
| F1 = 0 | |
| bestF1 = 0 | |
| bestEpsilon = 0 | |
| stepsize = (np.max(pval) - np.min(pval))/1000 | |
| epsVec = np.arange(np.min(pval), np.max(pval), stepsize) | |
| noe = len(epsVec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def multivariateGaussian(X, mu, sigma2): | |
| n = np.size(sigma2, 1) | |
| m = np.size(sigma2, 0) | |
| #print(m,n) | |
| if n == 1 or m == 1: | |
| # print('Yes!') | |
| sigma2 = np.diag(sigma2[0, :]) | |
| #print(sigma2) | |
| X = X - mu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def estimateGaussian(X): | |
| n = np.size(X, 1) | |
| m = np.size(X, 0) | |
| mu = np.zeros((n, 1)) | |
| sigma2 = np.zeros((n, 1)) | |
| mu = np.reshape((1/m)*np.sum(X, 0), (1, n)) | |
| sigma2 = np.reshape((1/m)*np.sum(np.power((X - mu),2), 0),(1, n)) | |
| return mu, sigma2 |
NewerOlder