Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print('Orig Fit time:', time.time() - start)
print()
all_results = list(map(list, zip(*all_results)))
trained_estimators = _unfold_parallel(all_results[0], n_jobs)
jl_transformers = _unfold_parallel(all_results[1], n_jobs)
##########################################################################
start = time.time()
n_estimators = len(base_estimators)
n_estimators_list, starts, n_jobs = _partition_estimators(n_estimators,
n_jobs)
# model prediction
all_results_pred = Parallel(n_jobs=n_jobs, max_nbytes=None,
verbose=True)(
delayed(_parallel_predict)(
n_estimators_list[i],
trained_estimators[starts[i]:starts[i + 1]],
None,
X_test,
n_estimators,
# rp_flags[starts[i]:starts[i + 1]],
jl_transformers,
approx_flags[starts[i]:starts[i + 1]],
contamination,
verbose=True)
for i in range(n_jobs))
print('Orig Predict time:', time.time() - start)
print()
# unfold and generate the label matrix
print('Orig Fit time:', time.time() - start)
print()
all_results = list(map(list, zip(*all_results)))
trained_estimators = _unfold_parallel(all_results[0], n_jobs)
jl_transformers = _unfold_parallel(all_results[1], n_jobs)
##########################################################################
start = time.time()
n_estimators = len(base_estimators)
n_estimators_list, starts, n_jobs = _partition_estimators(n_estimators,
n_jobs)
# model prediction
all_results_pred = Parallel(n_jobs=n_jobs, max_nbytes=None,
verbose=True)(
delayed(_parallel_predict)(
n_estimators_list[i],
trained_estimators[starts[i]:starts[i + 1]],
None,
X_test,
n_estimators,
jl_transformers,
approx_flags[starts[i]:starts[i + 1]],
contamination,
verbose=True)
for i in range(n_jobs))
print('Orig Predict time:', time.time() - start)
print()
# unfold and generate the label matrix
predicted_labels_orig = np.zeros([X_test.shape[0], n_estimators])
else:
# use simple equal split by sklearn
n_estimators_list, starts, n_jobs = _partition_estimators(
self.n_estimators, self.n_jobs)
# fit the base models
if self.verbose:
print('Parallel label prediction...')
start = time.time()
# TODO: code cleanup. There is an existing bug for joblib on Windows:
# https://github.com/joblib/joblib/issues/806
# max_nbytes can be dropped on other OS
all_results_pred = Parallel(n_jobs=n_jobs, max_nbytes=None,
verbose=True)(
delayed(_parallel_predict)(
n_estimators_list[i],
self.base_estimators[starts[i]:starts[i + 1]],
self.approximators[starts[i]:starts[i + 1]],
X,
self.n_estimators,
# self.rp_flags[starts[i]:starts[i + 1]],
self.jl_transformers_[starts[i]:starts[i + 1]],
self.approx_flags[starts[i]:starts[i + 1]],
self.contamination,
verbose=True)
for i in range(n_jobs))
if self.verbose:
print('Parallel Label Predicting without Approximators '
'Total Time:', time.time() - start)
# delayed(_parallel_predict)(
# n_estimators_list[i],
# trained_estimators[starts[i]:starts[i + 1]],
# approximators[starts[i]:starts[i + 1]],
# X,
# n_estimators,
# rp_flags[starts[i]:starts[i + 1]],
# jl_transformers[starts[i]:starts[i + 1]],
# approx_flags[starts[i]:starts[i + 1]],
# contamination,
# verbose=True)
# for i in range(n_jobs))
all_results_pred = Parallel(n_jobs=n_jobs, max_nbytes=None,
verbose=True)(
delayed(_parallel_predict)(
n_estimators_list[i],
trained_estimators[starts[i]:starts[i + 1]],
approximators[starts[i]:starts[i + 1]],
X,
n_estimators,
rp_flags[starts[i]:starts[i + 1]],
jl_transformers[starts[i]:starts[i + 1]],
approx_flags[starts[i]:starts[i + 1]],
contamination,
verbose=True)
for i in range(n_jobs))
# unfold and generate the label matrix
predicted_labels = np.zeros([X.shape[0], n_estimators])
for i in range(n_jobs):
predicted_labels[:, starts[i]:starts[i + 1]] = np.asarray(
verbose=True)
for i in range(n_jobs))
print('Orig Fit time:', time.time() - start)
print()
all_results = list(map(list, zip(*all_results)))
trained_estimators = _unfold_parallel(all_results[0], n_jobs)
jl_transformers = _unfold_parallel(all_results[1], n_jobs)
##########################################################################
start = time.time()
# model prediction
all_results_pred = Parallel(n_jobs=n_jobs, max_nbytes=None,
verbose=True)(
delayed(_parallel_predict)(
n_estimators_list[i],
trained_estimators[starts[i]:starts[i + 1]],
None,
X,
n_estimators,
rp_flags[starts[i]:starts[i + 1]],
jl_transformers,
approx_flags[starts[i]:starts[i + 1]],
contamination,
verbose=True)
for i in range(n_jobs))
print('Orig Predict time:', time.time() - start)
print()
# unfold and generate the label matrix