gpt4 book ai didi

validation - 接收,使用 CreateML 创建文本分类器模型时为 "An error was thrown and was not caught: The validation data provided must contain ..."

转载 作者:行者123 更新时间:2023-12-03 20:58:25 24 4
gpt4 key购买 nike

我正在使用 Playground 使用 CreateML 创建文本分类器模型并不断收到错误消息:

Playground execution terminated: An error was thrown and was not caught:
▿ The validation data provided must contain class.
▿ type : 1 element
- reason : "The validation data provided must contain class."

我的代码比较简单,使用了一个数据表中的两列。 textColumn 被标记为“text”,labelColumn 被标记为“class”:
import Cocoa
import CreateML

let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ ... .csv"))
let(trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5)
let sentimentClassifier = try MLTextClassifier(trainingData: trainingData, textColumn: "text", labelColumn: "class")
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "class")
let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100

我能找到的这与 Apple Developer Documentation 中提供的代码之间的唯一区别是,而不是
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "text", labelColumn: "class")

他们的文件是:
let evaluationMetrics = sentimentClassifier.evaluation(on: testingData)

如果我尝试使用 Apple Developer Documentation 中的行,Xcode 11.2.1 版会失败。

预先感谢您提供的任何帮助。

最佳答案

尝试这个!这个对我有用

let data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/justinmacbook/Desktop/twitter-sanders-apple3.csv"))

let (trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5 )

let sentimentClassifier = try MLTextClassifier(trainingData: trainingData, textColumn: "class", labelColumn: "text")

let evaluationMetrics = sentimentClassifier.evaluation(on: testingData, textColumn: "class", labelColumn: "text")

let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100

关于validation - 接收,使用 CreateML 创建文本分类器模型时为 "An error was thrown and was not caught: The validation data provided must contain ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59637050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com