Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clf = LOF() # change this to other detection algorithms
clf.fit(X)
y_train_scores = clf.decision_scores_
original_time.append(time.time() - start)
original_roc.append(roc_auc_score(y, y_train_scores))
original_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "basic")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
basic_time.append(time.time() - start)
basic_roc.append(roc_auc_score(y, y_train_scores))
basic_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "discrete")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
discrete_time.append(time.time() - start)
discrete_roc.append(roc_auc_score(y, y_train_scores))
discrete_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "circulant")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
circulant_time.append(time.time() - start)
circulant_roc.append(roc_auc_score(y, y_train_scores))
circulant_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "toeplitz")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
discrete_time.append(time.time() - start)
discrete_roc.append(roc_auc_score(y, y_train_scores))
discrete_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "circulant")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
circulant_time.append(time.time() - start)
circulant_roc.append(roc_auc_score(y, y_train_scores))
circulant_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "toeplitz")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
toeplitz_time.append(time.time() - start)
toeplitz_roc.append(roc_auc_score(y, y_train_scores))
toeplitz_prn.append(precision_n_scores(y, y_train_scores))
X_transformed = PCA_sklearn(n_components=dim_new).fit_transform(X)
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
pca_time.append(time.time() - start)
pca_roc.append(roc_auc_score(y, y_train_scores))
pca_prn.append(precision_n_scores(y, y_train_scores))
selected_features = generate_bagging_indices(random_state=j,
pca_time = []
rp_roc = []
rp_prn = []
rp_time = []
for j in range(n_iter):
start = time.time()
clf = LOF() # change this to other detection algorithms
clf.fit(X)
y_train_scores = clf.decision_scores_
original_time.append(time.time() - start)
original_roc.append(roc_auc_score(y, y_train_scores))
original_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "basic")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
basic_time.append(time.time() - start)
basic_roc.append(roc_auc_score(y, y_train_scores))
basic_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "discrete")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
discrete_time.append(time.time() - start)
discrete_roc.append(roc_auc_score(y, y_train_scores))
discrete_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "circulant")
def _parallel_fit(n_estimators, clfs, X, total_n_estimators,
rp_flags, objective_dim, rp_method, verbose):
X = check_array(X)
# Build estimators
estimators = []
rp_transformers = []
for i in range(n_estimators):
estimator = clone(clfs[i])
if verbose > 1:
print("Building estimator %d of %d for this parallel run "
"(total %d)..." % (i + 1, n_estimators, total_n_estimators))
if rp_flags[i] == 1:
X_scaled, jlt_transformer = jl_fit_transform(X, objective_dim,
rp_method)
rp_transformers.append(jlt_transformer)
estimator.fit(X_scaled)
estimators.append(estimator)
else:
# if projection is not used, use an identity matrix to keep the shape
rp_transformers.append(np.ones([X.shape[1], X.shape[1]]))
estimator.fit(X)
estimators.append(estimator)
return estimators, rp_transformers
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
basic_time.append(time.time() - start)
basic_roc.append(roc_auc_score(y, y_train_scores))
basic_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "discrete")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
discrete_time.append(time.time() - start)
discrete_roc.append(roc_auc_score(y, y_train_scores))
discrete_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "circulant")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
circulant_time.append(time.time() - start)
circulant_roc.append(roc_auc_score(y, y_train_scores))
circulant_prn.append(precision_n_scores(y, y_train_scores))
X_transformed, _ = jl_fit_transform(X, dim_new, "toeplitz")
start = time.time()
clf.fit(X_transformed)
y_train_scores = clf.decision_scores_
toeplitz_time.append(time.time() - start)
toeplitz_roc.append(roc_auc_score(y, y_train_scores))
toeplitz_prn.append(precision_n_scores(y, y_train_scores))
X_transformed = PCA_sklearn(n_components=dim_new).fit_transform(X)