【问题标题】:How can I alter this ML.NET code to input data through the console instead如何更改此 ML.NET 代码以通过控制台输入数据
【发布时间】:2022-01-03 12:16:48
【问题描述】:

我正在关注一个教程,它给了我这个示例代码。我想更改它,以便用户通过控制台而不是在代码中输入数据,但我不确定如何,有什么想法吗?

using MyMLApp;
// Add input data

var sampleData = new SentimentModel.ModelInput()
{
    Col0 = "Will never go here again!"
};

// Load model and predict output of sample data
var result = SentimentModel.Predict(sampleData);

// If Prediction is 1, sentiment is "Positive"; otherwise, sentiment is "Negative"
string sentiment = result.Prediction == 1 ? "Positive" : "Negative";
Console.WriteLine($"Text: {sampleData.Col0}\nSentiment: {sentiment}");

【问题讨论】:

    标签: c# machine-learning ml.net


    【解决方案1】:

    使用 Console.ReadLine()。可选择处理代码中的空输入。

    string? input = Console.ReadLine();
    var sampleData = new SentimentModel.ModelInput()
    {
        Col0 = input
    };
    

    【讨论】:

    • 非常感谢这个作品,我在没有 ?在字符串之后,这就是为什么它对我不起作用:)
    猜你喜欢
    • 2022-08-21
    • 1970-01-01
    • 2023-01-12
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多