Github user hirakendu commented on a diff in the pull request:
https://github.com/apache/spark/pull/79#discussion_r11228901
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/tree/impurity/Impurity.scala ---
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.mllib.tree.impurity
+
+/**
+ * Trail for calculating information gain
+ */
+trait Impurity extends Serializable {
+
+ /**
+ * information calculation for binary classification
+ * @param c0 count of instances with label 0
+ * @param c1 count of instances with label 1
+ * @return information value
+ */
+ def calculate(c0 : Double, c1 : Double): Double
+
+ /**
+ * information calculation for regression
+ * @param count number of instances
+ * @param sum sum of labels
+ * @param sumSquares summation of squares of the labels
+ * @return information value
+ */
+ def calculate(count: Double, sum: Double, sumSquares: Double): Double
--- End diff --
Adding to the discussion on the need for a generic interface for
`Impurity`, or more precisely `Error`, I believe we all see that it's good to
have. Ideally I would have preferred a single `Error` trait and that all types
of Error like Square or KL divergence extend it, but the consensus is
that it negatively impacts performance.
In addition to performance-oriented implementations for specific loss
functions, I would still recommend a generic `Error` interface and a generic
implementation of decision-tree based on this interface. One possibility is to
add a third `calculate(stats)`, or more precisely `error(errorStats:
ErrorStats)` to the `Error` interface. I am not sure it will help the signature
collision problem though, unless we just keep the one signature for generic
error statistics.
For reference and example of one such interface and implementations, see
`trait LossStats[S <: LossStats[S]]` and `abstract class Loss[S <:
LossStats[S]:Manifest]` in my previous PR,
[https://github.com/apache/incubator-spark/pull/161/files](https://github.com/apache/incubator-spark/pull/161/files),
that exactly do that and provide interfaces for aggregable error statistics
and calculating error from these statistics. (On second thought, I feel
`ErrorStats` and `Error` are better names.) Also see the generic implementation
`class DecisionTreeAlgorithm[S <: LossStats[S]:Manifest]` and implementations
of specific error functions, `SquareLoss` and `EntropyLoss`.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---