本文整理汇总了Python中pyspark.ml.param.Params类的典型用法代码示例。如果您正苦于以下问题:Python Params类的具体用法?Python Params怎么用?Python Params使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Params类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, sklearnEstimator=None, keyCols=None, xCol=None, outputCol=None, yCol=None,
estimatorType=None, keyedSklearnEstimators=None, outputType=None):
"""The constructor is used by :class:`KeyedEstimator` to generate a :class:`KeyedModel`; it
is not intended for external use."""
assert (estimatorType == "predictor") == (yCol is not None), \
"yCol is {}, but it should {}be None for a {} estimatorType".format(
yCol, "not " if isLabelled else "", estimatorType)
assert estimatorType in ["transformer", "clusterer", "predictor"], estimatorType
def implies(a, b):
return not a or b
assert implies(estimatorType == "transformer", outputType == Vector.__UDT__), outputType
assert implies(estimatorType == "clusterer", outputType == LongType()), outputType
assert len(keyCols) > 0, len(keyCols)
assert set(keyedSklearnEstimators.columns) == (set(keyCols) | {"estimator"}), \
"keyedSklearnEstimator columns {} should have both key columns {} and " + \
"an estimator column".format(keyedSklearnEstimators.columns, keyCols)
# The superclass expects Param attributes to already be set, so we only init it after
# doing so.
for paramName, paramSpec in KeyedModel._paramSpecs.items():
setattr(self, paramName, Param(Params._dummy(), paramName, paramSpec["doc"]))
super(KeyedModel, self).__init__()
if yCol and type(outputType) not in KeyedModel._sql_types:
raise TypeError("Output type {} is not an AtomicType (expected for {} estimator)"
.format(outputType, estimatorType))
self._set(**self._input_kwargs)
示例2: copy
def copy(self, extra={}):
newCV = Params.copy(self, extra)
if self.isSet(self.estimator):
newCV.setEstimator(self.getEstimator().copy(extra))
# estimatorParamMaps remain the same
if self.isSet(self.evaluator):
newCV.setEvaluator(self.getEvaluator().copy(extra))
return newCV
示例3: copy
def copy(self, extra=None):
if extra is None:
extra = dict()
newCV = Params.copy(self, extra)
if self.isSet(self.estimator):
newCV.setEstimator(self.getEstimator().copy(extra))
# estimatorParamMaps remain the same
if self.isSet(self.evaluator):
newCV.setEvaluator(self.getEvaluator().copy(extra))
return newCV
示例4: copy
def copy(self, extra=None):
"""
Creates a copy of this instance.
:param extra: extra parameters
:returns: new instance
"""
if extra is None:
extra = dict()
that = Params.copy(self, extra)
stages = [stage.copy(extra) for stage in that.getStages()]
return that.setStages(stages)
示例5: copy
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)
if self.isSet(self.estimator):
newCV.setEstimator(self.getEstimator().copy(extra))
# estimatorParamMaps remain the same
if self.isSet(self.evaluator):
newCV.setEvaluator(self.getEvaluator().copy(extra))
return newCV
示例6: test_params
def test_params(self):
testParams = TestParams()
maxIter = testParams.maxIter
inputCol = testParams.inputCol
seed = testParams.seed
params = testParams.params
self.assertEqual(params, [inputCol, maxIter, seed])
self.assertTrue(testParams.hasParam(maxIter.name))
self.assertTrue(testParams.hasDefault(maxIter))
self.assertFalse(testParams.isSet(maxIter))
self.assertTrue(testParams.isDefined(maxIter))
self.assertEqual(testParams.getMaxIter(), 10)
testParams.setMaxIter(100)
self.assertTrue(testParams.isSet(maxIter))
self.assertEqual(testParams.getMaxIter(), 100)
self.assertTrue(testParams.hasParam(inputCol.name))
self.assertFalse(testParams.hasDefault(inputCol))
self.assertFalse(testParams.isSet(inputCol))
self.assertFalse(testParams.isDefined(inputCol))
with self.assertRaises(KeyError):
testParams.getInputCol()
otherParam = Param(Params._dummy(), "otherParam", "Parameter used to test that " +
"set raises an error for a non-member parameter.",
typeConverter=TypeConverters.toString)
with self.assertRaises(ValueError):
testParams.set(otherParam, "value")
# Since the default is normally random, set it to a known number for debug str
testParams._setDefault(seed=41)
testParams.setSeed(43)
self.assertEqual(
testParams.explainParams(),
"\n".join(["inputCol: input column name. (undefined)",
"maxIter: max number of iterations (>= 0). (default: 10, current: 100)",
"seed: random seed. (default: 41, current: 43)"]))
示例7: copy
def copy(self, extra=None):
if extra is None:
extra = dict()
that = Params.copy(self, extra)
stages = [stage.copy(extra) for stage in that.getStages()]
return that.setStages(stages)
示例8: copy
def copy(self, extra={}):
that = Params.copy(self, extra)
stages = [stage.copy(extra) for stage in that.getStages()]
return that.setStages(stages)