zoukankan      html  css  js  c++  java
  • ALINK(四十):模型评估(五)排序评估 (EvalRankingBatchOp)

    Java 类名:com.alibaba.alink.operator.batch.evaluation.EvalRankingBatchOp

    Python 类名:EvalRankingBatchOp

    功能介绍

    排序评估是对推荐排序算法的预测结果进行效果评估,支持下列评估指标。

     

     

     

    参数说明

    名称

    中文名称

    描述

    类型

    是否必须?

    默认值

    labelCol

    标签列名

    输入表中的标签列名

    String

     

    predictionCol

    预测结果列名

    预测结果列名

    String

     

    labelRankingInfo

    Object列列名

    Object列列名

    String

     

    "object"

    predictionRankingInfo

    Object列列名

    Object列列名

    String

     

    "object"

    代码示例

    Python 代码

    from pyalink.alink import *
    import pandas as pd
    useLocalEnv(1)
    df = pd.DataFrame([
        ["{"object":"[1, 6, 2, 7, 8, 3, 9, 10, 4, 5]"}", "{"object":"[1, 2, 3, 4, 5]"}"],
        ["{"object":"[4, 1, 5, 6, 2, 7, 3, 8, 9, 10]"}", "{"object":"[1, 2, 3]"}"],
        ["{"object":"[1, 2, 3, 4, 5]"}", "{"object":"[]"}"]
    ])
    inOp = BatchOperator.fromDataframe(df, schemaStr='pred string, label string')
    metrics = EvalRankingBatchOp().setPredictionCol('pred').setLabelCol('label').linkFrom(inOp).collectMetrics()
    print(metrics)

    Java 代码

    import org.apache.flink.types.Row;
    import com.alibaba.alink.operator.batch.BatchOperator;
    import com.alibaba.alink.operator.batch.evaluation.EvalRankingBatchOp;
    import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
    import com.alibaba.alink.operator.common.evaluation.RankingMetrics;
    import org.junit.Test;
    import java.util.Arrays;
    import java.util.List;
    public class EvalRankingBatchOpTest {
      @Test
      public void testEvalRankingBatchOp() throws Exception {
        List <Row> df = Arrays.asList(
          Row.of("{"object":"[1, 6, 2, 7, 8, 3, 9, 10, 4, 5]"}", "{"object":"[1, 2, 3, 4, 5]"}"),
          Row.of("{"object":"[4, 1, 5, 6, 2, 7, 3, 8, 9, 10]"}", "{"object":"[1, 2, 3]"}"),
          Row.of("{"object":"[1, 2, 3, 4, 5]"}", "{"object":"[]"}")
        );
        BatchOperator <?> inOp = new MemSourceBatchOp(df, "pred string, label string");
        RankingMetrics metrics = new EvalRankingBatchOp().setPredictionCol("pred").setLabelCol("label").linkFrom(inOp)
          .collectMetrics();
        System.out.println(metrics.toString());
      }
    }

    运行结果

    -------------------------------- Metrics: --------------------------------
    microPrecision:0.32
    averageReciprocalHitRank:0.5
    precision:0.2667
    accuracy:0.2667
    f1:0.3761
    hitRate:0.6667
    microRecall:1
    microF1:0.4848
    subsetAccuracy:0
    recall:0.6667
    map:0.355
    hammingLoss:0.5667
  • 相关阅读:
    kubernetes安装记录
    nginx ssl 客户端认证配置调研
    centos 6 docker 安装(通过yum)
    elk docker 部署实战
    react 技术栈项目轻量化方案调研
    service worker 实战
    记一次 node-fetch 使用时踩的坑
    那些年使用npm进行依赖管理所踩的坑
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    linux 环境变量设置错误导致 command not found
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/14902443.html
Copyright © 2011-2022 走看看