1. 程式人生 > 其它 >ALINK(四十):模型評估(五)排序評估 (EvalRankingBatchOp)

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