Example usage for org.apache.mahout.cf.taste.impl.recommender.svd ALSWRFactorizer factorize

List of usage examples for org.apache.mahout.cf.taste.impl.recommender.svd ALSWRFactorizer factorize

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.recommender.svd ALSWRFactorizer factorize.

Prototype

@Override
    public Factorization factorize() throws TasteException 

Source Link

Usage

From source file:org.plista.kornakapi.core.training.FactorizationbasedInMemoryTrainer.java

License:Apache License

@Override
protected void doTrain(File targetFile, DataModel inmemoryData, int numProcessors) throws IOException {
    try {/*w w w  . ja va 2  s .co  m*/
        if (inmemoryData.getNumItems() >= 5 && inmemoryData.getNumUsers() >= 10) {//preventing matrix singularity
            ALSWRFactorizer factorizer = new ALSWRFactorizer(inmemoryData, conf.getNumberOfFeatures(),
                    conf.getLambda(), conf.getNumberOfIterations(), conf.isUsesImplicitFeedback(),
                    conf.getAlpha(), numProcessors);

            long start = System.currentTimeMillis();
            Factorization factorization = factorizer.factorize();
            long estimateDuration = System.currentTimeMillis() - start;

            if (log.isInfoEnabled()) {
                log.info("Model trained in {} ms", estimateDuration);
            }

            new FilePersistenceStrategy(targetFile).maybePersist(factorization);
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
}