用例 - Spark实现: 继续,现在让我们使用Eclipse IDE for Spark实现我们的项目。
找到下面的伪代码:
[mw_shl_code=scala,true]//Importing the necessary classes
import org.apache.spark._
...
//Creating an Object earthquake
object earthquake {
def main(args: Array[String]) {
//Creating a Spark Configuration and Spark Context
val sparkConf = new SparkConf().setAppName("earthquake").setMaster("local[2]")
val sc = new SparkContext(sparkConf)
//Loading the Earthquake ROC Dataset file as a LibSVM file
val data = MLUtils.loadLibSVMFile(sc, *Path to the Earthquake File* )
//Training the data for Machine Learning
val splits = data.randomSplit( *Splitting 60% to 40%* , seed = 11L)
val training = splits(0).cache()
val test = splits(1)
//Creating a model of the trained data
val numIterations = 100
val model = *Creating SVM Model with SGD* ( *Training Data* , *Number of Iterations* )
//Using map transformation of model RDD
val scoreAndLabels = *Map the model to predict features*
//Using Binary Classification Metrics on scoreAndLabels
val metrics = * Use Binary Classification Metrics on scoreAndLabels *(scoreAndLabels)
val auROC = metrics. *Get the area under the ROC Curve*()
//Displaying the area under Receiver Operating Characteristic
println("Area under ROC = " + auROC)
}
}[/mw_shl_code]