-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-11938][ML] Expose numFeatures in all ML PredictionModel for Py… #9936
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import warnings | ||
|
||
from pyspark import since | ||
from pyspark.ml.base import * | ||
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. Only import the needed class |
||
from pyspark.ml.util import * | ||
from pyspark.ml.wrapper import JavaEstimator, JavaModel | ||
from pyspark.ml.param import TypeConverters | ||
|
@@ -200,7 +201,7 @@ def _checkThresholdConsistency(self): | |
" threshold (%g) and thresholds (equivalent to %g)" % (t2, t)) | ||
|
||
|
||
class LogisticRegressionModel(JavaModel, JavaMLWritable, JavaMLReadable): | ||
class LogisticRegressionModel(HasNumFeaturesModel, JavaModel, JavaMLWritable, JavaMLReadable): | ||
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. Put HasNumFeaturesModel at end of list (here and elsewhere) |
||
""" | ||
Model fitted by LogisticRegression. | ||
|
||
|
@@ -324,6 +325,8 @@ class DecisionTreeClassifier(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPred | |
>>> model2 = DecisionTreeClassificationModel.load(model_path) | ||
>>> model.featureImportances == model2.featureImportances | ||
True | ||
>>> model.numFeatures | ||
1 | ||
|
||
.. versionadded:: 1.4.0 | ||
""" | ||
|
@@ -373,7 +376,8 @@ def _create_model(self, java_model): | |
|
||
|
||
@inherit_doc | ||
class DecisionTreeClassificationModel(DecisionTreeModel, JavaMLWritable, JavaMLReadable): | ||
class DecisionTreeClassificationModel(HasNumFeaturesModel, DecisionTreeModel, JavaMLWritable, | ||
JavaMLReadable): | ||
""" | ||
Model fitted by DecisionTreeClassifier. | ||
|
||
|
@@ -439,6 +443,8 @@ class RandomForestClassifier(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPred | |
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"]) | ||
>>> model.transform(test1).head().prediction | ||
1.0 | ||
>>> model.numFeatures | ||
1 | ||
|
||
.. versionadded:: 1.4.0 | ||
""" | ||
|
@@ -487,7 +493,7 @@ def _create_model(self, java_model): | |
return RandomForestClassificationModel(java_model) | ||
|
||
|
||
class RandomForestClassificationModel(TreeEnsembleModels): | ||
class RandomForestClassificationModel(HasNumFeaturesModel, TreeEnsembleModels): | ||
""" | ||
Model fitted by RandomForestClassifier. | ||
|
||
|
@@ -540,6 +546,8 @@ class GBTClassifier(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredictionCol | |
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"]) | ||
>>> model.transform(test1).head().prediction | ||
1.0 | ||
>>> model.numFeatures | ||
1 | ||
|
||
.. versionadded:: 1.4.0 | ||
""" | ||
|
@@ -604,7 +612,7 @@ def getLossType(self): | |
return self.getOrDefault(self.lossType) | ||
|
||
|
||
class GBTClassificationModel(TreeEnsembleModels): | ||
class GBTClassificationModel(HasNumFeaturesModel, TreeEnsembleModels): | ||
""" | ||
Model fitted by GBTClassifier. | ||
|
||
|
@@ -675,6 +683,8 @@ class NaiveBayes(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredictionCol, H | |
True | ||
>>> model.theta == model2.theta | ||
True | ||
>>> model.numFeatures | ||
2 | ||
|
||
.. versionadded:: 1.5.0 | ||
""" | ||
|
@@ -749,7 +759,7 @@ def getModelType(self): | |
return self.getOrDefault(self.modelType) | ||
|
||
|
||
class NaiveBayesModel(JavaModel, JavaMLWritable, JavaMLReadable): | ||
class NaiveBayesModel(HasNumFeaturesModel, JavaModel, JavaMLWritable, JavaMLReadable): | ||
""" | ||
Model fitted by NaiveBayes. | ||
|
||
|
@@ -817,6 +827,8 @@ class MultilayerPerceptronClassifier(JavaEstimator, HasFeaturesCol, HasLabelCol, | |
True | ||
>>> model.weights == model2.weights | ||
True | ||
>>> model.numFeatures | ||
2 | ||
|
||
.. versionadded:: 1.6.0 | ||
""" | ||
|
@@ -894,7 +906,8 @@ def getBlockSize(self): | |
return self.getOrDefault(self.blockSize) | ||
|
||
|
||
class MultilayerPerceptronClassificationModel(JavaModel, JavaMLWritable, JavaMLReadable): | ||
class MultilayerPerceptronClassificationModel(HasNumFeaturesModel, JavaModel, JavaMLWritable, | ||
JavaMLReadable): | ||
""" | ||
Model fitted by MultilayerPerceptronClassifier. | ||
|
||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove since tag. If this is added to another class in a later version, the since tag will be incorrect.