Complete the code to create a LogisticRegression model.
from pyspark.ml.classification import [1] model = LogisticRegression(featuresCol='features', labelCol='label')
The LogisticRegression class is imported to create a logistic regression model for classification.
Complete the code to fit the RandomForest model on training data.
rf = RandomForestClassifier(featuresCol='features', labelCol='label') rfModel = rf.[1](trainingData)
The fit method trains the RandomForest model on the training dataset.
Fix the error in the code to evaluate the LogisticRegression model using BinaryClassificationEvaluator.
from pyspark.ml.evaluation import BinaryClassificationEvaluator predictions = model.transform(testData) evaluator = BinaryClassificationEvaluator(labelCol='label', rawPredictionCol='[1]') auc = evaluator.evaluate(predictions)
The rawPrediction column contains the raw scores needed by BinaryClassificationEvaluator.
Fill both blanks to create a RandomForest model with 20 trees and max depth 5.
rf = RandomForestClassifier(numTrees=[1], maxDepth=[2], featuresCol='features', labelCol='label')
Setting numTrees to 20 and maxDepth to 5 configures the RandomForest model as requested.
Fill all three blanks to create a dictionary of feature importances from the RandomForest model.
importances = {feature: importance for feature, importance in zip([1], rfModel.[2])}
sorted_importances = dict(sorted(importances.items(), key=lambda item: item[[3]], reverse=True))The feature_names list pairs with featureImportances vector to create the dictionary. Sorting uses index 1 to sort by importance values.
