def score(self, X, y): scores = outlier.SWRRCT(**self.params, n_jobs=1).fit_predict(X[:,:-1]) if np.any(np.isnan(scores)): print ('Warning: marking NaN as non-outlier') scores[np.isnan(scores)] = 0 return compute_training_score(y, transform_scores(scores))
else: print("ERROR: Invalid algorithm! \n") quit() print("--------------") for idx in range(nrep): if alg=='sdo': detector = pysdo.SDO(k=best_param['k'], x=best_param['x'], qv=best_param['qv'], random_state=idx, chunksize=blocksize+1, return_scores = True) elif alg=='sdostream': detector = outlier.SDOstream(k=best_param['k'], T=timepam, x=best_param['x'], qv=best_param['qv'], seed=idx) elif alg=='swknn': detector = outlier.SWKNN(k=best_param['k'], window=timepam) elif alg=='swlof': detector = outlier.SWLOF(k=best_param['k'], window=timepam) elif alg=='rrct': detector = outlier.SWRRCT(n_estimators=best_param['n_estimators'], window=timepam, seed=idx, n_jobs=1) elif alg=='xstream': detector = xStream(k=best_param['k'], c=best_param['c'], d=best_param['d'], init_sample=timepam, seed=idx) elif alg=='rshash': detector = outlier.RSHash(n_estimators=best_param['n_estimators'], cms_w=best_param['cms_w'], cms_d=best_param['cms_d'], window=timepam, seed=idx, n_jobs=1) elif alg=='loda': detector = outlier.LODA(n_projections=best_param['n_projections'], n_bins=best_param['n_bins'], window=timepam) print("Run ",idx , " of ", nrep) scores = np.zeros(data.shape[0]) ### TRAINING start_tr = time.time() scores[:training_len] = detector.fit_predict(data[:training_len,:]) end_tr = time.time() elapsed_tr = end_tr - start_tr