forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic building blocks for intermediate RDD calculation. untested.
Signed-off-by: Manish Amde <manish9ue@gmail.com>
- Loading branch information
1 parent
cd53eae
commit 92cedce
Showing
6 changed files
with
262 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
mllib/src/main/scala/org/apache/spark/mllib/tree/model/Filter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.spark.mllib.tree.model | ||
|
||
case class Filter(split : Split, comparison : Int) { | ||
// Comparison -1,0,1 signifies <.=,> | ||
override def toString = " split = " + split + "comparison = " + comparison | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
mllib/src/test/scala/org/apache/spark/mllib/tree/DecisionTreeSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.spark.mllib.tree | ||
|
||
import scala.util.Random | ||
|
||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.FunSuite | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.SparkContext._ | ||
|
||
import org.jblas._ | ||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.mllib.regression.LabeledPoint | ||
import org.apache.spark.mllib.tree.impurity.Gini | ||
|
||
class DecisionTreeSuite extends FunSuite with BeforeAndAfterAll { | ||
|
||
@transient private var sc: SparkContext = _ | ||
|
||
override def beforeAll() { | ||
sc = new SparkContext("local", "test") | ||
} | ||
|
||
override def afterAll() { | ||
sc.stop() | ||
System.clearProperty("spark.driver.port") | ||
} | ||
|
||
test("split and bin calculation"){ | ||
val arr = DecisionTreeSuite.generateReverseOrderedLabeledPoints() | ||
assert(arr.length == 1000) | ||
val rdd = sc.parallelize(arr) | ||
val strategy = new Strategy("regression",Gini,3,100,"sort") | ||
val (splits, bins) = DecisionTree.find_splits_bins(rdd,strategy) | ||
assert(splits.length==2) | ||
assert(bins.length==2) | ||
assert(splits(0).length==99) | ||
assert(bins(0).length==100) | ||
println(splits(1)(98)) | ||
} | ||
} | ||
|
||
object DecisionTreeSuite { | ||
|
||
def generateReverseOrderedLabeledPoints() : Array[LabeledPoint] = { | ||
val arr = new Array[LabeledPoint](1000) | ||
for (i <- 0 until 1000){ | ||
val lp = new LabeledPoint(1.0,Array(i.toDouble,1000.0-i)) | ||
arr(i) = lp | ||
} | ||
arr | ||
} | ||
|
||
} |