Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

dynamic Dimensions #5

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions data/import_eventserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def import_events(client, file):
entity_type="user",
entity_id=str(count), # use the count num as user ID
properties= {
"attr0" : int(attr[0]),
"attr1" : int(attr[1]),
"attr2" : int(attr[2]),
"attrs" : [int(attr[0]),int(attr[1]),int(attr[2]) ],
"plan" : int(plan)
}
)
Expand Down
20 changes: 8 additions & 12 deletions src/main/scala/DataSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ class DataSource(val dsp: DataSourceParams)
appName = dsp.appName,
entityType = "user",
// only keep entities with these required properties defined
required = Some(List("plan", "attr0", "attr1", "attr2")))(sc)
required = Some(List("plan", "attrs")))(sc)
// aggregateProperties() returns RDD pair of
// entity ID and its aggregated properties
.map { case (entityId, properties) =>
try {
LabeledPoint(properties.get[Double]("plan"),
Vectors.dense(Array(
properties.get[Double]("attr0"),
properties.get[Double]("attr1"),
properties.get[Double]("attr2")
))
Vectors.dense(
properties.get[Array[Double]]("attrs")
)
)
} catch {
case e: Exception => {
Expand Down Expand Up @@ -68,17 +66,15 @@ class DataSource(val dsp: DataSourceParams)
appName = dsp.appName,
entityType = "user",
// only keep entities with these required properties defined
required = Some(List("plan", "attr0", "attr1", "attr2")))(sc)
required = Some(List("plan", "attrs")))(sc)
// aggregateProperties() returns RDD pair of
// entity ID and its aggregated properties
.map { case (entityId, properties) =>
try {
LabeledPoint(properties.get[Double]("plan"),
Vectors.dense(Array(
properties.get[Double]("attr0"),
properties.get[Double]("attr1"),
properties.get[Double]("attr2")
))
Vectors.dense(
properties.get[Array[Double]]("attrs")
)
)
} catch {
case e: Exception => {
Expand Down
12 changes: 7 additions & 5 deletions src/main/scala/Engine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package org.template.classification
import io.prediction.controller.EngineFactory
import io.prediction.controller.Engine

class Query(
val attr0 : Double,
val attr1 : Double,
val attr2 : Double
) extends Serializable
class Query extends Serializable{
var attrs: Seq[Double] = null
def this(attrs: Double*) {
this()
this.attrs = attrs
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @MZJgithub , wondering why we need to have an auxiliary constructor here. Can we simply have

class Query(val attrs: Seq[Double]) extends Serializable

?


class PredictedResult(
val label: Double
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/NaiveBayesAlgorithm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NaiveBayesAlgorithm(val ap: AlgorithmParams)

def predict(model: NaiveBayesModel, query: Query): PredictedResult = {
val label = model.predict(Vectors.dense(
Array(query.attr0, query.attr1, query.attr2)
Array(query.attrs: _*)
))
new PredictedResult(label)
}
Expand Down