【发布时间】:2020-07-06 20:47:50
【问题描述】:
我试图使用 ML.NET 使用小型数据集(760 个项目)进行一些简单的线性回归测试,但是当我调用 Fit() 来获取变压器时,它会抛出错误“列‘时间’的值为DateTime,与之前观察到的 Single 类型不同。"
好像函数混淆了csv中每一列的类型?
代码
public class PriceData
{
[ColumnName("Time")]
[LoadColumn(0)]
public DateTime Time;
[ColumnName("ClosePrice")]
[LoadColumn(1)]
public float ClosePrice;
}
public class DemandPrediction
{
[ColumnName("Score")]
public float ApproximationScore;
}
static string URL = "https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=USD-BTC&tickInterval=day";
public static void Main(string[] args)
{
try
{
List<PriceData> priceData = new List<PriceData>();
DownloadData(URL,ref priceData);
var context = new MLContext();
var data = context.Data.LoadFromTextFile<PriceData>("data.csv",hasHeader:false,separatorChar:',');
var pipeline = context.Transforms.Concatenate(outputColumnName:"PriceData",
nameof(PriceData.Time),
nameof(PriceData.ClosePrice)
).AppendCacheCheckpoint(context);
var trainerType = context.Regression.Trainers.OnlineGradientDescent(lossFunction: new TweedieLoss());
var fullPipeline = pipeline.Append(trainerType);
var model = pipeline.Fit(data);
var predictions = model.Transform(data);
var metrics = context.Regression.Evaluate(
data: predictions,
labelColumnName: "ClosePrice",
scoreColumnName: "Score");
var sample = new PriceData { Time =Convert.ToDateTime("7/6/2020 12:00:00 AM"), ClosePrice = 9273.18f };
// create a prediction engine
var engine = context.Model.CreatePredictionEngine<PriceData, DemandPrediction>(model);
// make the prediction
var prediction = engine.Predict(sample);
Console.ReadKey();
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
}```
【问题讨论】:
-
使用时间序列预测而不是回归模型可能会更好 - docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/…
-
@Jon 在准确性方面有什么区别?
-
每当我尝试调用函数 mlContext.Forecasting.ForecastBySsa 时,它都不会出现在我的 ML.NET 版本 1.5.0 中是否有一些更新删除了该函数?编辑:docs.microsoft.com/en-us/dotnet/api/…
-
它有自己的 NuGet - nuget.org/packages/Microsoft.ML.TimeSeries