forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
262 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
header = """# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#""" | ||
|
||
|
||
def _gen_param_code(name, doc, defaultValue): | ||
""" | ||
Generates Python code for a shared param class. | ||
:param name: param name | ||
:param doc: param doc | ||
:param defaultValue: string representation of the param | ||
:return: code string | ||
""" | ||
upperCamelName = name[0].upper() + name[1:] | ||
return """class Has%s(Params): | ||
def __init__(self): | ||
super(Has%s, self).__init__() | ||
#: %s | ||
self.%s = Param(self, "%s", "%s", %s) | ||
def set%s(self, value): | ||
self.paramMap[self.%s] = value | ||
return self | ||
def get%s(self, value): | ||
if self.%s in self.paramMap: | ||
return self.paramMap[self.%s] | ||
else: | ||
return self.defaultValue""" % ( | ||
upperCamelName, upperCamelName, doc, name, name, doc, defaultValue, upperCamelName, name, | ||
upperCamelName, name, name) | ||
|
||
if __name__ == "__main__": | ||
print header | ||
print "\n# DO NOT MODIFY. The code is generated by _gen_shared_params.py.\n" | ||
print "from pyspark.ml.param import Param, Params\n\n" | ||
shared = [ | ||
("maxIter", "max number of iterations", "100"), | ||
("regParam", "regularization constant", "0.1"), | ||
("featuresCol", "features column name", "'features'"), | ||
("labelCol", "label column name", "'label'"), | ||
("predictionCol", "prediction column name", "'prediction'"), | ||
("inputCol", "input column name", "'input'"), | ||
("outputCol", "output column name", "'output'")] | ||
code = [] | ||
for name, doc, defaultValue in shared: | ||
code.append(_gen_param_code(name, doc, defaultValue)) | ||
print "\n\n\n".join(code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# DO NOT MODIFY. The code is generated by _gen_shared_params.py. | ||
|
||
from pyspark.ml.param import Param, Params | ||
|
||
|
||
class HasMaxIter(Params): | ||
|
||
def __init__(self): | ||
super(HasMaxIter, self).__init__() | ||
#: max number of iterations | ||
self.maxIter = Param(self, "maxIter", "max number of iterations", 100) | ||
|
||
def setMaxIter(self, value): | ||
self.paramMap[self.maxIter] = value | ||
return self | ||
|
||
def getMaxIter(self, value): | ||
if self.maxIter in self.paramMap: | ||
return self.paramMap[self.maxIter] | ||
else: | ||
return self.defaultValue | ||
|
||
|
||
class HasRegParam(Params): | ||
|
||
def __init__(self): | ||
super(HasRegParam, self).__init__() | ||
#: regularization constant | ||
self.regParam = Param(self, "regParam", "regularization constant", 0.1) | ||
|
||
def setRegParam(self, value): | ||
self.paramMap[self.regParam] = value | ||
return self | ||
|
||
def getRegParam(self, value): | ||
if self.regParam in self.paramMap: | ||
return self.paramMap[self.regParam] | ||
else: | ||
return self.defaultValue | ||
|
||
|
||
class HasFeaturesCol(Params): | ||
|
||
def __init__(self): | ||
super(HasFeaturesCol, self).__init__() | ||
#: features column name | ||
self.featuresCol = Param(self, "featuresCol", "features column name", 'features') | ||
|
||
def setFeaturesCol(self, value): | ||
self.paramMap[self.featuresCol] = value | ||
return self | ||
|
||
def getFeaturesCol(self, value): | ||
if self.featuresCol in self.paramMap: | ||
return self.paramMap[self.featuresCol] | ||
else: | ||
return self.defaultValue | ||
|
||
|
||
class HasLabelCol(Params): | ||
|
||
def __init__(self): | ||
super(HasLabelCol, self).__init__() | ||
#: label column name | ||
self.labelCol = Param(self, "labelCol", "label column name", 'label') | ||
|
||
def setLabelCol(self, value): | ||
self.paramMap[self.labelCol] = value | ||
return self | ||
|
||
def getLabelCol(self, value): | ||
if self.labelCol in self.paramMap: | ||
return self.paramMap[self.labelCol] | ||
else: | ||
return self.defaultValue | ||
|
||
|
||
class HasPredictionCol(Params): | ||
|
||
def __init__(self): | ||
super(HasPredictionCol, self).__init__() | ||
#: prediction column name | ||
self.predictionCol = Param(self, "predictionCol", "prediction column name", 'prediction') | ||
|
||
def setPredictionCol(self, value): | ||
self.paramMap[self.predictionCol] = value | ||
return self | ||
|
||
def getPredictionCol(self, value): | ||
if self.predictionCol in self.paramMap: | ||
return self.paramMap[self.predictionCol] | ||
else: | ||
return self.defaultValue | ||
|
||
|
||
class HasInputCol(Params): | ||
|
||
def __init__(self): | ||
super(HasInputCol, self).__init__() | ||
#: input column name | ||
self.inputCol = Param(self, "inputCol", "input column name", 'input') | ||
|
||
def setInputCol(self, value): | ||
self.paramMap[self.inputCol] = value | ||
return self | ||
|
||
def getInputCol(self, value): | ||
if self.inputCol in self.paramMap: | ||
return self.paramMap[self.inputCol] | ||
else: | ||
return self.defaultValue | ||
|
||
|
||
class HasOutputCol(Params): | ||
|
||
def __init__(self): | ||
super(HasOutputCol, self).__init__() | ||
#: output column name | ||
self.outputCol = Param(self, "outputCol", "output column name", 'output') | ||
|
||
def setOutputCol(self, value): | ||
self.paramMap[self.outputCol] = value | ||
return self | ||
|
||
def getOutputCol(self, value): | ||
if self.outputCol in self.paramMap: | ||
return self.paramMap[self.outputCol] | ||
else: | ||
return self.defaultValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters