
Advanced Spark Machine Learning Techniques
Learn how to create and evaluate machine learning models using Apache Spark, specifically focusing on RandomForestClassifier. This tutorial covers steps such as creating the model, defining the parameter grid, setting up cross-validation, applying the model to test data, and evaluating the results. Gain insights into the process of optimizing machine learning models with Spark.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Create the machine learning model import org.apache.spark.ml.classification.RandomForestClassifier import org.apache.spark.ml.tuning.{ParamGridBuilder, TrainValidationSplit, CrossValidator} import org.apache.spark.ml.evaluation.MulticlassClassificationEvaluator [f1, f2, f3 fn], label // create the model val rf = new RandomForestClassifier() 10000 0000 00000 1..00 https://www.youtube.com/watch?v=goPiwckWE9M
Create the parameter grid // create the param grid val paramGrid = new ParamGridBuilder(). addGrid(rf.numTrees,Array(20,50,100)). build()
Cross-Validation 20, 50, 100 K-Cross-Validation 3 5 Cross Validation 10 Cross -Validation // create cross val object, define scoring metric val cv = new CrossValidator(). setEstimator(rf). setEvaluator(new MulticlassClassificationEvaluator().setMetricName("weightedRecall")). setEstimatorParamMaps(paramGrid). setNumFolds(10). setParallelism(2) // You can then treat this object as the model and use fit on it. val model = cv.fit(training) https://upload.wikimedia.org/wikipedia/commons/b/b5/K-fold_cross_validation_EN.svg
Apply to test data val results = model.transform(test).select("features", "label", "prediction")
Evaluation on Testing Data Actual labels not certified (0) certified (1) import org.apache.spark.mllib.evaluation.MulticlassMetrics import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics 99622 295 1053 894 0 1 Predicted labels val predictionAndLabels = results. select($"prediction",$"label"). as[(Double, Double)]. rdd // Instantiate a new metrics objects val bMetrics = new BinaryClassificationMetrics(predictionAndLabels) val mMetrics = new MulticlassMetrics(predictionAndLabels) val labels = mMetrics.labels // Print out the Confusion matrix println("Confusion matrix:") println(mMetrics.confusionMatrix)