Skip to content

Instantly share code, notes, and snippets.

@oneryalcin
Last active September 24, 2019 00:08
Show Gist options
  • Save oneryalcin/122e312d9de413daca3a7afe4fa0bfbc to your computer and use it in GitHub Desktop.
Save oneryalcin/122e312d9de413daca3a7afe4fa0bfbc to your computer and use it in GitHub Desktop.
13 Sparkify Cross Validation
# Our Grid Search object allows us to define various hyperparameters to test our model
params = ParamGridBuilder()\
.addGrid(classifier.maxDepth, [2, 5, 10])\
.addGrid(classifier.featureSubsetStrategy, ['all', 'onethird', 'sqrt', 'log2'])\
.build()
# Define the evaluator, this will measure teh success of model(s)
evaluator = binary_evaluator = BinaryClassificationEvaluator(labelCol='churned')
# CrossValidator will build pipeline, create models based on ParamGridBuilder,
# evalute against defined evaluator success and do cross validation using 5 folds
cv = CrossValidator(estimator=pipeline,
estimatorParamMaps=params,
evaluator=evaluator,
numFolds=5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment