ALINK(三十九):模型評估(四)多標籤分類評估 (EvalMultiLabelBatchOp)
阿新 • • 發佈:2021-06-19
多標籤分類評估 (EvalMultiLabelBatchOp)
Java 類名:com.alibaba.alink.operator.batch.evaluation.EvalMultiLabelBatchOp
Python 類名:EvalMultiLabelBatchOp
功能介紹
多label分類評估是對多label分類演算法的預測結果進行效果評估,支援下列評估指標。
f1
引數說明
名稱 |
中文名稱 |
描述 |
型別 |
是否必須? |
預設值 |
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\":\"[0.0, 1.0]\"}", "{\"object\":\"[0.0, 2.0]\"}"], ["{\"object\":\"[0.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"], ["{\"object\":\"[]\"}", "{\"object\":\"[0.0]\"}"], ["{\"object\":\"[2.0]\"}", "{\"object\":\"[2.0]\"}"], ["{\"object\":\"[2.0, 0.0]\"}", "{\"object\":\"[2.0, 0.0]\"}"], ["{\"object\":\"[0.0, 1.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"], ["{\"object\":\"[1.0]\"}", "{\"object\":\"[1.0, 2.0]\"}"] ]) source = BatchOperator.fromDataframe(df, "pred string, label string") evalMultiLabelBatchOp: EvalMultiLabelBatchOp = EvalMultiLabelBatchOp().setLabelCol("label").setPredictionCol("pred").linkFrom(source) metrics = evalMultiLabelBatchOp.collectMetrics() print(metrics)
Java 程式碼
import org.apache.flink.types.Row; import com.alibaba.alink.operator.batch.BatchOperator; import com.alibaba.alink.operator.batch.evaluation.EvalMultiLabelBatchOp; import com.alibaba.alink.operator.batch.source.MemSourceBatchOp; import com.alibaba.alink.operator.common.evaluation.MultiLabelMetrics; import org.junit.Test; import java.util.Arrays; import java.util.List; public class EvalMultiLabelBatchOpTest { @Test public void testEvalMultiLabelBatchOp() throws Exception { List <Row> df = Arrays.asList( Row.of("{\"object\":\"[0.0, 1.0]\"}", "{\"object\":\"[0.0, 2.0]\"}"), Row.of("{\"object\":\"[0.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"), Row.of("{\"object\":\"[]\"}", "{\"object\":\"[0.0]\"}"), Row.of("{\"object\":\"[2.0]\"}", "{\"object\":\"[2.0]\"}"), Row.of("{\"object\":\"[2.0, 0.0]\"}", "{\"object\":\"[2.0, 0.0]\"}"), Row.of("{\"object\":\"[0.0, 1.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"), Row.of("{\"object\":\"[1.0]\"}", "{\"object\":\"[1.0, 2.0]\"}") ); BatchOperator <?> source = new MemSourceBatchOp(df, "pred string, label string"); EvalMultiLabelBatchOp evalMultiLabelBatchOp = new EvalMultiLabelBatchOp().setLabelCol("label").setPredictionCol( "pred").linkFrom(source); MultiLabelMetrics metrics = evalMultiLabelBatchOp.collectMetrics(); System.out.println(metrics.toString()); } }
-------------------------------- Metrics: -------------------------------- microPrecision:0.7273 microF1:0.6957 subsetAccuracy:0.2857 precision:0.6667 recall:0.6429 accuracy:0.5476 f1:0.6381 microRecall:0.6667 hammingLoss:0.3333