我是机器学习的新手,我正在尝试使用 Keras 创建我的第一个应用程序。我正在使用名为 Keras .NET 的库,它允许我在 .NET 平台上使用 Keras API。我想为几家公司创建一个预测模型(股票价格预测)。我有我的公司的集合,我正在遍历它:
foreach (var company in companies)
{
await CreatePredictionModelAsync(company, cancellationToken);
}
CreatePredictionModelAsync 方法有时会调用以下方法:
private static PredictionModel BuildModel(
TransformationResult transformationResult,
Guid companyId,
int dataSetCount,
string predictionModelSelectedProperty)
{
var model = new Sequential();
var inputShape = new Keras.Shape(transformationResult.Domain.shape[1], 1);
model.Add(new LSTM(UnitAmount, return_sequences: true, input_shape: inputShape));
model.Add(new Dropout(DropoutRate));
model.Add(new LSTM(UnitAmount, return_sequences: true));
model.Add(new Dropout(DropoutRate));
model.Add(new LSTM(UnitAmount, return_sequences: true));
model.Add(new Dropout(DropoutRate));
model.Add(new LSTM(UnitAmount));
model.Add(new Dropout(DropoutRate));
model.Add(new Dense(DenseLayerOutputUnitAmount));
model.Compile(Optimizer, RegressionLoss);
model.Fit(transformationResult.Domain, transformationResult.ValueSet, BatchSize, Epochs);
var predictionModel = new PredictionModel(Guid.NewGuid())
{
Model = model,
ModelType = nameof(Sequential),
CreatedAt = DateTime.Now,
DataSetCount = dataSetCount,
Strategy = nameof(PredictionModelAdaptor),
MeasurementCalculationAttributeName = predictionModelSelectedProperty,
Offset = transformationResult.Offset,
Scale = transformationResult.Scale,
CompanyId = companyId
};
return predictionModel;
}
第一家公司的预测模型创建工作正常 - 该函数创建工作预测模型。然后循环移动到我公司集合的下一个元素。当第二个公司模型创建以 BuildModel 函数调用开始时,Keras 停止响应(我在控制台屏幕上看不到任何输出,程序在“var model = new Sequential()”行停止)。我不知道这是与 Keras 或我正在使用的库有关的问题。我正在使用 Tensorflow 后端。 这是我的环境规范: