ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] avplatonov commented on a change in pull request #6849: IGNITE-12148: [ML] Recommendation Engine
Date Tue, 10 Sep 2019 08:59:38 GMT
avplatonov commented on a change in pull request #6849: IGNITE-12148: [ML] Recommendation Engine
URL: https://github.com/apache/ignite/pull/6849#discussion_r322625278
 
 

 ##########
 File path: examples/src/main/java/org/apache/ignite/examples/ml/recommendation/MovieLensExample.java
 ##########
 @@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.recommendation;
+
+import java.io.IOException;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.ml.dataset.impl.cache.CacheBasedDatasetBuilder;
+import org.apache.ignite.ml.environment.LearningEnvironmentBuilder;
+import org.apache.ignite.ml.recommendation.ObjectSubjectRatingTriplet;
+import org.apache.ignite.ml.recommendation.RecommendationModel;
+import org.apache.ignite.ml.recommendation.RecommendationTrainer;
+import org.apache.ignite.ml.util.MLSandboxDatasets;
+import org.apache.ignite.ml.util.SandboxMLCache;
+
+/**
+ * Example of recommendation system based on MovieLens dataset (see https://grouplens.org/datasets/movielens/).
+ * In this example we create a cache with MovieLens rating data. Each entry in this cache
represnts a rating point
+ * (raiting set by a single user to a single movie). Then we pass this cache to {@link RecommendationTrainer}
and so
+ * that train {@link RecommendationModel}. This model predices rating with assumed to be
set by any user to any movie.
+ * When model is ready we calculate R2 score.
+ */
+public class MovieLensExample {
+    /** Run example. */
+    public static void main(String[] args) throws IOException {
+        System.out.println();
+        System.out.println(">>> Recommendation system over cache based dataset usage
example started.");
+        // Start ignite grid.
+        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            System.out.println(">>> Ignite grid started.");
+
+            IgniteCache<Integer, RatingPoint> movielensCache = loadMovieLensDataset(ignite,
10_000);
+            try {
+                LearningEnvironmentBuilder envBuilder = LearningEnvironmentBuilder.defaultBuilder().withRNGSeed(1);
+                RecommendationTrainer trainer = new RecommendationTrainer()
+                    .withMaxIterations(-1)
+                    .withMinMdlImprovement(10)
+                    .withBatchSize(10)
+                    .withLearningRate(10)
+                    .withLearningEnvironmentBuilder(envBuilder)
+                    .withTrainerEnvironment(envBuilder.buildForTrainer());
+
+                RecommendationModel<Integer, Integer> mdl = trainer.fit(
+                    new CacheBasedDatasetBuilder<>(ignite, movielensCache)
+                );
+
+                double mean = 0;
+                try (QueryCursor<Cache.Entry<Integer, RatingPoint>> cursor =
movielensCache.query(new ScanQuery<>())) {
 
 Review comment:
   We can compute RSS using just one query, there is no need to do two-pass process of estimation.
Please, have a look at this page: https://en.wikipedia.org/wiki/Variance . Variance could
be computed using two means - mean value of original data and mean value of squared data.
We can compute these two values to determine variance that used in RSS formula.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message