Asp.net 时间序列预测ML.Net
进入asp.net 3/4年后,我从几周开始尝试学习ML.net,但我在预测时间序列方面遇到了一些问题 以下是我的主要问题:Asp.net 时间序列预测ML.Net,asp.net,machine-learning,forecasting,ml.net,Asp.net,Machine Learning,Forecasting,Ml.net,进入asp.net 3/4年后,我从几周开始尝试学习ML.net,但我在预测时间序列方面遇到了一些问题 以下是我的主要问题: 我想预测未来7天的价格,但我的数据分布不均匀,我如何才能迫使地平线预测未来7天的价格,而不仅仅是7次 我可以预测同一发动机中的所有3个值(单价、价格包10、价格包100)吗 每个项目都有自己的“寿命”(一个项目的价格可能下降,而另一个项目的价格可能上升),我需要为每个项目创建一个模型吗 即使我的数据集目前还不够大,我怎样才能从这些数据中得到更好的预测(文章末尾的预测结果
- 我想预测未来7天的价格,但我的数据分布不均匀,我如何才能迫使地平线预测未来7天的价格,而不仅仅是7次
- 我可以预测同一发动机中的所有3个值(单价、价格包10、价格包100)吗
- 每个项目都有自己的“寿命”(一个项目的价格可能下降,而另一个项目的价格可能上升),我需要为每个项目创建一个模型吗
- 即使我的数据集目前还不够大,我怎样才能从这些数据中得到更好的预测(文章末尾的预测结果)
string queryThisWeek = "SELECT * from Ressource where ressource ='" + ressourceToHandle.Ressource + "' and Date >= '" + startCurrentWeek + "' order by Date desc";
string queryBeforeThisWeek = "SELECT * from Ressource where ressource ='" + ressourceToHandle.Ressource + "' and Date < '" + startCurrentWeek + "' order by Date desc";
var connection = new SqliteConnection(ConnectionString);
var factory = DbProviderFactories.GetFactory(connection);
DatabaseSource dbSourceThisWeek = new DatabaseSource(factory, ConnectionString, queryThisWeek);
DatabaseSource dbSourceBeforeThisWeek = new DatabaseSource(factory, ConnectionString, queryBeforeThisWeek);
IDataView dataViewThisWeek = loader.Load(dbSourceThisWeek);
IDataView dataViewBeforeThisWeek = loader.Load(dbSourceBeforeThisWeek);
我的设置是否符合我的需要
评估我对每个价格的3个预测:
actual = mlContext.Data.CreateEnumerable<Ressources>(testData, true)
.Select(observed => observed.Prix1);
forecast = mlContext.Data.CreateEnumerable<RessourceLot1Prediction>(predictions, true)
.Select(prediction => prediction.PriceForecasted[0]);
// Calculate error (actual - forecast)
var metrics = actual.Zip(forecast, (actualValue, forecastValue) => actualValue - forecastValue);
// Get metric averages
var MAE = metrics.Average(error => Math.Abs(error)); // Mean Absolute Error
var RMSE = Math.Sqrt(metrics.Average(error => Math.Pow(error, 2))); // Root Mean Squared Error
actual = mlContext.Data.CreateEnumerable<Ressources>(testData, true)
.Select(observed => observed.Prix1);
forecast = mlContext.Data.CreateEnumerable<RessourceLot1Prediction>(predictions, true)
.Select(prediction => prediction.PriceForecasted[0]);
// Calculate error (actual - forecast)
var metrics = actual.Zip(forecast, (actualValue, forecastValue) => actualValue - forecastValue);
// Get metric averages
var MAE = metrics.Average(error => Math.Abs(error)); // Mean Absolute Error
var RMSE = Math.Sqrt(metrics.Average(error => Math.Pow(error, 2))); // Root Mean Squared Error
var forecastEngineLot1 = forecaster.CreateTimeSeriesEngine<Ressources, RessourceLot1Prediction>(core.mlContext);
forecastEngineLot1.CheckPoint(core.mlContext, modelPath);
IEnumerable<string> forecastOutput =
mlContext.Data.CreateEnumerable<Ressources>(testData, reuseRowObject: false)
.Take(horizon)
.Select((Ressources ress, int index) =>
{
string Date = ress.Date.ToString("dd-MM-yyyy hh:mm");
float actualPrice = ress.Prix1;
float lowerEstimate = Math.Max(0, forecast.LowerBoundPrice[index]);
float estimate = forecast.PriceForecasted[index];
float upperEstimate = forecast.UpperBoundPrice[index];
return $"Date: {Date}\n" +
$"Actual price: {actualPrice}\n" +
$"Lower Estimate: {lowerEstimate}\n" +
$"Forecast: {estimate}\n" +
$"Upper Estimate: {upperEstimate}\n";
});
public class Ressources
{
[LoadColumn(0)]
public string Ressource { get; set; }
[LoadColumn(1)]
public float Price1 { get; set; }
[LoadColumn(2)]
public float Price10 { get; set; }
[LoadColumn(3)]
public float Price100 { get; set; }
[LoadColumn(4)]
public float PriceAverage { get; set; }
[LoadColumn(5)]
public DateTime Date { get; set; }
}
public class RessourceLot1Prediction
{
public float[] PriceForecasted { get; set; }
public float[] LowerBoundPrice { get; set; }
public float[] UpperBoundPrice { get; set; }
}
public class RessourceLot10Prediction
{
public float[] PriceForecasted { get; set; }
public float[] LowerBoundPrice { get; set; }
public float[] UpperBoundPrice { get; set; }
}
public class RessourceLot100Prediction
{
public float[] PriceForecasted { get; set; }
public float[] LowerBoundPrice { get; set; }
public float[] UpperBoundPrice { get; set; }
}