Esempio n. 1
0
 def score(self, X, y):
     scores = pysdo.SDO(**self.params).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))
Esempio n. 2
0
        best_param = parameter_tuning(param, np.hstack((data[0:training_len,:],timestamps[0:training_len,:])), labels[0:training_len], wrapper)
    elif alg=='loda':
        print("Algorithm: LODA")
        pnp = [int(x) for x in np.linspace(10, 500, num = 30)]
        pnb = [int(x) for x in np.linspace(10, 100, num = 30)]
        param = dict(n_projections=pnp, n_bins=pnb, window=[timepam])
        wrapper = wLODA()
        best_param = parameter_tuning(param, np.hstack((data[0:training_len,:],timestamps[0:training_len,:])), labels[0:training_len], wrapper)
    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)