Skip to content

Commit

Permalink
Changes as per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhbhardwaj committed Nov 3, 2015
1 parent a71e99b commit 29a8067
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from pyspark.mllib.tree import GradientBoostedTrees, GradientBoostedTreesModel
from pyspark.mllib.util import MLUtils
# $example off$

if __name__ == "__main__":
sc = SparkContext(appName="PythonGradientBoostedTreesClassificationExample")
# $example on$
# Load and parse the data file.
data = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_libsvm_data.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
from pyspark.mllib.tree import GradientBoostedTrees, GradientBoostedTreesModel
from pyspark.mllib.util import MLUtils
# $example off$
# $example off#

if __name__ == "__main__":
sc = SparkContext(appName="PythonGradientBoostedTreesRegressionExample")
# $example on$
# Load and parse the data file.
data = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_libsvm_data.txt")
Expand All @@ -44,8 +45,8 @@
# Evaluate model on test instances and compute test error
predictions = model.predict(testData.map(lambda x: x.features))
labelsAndPredictions = testData.map(lambda lp: lp.label).zip(predictions)
testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() /
float(testData.count())
testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() /\
float(testData.count())
print('Test Mean Squared Error = ' + str(testMSE))
print('Learned regression GBT model:')
print(model.toDebugString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from pyspark.mllib.tree import RandomForest, RandomForestModel
from pyspark.mllib.util import MLUtils
# $example off$

if __name__ == "__main__":
sc = SparkContext(appName="PythonRandomForestClassificationExample")
# $example on$
# Load and parse the data file into an RDD of LabeledPoint.
data = MLUtils.loadLibSVMFile(sc, 'data/mllib/sample_libsvm_data.txt')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from pyspark.mllib.tree import RandomForest, RandomForestModel
from pyspark.mllib.util import MLUtils
# $example off$

if __name__ == "__main__":
sc = SparkContext(appName="PythonRandomForestRegressionExample")
# $example on$
# Load and parse the data file into an RDD of LabeledPoint.
data = MLUtils.loadLibSVMFile(sc, 'data/mllib/sample_libsvm_data.txt')
Expand All @@ -45,8 +47,8 @@
# Evaluate model on test instances and compute test error
predictions = model.predict(testData.map(lambda x: x.features))
labelsAndPredictions = testData.map(lambda lp: lp.label).zip(predictions)
testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() /
float(testData.count())
testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() /\
float(testData.count())
print('Test Mean Squared Error = ' + str(testMSE))
print('Learned regression forest model:')
print(model.toDebugString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.apache.spark.mllib.util.MLUtils
// $example off$

object GradientBoostingClassificationExample {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("GradientBoostedTreesClassificationExample")
val sc = new SparkContext(conf)
// $example on$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.apache.spark.mllib.util.MLUtils
// $example off$

object GradientBoostingRegressionExample {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("GradientBoostedTreesRegressionExample")
val sc = new SparkContext(conf)
// $example on$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.mllib.util.MLUtils
// $example off$

object RandomForestClassificationExample {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("RandomForestClassificationExample")
val sc = new SparkContext(conf)
// $example on$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.mllib.util.MLUtils
// $example off$

object RandomForestRegressionExample {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("RandomForestRegressionExample")
val sc = new SparkContext(conf)
// $example on$
Expand Down

0 comments on commit 29a8067

Please sign in to comment.