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
void bubble_sort(int * array,int length) { | |
int i,j,temp; | |
comparison_count = swap_count = 0; | |
for ( i = 0 ; i < length ; i++) { | |
swapped = 0; | |
for ( j = 0 ; j < length - 1; j++) { | |
comparison_count++; | |
if ( array[j] > array[j+1]) { | |
swap_count++; | |
temp = array[j]; |
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
libraryDependencies ++= Seq( | |
"org.apache.spark" %% "spark-core" % sparkVersion % "provided", | |
"org.apache.spark" %% "spark-sql" % sparkVersion % "provided", | |
"org.apache.spark" %% "spark-mllib" % sparkVersion % "provided" | |
) |
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
val spark = SparkSession.builder.appName("MLPipelineBlogDemo").master("local[*]").getOrCreate() |
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
val splits = df.randomSplit(Array(0.8, 0.2), seed = 1234L) | |
val train = splits(0) | |
val test = splits(1) |
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
val genderIndexer = new StringIndexer().setInputCol("Gender").setOutputCol("GenderIndex") | |
val genderOneHotEncoder = new OneHotEncoder().setInputCol("GenderIndex").setOutputCol("GenderOHE") |
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
val features = Array("GenderOHE", "Age", "EstimatedSalary") | |
val dependetVariable = "Purchased" | |
val vectorAssembler = new VectorAssembler().setInputCols(features).setOutputCol("features") | |
val scaler = new StandardScaler().setInputCol("features").setOutputCol("scaledFeatures") |
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
val logisticRegression = new LogisticRegression() | |
.setFeaturesCol("scaledFeatures") | |
.setLabelCol(dependetVariable) |
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
// Assemble the pipeline | |
val stages = Array(genderIndexer, genderOneHotEncoder, vectorAssembler, scaler, logisticRegression) | |
val pipeline = new Pipeline().setStages(stages) | |
//Fit the pipeline | |
val model = pipeline.fit(train) |
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
//Predicting Result for test set | |
val results = model.transform(test) |
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
val evaluator = new BinaryClassificationEvaluator() | |
.setLabelCol(dependetVariable) | |
.setRawPredictionCol("rawPrediction") | |
.setMetricName("areaUnderROC") | |
val accuracy = evaluator.evaluate(results) | |
println(s"Accuracy of Model : ${accuracy}") |
OlderNewer