Skip to content

Commit

Permalink
Fix h2o-scala to be in sync with current H2O API.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalohlava committed Apr 1, 2014
1 parent 41361e0 commit 225d6b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
5 changes: 2 additions & 3 deletions h2o-scala/src/main/scala/water/api/dsl/DslLegos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ trait T_H2O_Env[K<:HexKey, VT <: DFrame] { // Operating with only given represen
def jobs() = {
val aj = Job.all()
aj foreach { j:Job =>
val cancelled = if (j.end_time == 0) Job.isRunning(j.self()) else j.end_time == Job.CANCELLED_END_TIME
val progress = if (j.end_time == 0) (if (cancelled) "DONE" else j.progress()) else "DONE"
println(j.description + " | " + (if (cancelled) "CANCELLED" else progress))
val progress = if (!j.isRunning()) j.getState().toString else j.progress()*100+" %"
println(j.description + " | " + progress)
}
}
// We need shutdown for sure ! :-)
Expand Down
22 changes: 12 additions & 10 deletions h2o-scala/src/main/scala/water/api/dsl/examples/Examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ object Examples {
// Call in the context of H2O classloader
def userMain(args: Array[String]):Unit = {
H2O.main(args)
//example1()
//example2()
example1()
example2()
example3()
water.api.dsl.H2ODsl.shutdown()
}

def banner(id:Int, desc: String) = {
println("\n==== Example #"+id+" ====\n== \""+desc+"\"" )
println( "====\n")
}

/** Compute average for given column. */
def example1() = {
banner(1, "Compute average of 2nd column in cars dataset")
import water.api.dsl.H2ODsl._

/** Mutable class */
Expand All @@ -45,12 +52,11 @@ object Examples {
} )

println("Average of 2. column is: " + r.sum / r.cnt);
shutdown()
}

/** Call DRF, make a model, predict on a train data, compute MSE. */
def example2() = {

banner(2, "Call DRF API and make a forest for cars dataset")
import water.api.dsl.H2ODsl._
val f = parse("../private/cars.csv")
val source = f(1) ++ f(3 to 7)
Expand All @@ -74,13 +80,11 @@ object Examples {
})

println("RSS: " + rss)

shutdown()
}

/** Compute quantiles for all vectors in a given frame. */
def example3() = {

banner(3, "Call quantiles API and compute quantiles for all columns in cars dataset.")
import water.api.dsl.H2ODsl._
val f = parse("../private/cars.csv")

Expand All @@ -93,9 +97,7 @@ object Examples {
val q = quantiles(f, columnId)
println("Column '" + colname + "' quantile is " + q)
}
}

shutdown()
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/water/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ public boolean isCancelledOrCrashed() {
*/
public boolean isRunning() { return state == JobState.RUNNING; }

public JobState getState() { return state; }


/** Returns a list of all jobs in a system.
* @return list of all jobs including running, done, cancelled, crashed jobs.
Expand Down

0 comments on commit 225d6b5

Please sign in to comment.