我正在使用 ML.NET 回归模型来预测时间序列数据,是的,我知道有专门针对时间序列的类,但我需要它在我的论文中进行比较。但是当我更改模型甚至删除模型时,预测值不会改变。 这是带有模型的课程:
internal class FastTree
{
internal static List<SingleValueForecast> predict(List<Value> trainData, int scope)
{
var context = new MLContext();
var data = context.Data.LoadFromEnumerable(trainData);
var pipeline = context.Transforms.CopyColumns("Label", "zatizeniCerpani")
.Append(context.Transforms.Concatenate("Features", "Year", "Month", "Day","Hour"))
.Append(context.Regression.Trainers.FastTree("Label", "Features"));
var model = pipeline.Fit(data);
var predictionEngine = context.Model.CreatePredictionEngine<Value, SingleValueForecast>(model);
var forecasts = new List<SingleValueForecast>();
var last = trainData.Last();
forecasts.Add( new SingleValueForecast(last.date,last.zatizeniCerpani));
for (int i = 0; i < scope; i++)
{
var input = forecasts.Last();
var forecast = predictionEngine.Predict(input.toValue());
forecasts.Add(forecast);
}
return forecasts;
}
}
这是相关的类:
public class Value
{
public DateTime date { get; set; }
public float Year { get; set; }
public float Month { get; set; }
public float Day { get; set; }
public float Hour { get; set; }
public float zatizeniCerpani { get; set; }
public Value(DateTime date, float zatizeniCerpani)
{
this.date = date;
this.zatizeniCerpani = zatizeniCerpani;
this.Year = date.Year;
this.Month = date.Month;
this.Day = date.Day;
this.Hour = date.Hour;
}
}
public class SingleValueForecast
{
public float Year { get; set; }
public float Month { get; set; }
public float Day { get; set; }
public float Hour { get; set; }
public float zatizeniCerpani { get; set; }
public DateTime date { get; set; }
public SingleValueForecast(DateTime date, float zatizeniCerpani)
{
this.date = date;
this.zatizeniCerpani = zatizeniCerpani;
this.Year = date.Year;
this.Month = date.Month;
this.Day = date.Day;
this.Hour = date.Hour;
}
public SingleValueForecast()
{ }
public Value toValue()
{
return new Value(date,zatizeniCerpani);
}
}
我期望在更改我正在使用的模型时值会发生变化。但对于任何模型,甚至没有模型,值都是相同的。
我将非常感谢您的帮助。
编辑: 好吧,我错过了很多东西,但主要是它没有输出列,所以我总是得到相同的值,这里是固定的 SingleValueForecast 类:
public class SingleValueForecast
{
public float Year { get; set; }
public float Month { get; set; }
public float Day { get; set; }
public float Hour { get; set; }
public float zatizeniCerpani { get; set; }
public DateTime date { get; set; }
[ColumnName("Score")]
public float PredictedZatizeniCerpani { get; set; }
public SingleValueForecast(DateTime date, float zatizeniCerpani)
{
this.date = date;
this.zatizeniCerpani = zatizeniCerpani;
this.Year = date.Year;
this.Month = date.Month;
this.Day = date.Day;
this.Hour = date.Hour;
}
public SingleValueForecast()
{ }
public Value toValue()
{
return new Value(date,zatizeniCerpani);
}
}
找到解决方案,这是我的错误。编辑了问题。