spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mengxr <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-2478] [mllib] DecisionTree Python API
Date Sat, 02 Aug 2014 00:28:06 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1727#discussion_r15725329
  
    --- Diff: python/pyspark/mllib/tree.py ---
    @@ -0,0 +1,219 @@
    +#
    +# 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.
    +#
    +
    +from py4j.java_collections import MapConverter
    +
    +from pyspark import SparkContext, RDD
    +from pyspark.mllib._common import \
    +    _get_unmangled_rdd, _get_unmangled_double_vector_rdd, _serialize_double_vector, \
    +    _deserialize_labeled_point, _get_unmangled_labeled_point_rdd, \
    +    _deserialize_double
    +from pyspark.mllib.regression import LabeledPoint
    +from pyspark.serializers import NoOpSerializer
    +
    +class DecisionTreeModel(object):
    +    """
    +    A decision tree model for classification or regression.
    +
    +    WARNING: This is an experimental API.  It will probably be modified for Spark v1.2.
    +    """
    +
    +    def __init__(self, sc, java_model):
    +        """
    +        :param sc:  Spark context
    +        :param java_model:  Handle to Java model object
    +        """
    +        self._sc = sc
    +        self._java_model = java_model
    +
    +    def __del__(self):
    +        self._sc._gateway.detach(self._java_model)
    +
    +    def predict(self, x):
    +        """
    +        Predict the label of one or more examples.
    +        NOTE: This currently does NOT support batch prediction.
    +
    +        :param x:  Data point: feature vector, or a LabeledPoint (whose label is ignored).
    +        """
    +        pythonAPI = self._sc._jvm.PythonMLLibAPI()
    +        if isinstance(x, RDD):
    +            # Bulk prediction
    +            if x.count() == 0:
    +                raise RuntimeError("DecisionTreeModel.predict(x) given empty RDD x.")
    +            elementType = type(x.take(1)[0])
    +            if elementType == LabeledPoint:
    --- End diff --
    
    We don't support `predict(RDD[LabeledPoint])` in Scala/Python. This adds extra complexity
to the API.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message