Skip to content

Commit

Permalink
[SPARK-10284][ML][PySpark][Docs] Add @SInCE annotation to pyspark.ml.…
Browse files Browse the repository at this point in the history
…tuning
  • Loading branch information
yu-iskw committed Sep 10, 2015
1 parent 91a577d commit b3b36f9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions python/pyspark/ml/tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import itertools
import numpy as np

from pyspark import since
from pyspark.ml.param import Params, Param
from pyspark.ml import Estimator, Model
from pyspark.ml.util import keyword_only
Expand Down Expand Up @@ -47,11 +48,14 @@ class ParamGridBuilder(object):
True
>>> all([m in expected for m in output])
True
.. addedversion:: 1.4.0
"""

def __init__(self):
self._param_grid = {}

@since("1.4.0")
def addGrid(self, param, values):
"""
Sets the given parameters in this grid to fixed values.
Expand All @@ -60,6 +64,7 @@ def addGrid(self, param, values):

return self

@since("1.4.0")
def baseOn(self, *args):
"""
Sets the given parameters in this grid to fixed values.
Expand Down Expand Up @@ -104,6 +109,8 @@ class CrossValidator(Estimator):
>>> cvModel = cv.fit(dataset)
>>> evaluator.evaluate(cvModel.transform(dataset))
0.8333...
.. addedversion:: 1.4.0
"""

# a placeholder to make it appear in the generated doc
Expand Down Expand Up @@ -142,6 +149,7 @@ def __init__(self, estimator=None, estimatorParamMaps=None, evaluator=None, numF
self._set(**kwargs)

@keyword_only
@since("1.4.0")
def setParams(self, estimator=None, estimatorParamMaps=None, evaluator=None, numFolds=3):
"""
setParams(self, estimator=None, estimatorParamMaps=None, evaluator=None, numFolds=3):
Expand All @@ -150,52 +158,60 @@ def setParams(self, estimator=None, estimatorParamMaps=None, evaluator=None, num
kwargs = self.setParams._input_kwargs
return self._set(**kwargs)

@since("1.4.0")
def setEstimator(self, value):
"""
Sets the value of :py:attr:`estimator`.
"""
self._paramMap[self.estimator] = value
return self

@since("1.4.0")
def getEstimator(self):
"""
Gets the value of estimator or its default value.
"""
return self.getOrDefault(self.estimator)

@since("1.4.0")
def setEstimatorParamMaps(self, value):
"""
Sets the value of :py:attr:`estimatorParamMaps`.
"""
self._paramMap[self.estimatorParamMaps] = value
return self

@since("1.4.0")
def getEstimatorParamMaps(self):
"""
Gets the value of estimatorParamMaps or its default value.
"""
return self.getOrDefault(self.estimatorParamMaps)

@since("1.4.0")
def setEvaluator(self, value):
"""
Sets the value of :py:attr:`evaluator`.
"""
self._paramMap[self.evaluator] = value
return self

@since("1.4.0")
def getEvaluator(self):
"""
Gets the value of evaluator or its default value.
"""
return self.getOrDefault(self.evaluator)

@since("1.4.0")
def setNumFolds(self, value):
"""
Sets the value of :py:attr:`numFolds`.
"""
self._paramMap[self.numFolds] = value
return self

@since("1.4.0")
def getNumFolds(self):
"""
Gets the value of numFolds or its default value.
Expand Down Expand Up @@ -231,7 +247,15 @@ def _fit(self, dataset):
bestModel = est.fit(dataset, epm[bestIndex])
return CrossValidatorModel(bestModel)

@since("1.4.0")
def copy(self, extra=None):
"""
Creates a copy of this instance with a randomly generated uid
and some extra params. This copies creates a deep copy of
the embedded paramMap, and copies the embedded and extra parameters over.
:param extra: Extra parameters to copy to the new instance
:return: Copy of this instance
"""
if extra is None:
extra = dict()
newCV = Params.copy(self, extra)
Expand All @@ -246,6 +270,8 @@ def copy(self, extra=None):
class CrossValidatorModel(Model):
"""
Model from k-fold cross validation.
.. addedversion:: 1.4.0
"""

def __init__(self, bestModel):
Expand All @@ -256,6 +282,7 @@ def __init__(self, bestModel):
def _transform(self, dataset):
return self.bestModel.transform(dataset)

@since("1.4.0")
def copy(self, extra=None):
"""
Creates a copy of this instance with a randomly generated uid
Expand Down

0 comments on commit b3b36f9

Please sign in to comment.