Skip to content

Commit 6e3818b

Browse files
committed
Tuning spark regulation parameters
1. make sparkling parameters: rank, iteration, lambda can be loaded from config.edn 2. change Java RRD to have only one partition. (defn trans-rating [item] - (spark/tuple (rand-int 10) + (spark/tuple 1
1 parent 5237d7e commit 6e3818b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Diff for: env/dev/resources/config.edn

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{:dev true
22
:port 3000
3+
:spark-rank 8
4+
:spark-iteration 3
5+
:spark-lambda 0.1
36
;; when :nrepl-port is set the application starts the nREPL server on load
47
:nrepl-port 7000}

Diff for: src/clj/intowow/core.clj

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
(log/info "model training starts at" (time/now))
4343
(try
4444
(spark/re-train)
45+
(println "switch to the new matrix model!")
4546
(catch Exception e
4647
(log/error "Error in model training :" e)))
4748
(log/info "model training ends at" (time/now))))

Diff for: src/clj/intowow/sparkling.clj

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns intowow.sparkling
22
(:gen-class)
33
(:require [intowow.db.core :as db]
4+
[intowow.config :refer [env]]
45
[clojure.string :as str]
56
[sparkling.conf :as conf]
67
[sparkling.core :as spark]
@@ -14,7 +15,7 @@
1415
[org.apache.spark.mllib.recommendation ALS Rating]))
1516

1617
(defn trans-rating [item]
17-
(spark/tuple (rand-int 10)
18+
(spark/tuple 1
1819
(Rating. (:user_id item) (:item_id item) (:rating item))))
1920

2021
(defn get-db-ratings [sc]
@@ -56,9 +57,9 @@
5657
"create a new model.
5758
Class: org.apache.spark.mllib.recommendation.MatrixFactorizationModel"
5859
[]
59-
(let [options {:rank 8
60-
:num-iter 1
61-
:lambda 1.0}]
60+
(let [options {:rank (env :spark-rank)
61+
:num-iter (env :spark-iteration)
62+
:lambda (env :spark-lambda)}]
6263
(-> (get-db-ratings sc)
6364
(spark/values)
6465
(alternating-least-squares options))))

0 commit comments

Comments
 (0)