ios - 弃用警告 在 Create ML 中初始化时使用 DataSource 而不是 MLDataTable

标签 ios swift coreml createml

我正在 Xcode 14.3 Playgrounds 中运行以下代码。我使用的是 macOS Ventura 13.1。

let csvFile = Bundle.main.url(forResource: "all-data", withExtension: "csv")!
let dataTable = try MLDataTable(contentsOf: csvFile)


let (classifierEvaluationTable, classifierTrainingTable) = dataTable.randomSplit(by: 0.20, seed: 5)

let classifier = try MLTextClassifier(trainingData: classifierTrainingTable, textColumn: "text", labelColumn: "sentiment")

我收到以下警告:

'init(trainingData:textColumn:labelColumn:parameters:)' was deprecated in macOS 13.0: Use DataSource instead of MLDataTable when initializing.

问题是没有关于如何创建 DataFrame 或 DataSource 的文档。

最佳答案

处理该案子需要一些时间。我们可以使用DataFrame,这样警告就可以避免。目前尚未弃用。

有一个例子,我发现如何重写它。

以前的版本:

let csvFile = Bundle.main.url(forResource: "all-data", withExtension: "csv")!
let dataTable = try MLDataTable(contentsOf: csvFile)


let (classifierEvaluationTable, classifierTrainingTable) = dataTable.randomSplit(by: 0.20, seed: 5)

let classifier = try MLTextClassifier(trainingData: classifierTrainingTable, textColumn: "text", labelColumn: "sentiment")

更新:

另外添加这个

导入表格数据

let csvFile = Bundle.main.url(forResource: "all-data", withExtension: "csv")!
let dataFrame = DataFrame(contentsOfCSVFile: csvFile)

let (classifierEvaluationSlice, classifierTrainingSlice) = dataFrame.split(by: 0.20, seed: 5)


let classifierTrainingFrame = DataFrame(classifierTrainingSlice)
let classifier = try MLTextClassifier(trainingData: classifierEvaluationFrame, textColumn: "text", labelColumn: "sentiment"))

此外,我们可以比较和打印指标并保存文件:

let classifierEvaluationFrame = DataFrame(classifierEvaluationSlice)
let metrics = model.evaluation(on: classifierEvaluationFrame, textColumn: "text", labelColumn: "sentiment"))
print(metrics.classificationError)
    
let modelPath = URL(filePath: "YourPath/YourModelName.mlmodel")
try model.write(to: modelPath)

关于ios - 弃用警告 在 Create ML 中初始化时使用 DataSource 而不是 MLDataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76326314/

相关文章:

swift - 停止 SKPhysicsBody 运动中

machine-learning - ARKit 图像检测 - 许多图像

ios - CoreML : "Unexpected error processing model" error sometimes occurring

ios - Haneke 不使用 Swift 来使用 AWS SDK

android - * native react * |使用未知 URL 链接 => canOpenURL(url)?

ios - Realm 对象改变了,那个对象的另一个副本也改变了,为什么?

coreml - 视觉框架与 CoreML 模型类

iphone - 无法使用ALAssets返回的路径URL加载图像

ios - swift 2 : @objc protocol and enum array

ios - 如何使用 Swift 从多个按钮中一次仅突出显示一个按钮