Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
20f85eca
Commit
20f85eca
authored
11 years ago
by
Tor Myklebust
Browse files
Options
Downloads
Patches
Plain Diff
Java stubs for ALSModel.
parent
076fc162
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mllib/src/main/scala/org/apache/spark/mllib/api/PythonMLLibAPI.scala
+34
-0
34 additions, 0 deletions
...ain/scala/org/apache/spark/mllib/api/PythonMLLibAPI.scala
with
34 additions
and
0 deletions
mllib/src/main/scala/org/apache/spark/mllib/api/PythonMLLibAPI.scala
+
34
−
0
View file @
20f85eca
...
...
@@ -19,6 +19,7 @@ import org.apache.spark.api.java.JavaRDD
import
org.apache.spark.mllib.regression._
import
org.apache.spark.mllib.classification._
import
org.apache.spark.mllib.clustering._
import
org.apache.spark.mllib.recommendation._
import
org.apache.spark.rdd.RDD
import
java.nio.ByteBuffer
import
java.nio.ByteOrder
...
...
@@ -194,4 +195,37 @@ class PythonMLLibAPI extends Serializable {
ret
.
add
(
serializeDoubleMatrix
(
model
.
clusterCenters
))
return
ret
}
private
def
unpackRating
(
ratingBytes
:
Array
[
Byte
])
:
Rating
=
{
val
bb
=
ByteBuffer
.
wrap
(
ratingBytes
)
bb
.
order
(
ByteOrder
.
nativeOrder
())
val
user
=
bb
.
getInt
()
val
product
=
bb
.
getInt
()
val
rating
=
bb
.
getDouble
()
return
new
Rating
(
user
,
product
,
rating
)
}
/**
* Java stub for Python mllib ALSModel.train(). This stub returns a handle
* to the Java object instead of the content of the Java object. Extra care
* needs to be taken in the Python code to ensure it gets freed on exit; see
* the Py4J documentation.
*/
def
trainALSModel
(
ratingsBytesJRDD
:
JavaRDD
[
Array
[
Byte
]],
rank
:
Int
,
iterations
:
Int
,
lambda
:
Double
,
blocks
:
Int
)
:
MatrixFactorizationModel
=
{
val
ratings
=
ratingsBytesJRDD
.
rdd
.
map
(
unpackRating
)
return
ALS
.
train
(
ratings
,
rank
,
iterations
,
lambda
,
blocks
)
}
/**
* Java stub for Python mllib ALSModel.trainImplicit(). This stub returns a
* handle to the Java object instead of the content of the Java object.
* Extra care needs to be taken in the Python code to ensure it gets freed on
* exit; see the Py4J documentation.
*/
def
trainImplicitALSModel
(
ratingsBytesJRDD
:
JavaRDD
[
Array
[
Byte
]],
rank
:
Int
,
iterations
:
Int
,
lambda
:
Double
,
blocks
:
Int
,
alpha
:
Double
)
:
MatrixFactorizationModel
=
{
val
ratings
=
ratingsBytesJRDD
.
rdd
.
map
(
unpackRating
)
return
ALS
.
trainImplicit
(
ratings
,
rank
,
iterations
,
lambda
,
blocks
,
alpha
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment