hivemall-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myui <...@git.apache.org>
Subject [GitHub] incubator-hivemall pull request #107: [HIVEMALL-132] Generalize f1score UDAF...
Date Mon, 28 Aug 2017 12:43:32 GMT
Github user myui commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/107#discussion_r135514455
  
    --- Diff: core/src/main/java/hivemall/evaluation/F1ScoreUDAF.java ---
    @@ -0,0 +1,134 @@
    +/*
    + * 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 hivemall.evaluation;
    +
    +import hivemall.utils.hadoop.WritableUtils;
    +
    +import java.util.List;
    +
    +import org.apache.hadoop.hive.ql.exec.Description;
    +import org.apache.hadoop.hive.ql.exec.UDAF;
    +import org.apache.hadoop.hive.ql.exec.UDAFEvaluator;
    +import org.apache.hadoop.hive.serde2.io.DoubleWritable;
    +import org.apache.hadoop.io.IntWritable;
    +
    +@SuppressWarnings("deprecation")
    +@Description(name = "f1score", value = "_FUNC_(array[int], array[int]) - Return a F1
score")
    +public final class F1ScoreUDAF extends UDAF {
    +
    +    public static class Evaluator implements UDAFEvaluator {
    +
    +        public static class PartialResult {
    +            long tp;
    +            /** tp + fn */
    +            long totalActual;
    +            /** tp + fp */
    +            long totalPredicted;
    +
    +            PartialResult() {
    +                this.tp = 0L;
    +                this.totalPredicted = 0L;
    +                this.totalActual = 0L;
    +            }
    +
    +            void updateScore(final List<IntWritable> actual, final List<IntWritable>
predicted) {
    +                final int numActual = actual.size();
    +                final int numPredicted = predicted.size();
    +                int countTp = 0;
    +                for (int i = 0; i < numPredicted; i++) {
    +                    IntWritable p = predicted.get(i);
    +                    if (actual.contains(p)) {
    +                        countTp++;
    +                    }
    +                }
    +                this.tp += countTp;
    +                this.totalActual += numActual;
    +                this.totalPredicted += numPredicted;
    +            }
    +
    +            void merge(PartialResult other) {
    --- End diff --
    
    oops. This should be fixed.


---
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