Java 类名:com.alibaba.alink.operator.batch.evaluation.EvalTimeSeriesBatchOp
Python 类名:EvalTimeSeriesBatchOp

功能介绍

对时间序列结果进行评估。

参数说明

| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- |

| labelCol | 标签列名 | 输入表中的标签列名 | String | ✓ | | |

| predictionCol | 预测结果列名 | 预测结果列名 | String | ✓ | | |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. import time, datetime
  5. import numpy as np
  6. import pandas as pd
  7. data = pd.DataFrame([
  8. [1, datetime.datetime.fromtimestamp(1), 10.0, 10.5],
  9. [1, datetime.datetime.fromtimestamp(2), 11.0, 10.5],
  10. [1, datetime.datetime.fromtimestamp(3), 12.0, 11.5],
  11. [1, datetime.datetime.fromtimestamp(4), 13.0, 12.5],
  12. [1, datetime.datetime.fromtimestamp(5), 14.0, 13.5],
  13. [1, datetime.datetime.fromtimestamp(6), 15.0, 14.5],
  14. [1, datetime.datetime.fromtimestamp(7), 16.0, 14.5],
  15. [1, datetime.datetime.fromtimestamp(8), 17.0, 14.5],
  16. [1, datetime.datetime.fromtimestamp(9), 18.0, 14.5],
  17. [1, datetime.datetime.fromtimestamp(10), 19.0, 16.5]
  18. ])
  19. source = dataframeToOperator(data, schemaStr='id int, ts timestamp, val double, pred double', op_type='batch')
  20. cmex = source.link(
  21. EvalTimeSeriesBatchOp()\
  22. .setLabelCol("val")\
  23. .setPredictionCol("pred")
  24. ).collectMetrics()
  25. print(cmex.getMse())
  26. print(cmex.getMae())
  27. print(cmex.getRmse())
  28. print(cmex.getSse())
  29. print(cmex.getSst())
  30. print(cmex.getSsr())
  31. print(cmex.getSae())
  32. print(cmex.getMape())
  33. print(cmex.getSmape())
  34. print(cmex.getND())
  35. print(cmex.getCount())
  36. print(cmex.getYMean())
  37. print(cmex.getPredictionMean())

Java 代码

  1. package com.alibaba.alink.operator.batch.evaluation;
  2. import org.apache.flink.types.Row;
  3. import com.alibaba.alink.operator.batch.BatchOperator;
  4. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  5. import com.alibaba.alink.testutil.AlinkTestBase;
  6. import org.junit.Test;
  7. import java.sql.Timestamp;
  8. import java.util.Arrays;
  9. import java.util.List;
  10. public class EvalTimeSeriesBatchOpTest extends AlinkTestBase {
  11. @Test
  12. public void test() throws Exception {
  13. List <Row> mTableData = Arrays.asList(
  14. Row.of(1, new Timestamp(1), 10.0, 10.5),
  15. Row.of(1, new Timestamp(2), 11.0, 10.5),
  16. Row.of(1, new Timestamp(3), 12.0, 11.5),
  17. Row.of(1, new Timestamp(4), 13.0, 12.5),
  18. Row.of(1, new Timestamp(5), 14.0, 13.5),
  19. Row.of(1, new Timestamp(6), 15.0, 14.5),
  20. Row.of(1, new Timestamp(7), 16.0, 14.5),
  21. Row.of(1, new Timestamp(8), 17.0, 14.5),
  22. Row.of(1, new Timestamp(9), 18.0, 14.5),
  23. Row.of(1, new Timestamp(10), 19.0, 16.5)
  24. );
  25. MemSourceBatchOp source = new MemSourceBatchOp(mTableData, new String[] {"id", "ts", "val", "pred"});
  26. source.link(
  27. new EvalTimeSeriesBatchOp()
  28. .setLabelCol("val")
  29. .setPredictionCol("pred")
  30. ).lazyPrintMetrics();
  31. BatchOperator.execute();
  32. }
  33. }

运行结果

| regression_eval_result | | —- |

| {“predictionMean”:”13.3”,”SSE”:”28.5”,”count”:”10.0”,”SMAPE”:”8.606434351991227”,”MAPE”:”8.114625849726469”,”RMSE”:”1.6881943016134133”,”MAE”:”1.3”,”SSR”:”50.0”,”yMean”:”14.5”,”SST”:”82.5”,”SAE”:”13.0”,”ND”:”0.0896551724137931”,”Explained Variance”:”5.0”,”MSE”:”2.85”} |