-
Notifications
You must be signed in to change notification settings - Fork 28.9k
SPARK-9690 Adding the possibility to set the seed of the rand in the … #7997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,7 +121,7 @@ class CrossValidator(Estimator): | |
| numFolds = Param(Params._dummy(), "numFolds", "number of folds for cross validation") | ||
|
|
||
| @keyword_only | ||
| def __init__(self, estimator=None, estimatorParamMaps=None, evaluator=None, numFolds=3): | ||
| def __init__(self, estimator=None, estimatorParamMaps=None, evaluator=None, numFolds=3, seed=0): | ||
| """ | ||
| __init__(self, estimator=None, estimatorParamMaps=None, evaluator=None, numFolds=3) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update this line too. |
||
| """ | ||
|
|
@@ -136,6 +136,8 @@ def __init__(self, estimator=None, estimatorParamMaps=None, evaluator=None, numF | |
| self, "evaluator", | ||
| "evaluator used to select hyper-parameters that maximize the cross-validated metric") | ||
| #: param for number of folds for cross validation | ||
| self._setDefault(seed=0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put all defaults in one call to setDefault.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value of |
||
| self.seed = Param(self, "seed", "seed value used for k-fold") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also not necessary if we make |
||
| self.numFolds = Param(self, "numFolds", "number of folds for cross validation") | ||
| self._setDefault(numFolds=3) | ||
| kwargs = self.__init__._input_kwargs | ||
|
|
@@ -210,7 +212,7 @@ def _fit(self, dataset): | |
| nFolds = self.getOrDefault(self.numFolds) | ||
| h = 1.0 / nFolds | ||
| randCol = self.uid + "_rand" | ||
| df = dataset.select("*", rand(0).alias(randCol)) | ||
| df = dataset.select("*", rand(self.getOrDefault(self.seed)).alias(randCol)) | ||
| metrics = np.zeros(numModels) | ||
| for i in range(nFolds): | ||
| validateLB = i * h | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make
CorssValidatorextendHasSeedthen putseed=Nonehere.