Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
solver = self.solver
log.debug("Running %i ALS iterations", self.iterations)
with tqdm(total=self.iterations, disable=not show_progress) as progress:
# alternate between learning the user_factors from the item_factors and vice-versa
for iteration in range(self.iterations):
s = time.time()
solver(Cui, self.user_factors, self.item_factors, self.regularization,
num_threads=self.num_threads)
solver(Ciu, self.item_factors, self.user_factors, self.regularization,
num_threads=self.num_threads)
progress.update(1)
if self.calculate_training_loss:
loss = _als.calculate_loss(Cui, self.user_factors, self.item_factors,
self.regularization, num_threads=self.num_threads)
progress.set_postfix({"loss": loss})
if self.fit_callback:
self.fit_callback(iteration, time.time() - s)
if self.calculate_training_loss:
log.info("Final training loss %.4f", loss)
def solver(self):
if self.use_cg:
solver = _als.least_squares_cg if self.use_native else least_squares_cg
return functools.partial(solver, cg_steps=self.cg_steps)
return _als.least_squares if self.use_native else least_squares