How to use the implicit._als.least_squares function in implicit

To help you get started, we’ve selected a few implicit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benfred / implicit / examples / benchmark_cg.py View on Github external
def benchmark_times(plays):
    output = defaultdict(list)
    for factors in [50, 100, 150, 200, 250]:
        output['factors'].append(factors)
        for steps in [2, 3, 4]:
            current = []
            benchmark_solver(plays, factors,
                             functools.partial(least_squares_cg, cg_steps=steps),
                             lambda elapsed, X, Y: current.append(elapsed),
                             iterations=3)
            print("cg%i: %i factors : %ss" % (steps, factors, min(current)))
            output['cg%i' % steps].append(min(current))

        current = []
        benchmark_solver(plays, factors, least_squares,
                         lambda elapsed, X, Y: current.append(elapsed),
                         iterations=3)
        output['cholesky'].append(min(current))
        print("cholesky: %i factors : %ss" % (factors, min(current)))

    return output
github benfred / implicit / examples / benchmark_cg.py View on Github external
def benchmark_accuracy(plays):
    output = defaultdict(list)
    benchmark_solver(plays, 100,
                     least_squares,
                     lambda _, X, Y: output['cholesky'].append(calculate_loss(plays, X, Y,
                                                                              0)),
                     iterations=25)

    for steps in [2, 3, 4]:
        benchmark_solver(plays, 100, functools.partial(least_squares_cg, cg_steps=steps),
                         lambda _, X, Y: output['cg%i' % steps].append(calculate_loss(plays, X, Y,
                                                                                      0)),
                         iterations=25)

    return output