У меня есть код, который предсказывает временные ряды, используя Tensorflow JS. Он был построен для прогнозирования данных по дням. Тем не менее, я пытаюсь делать прогнозы с данными в часах или минутах, и код имеет неравномерный результат в прогнозе. Я опубликую ниже часть кода, которая проверяет данные, а затем прогноз:
async onClickValidate() {
this.demo_4_loadingdata = true;
this.demo_4_div_display = true;
let inputs = this.data_sma_vec.map(function(inp_f) {
return inp_f['set'].map(function (val) { return val['price']; });
});
let pred_X = inputs.slice(Math.floor(this.input_trainingsize / 100 * inputs.length), inputs.length);
let pred_Y = await this.model.makePredictions(pred_X, this.trained_model['model']);
let timestamps_a = this.data_raw.map(function (val) { return val['timestamp']; });
let timestamps_b = this.data_raw.map(function (val) {
return val['timestamp'];
}).splice(this.input_windowsize, (this.data_raw.length - Math.floor((100-this.input_trainingsize) / 100 * this.data_raw.length)));
let timestamps_c = this.data_raw.map(function (val) {
return val['timestamp'];
}).splice(this.input_windowsize + Math.floor(this.input_trainingsize / 100 * this.data_raw.length), this.data_raw.length);
let sma = this.data_sma_vec.map(function (val) { return val['avg']; });
let prices = this.data_raw.map(function (val) { return val['price']; });
this.demo_4_graph = {
data: [
{ x: timestamps_a, y: prices, name: "Actual Price" },
{ x: timestamps_b, y: sma, name: "Training Label (SMA)" },
{ x: timestamps_c, y: pred_Y, name: "Predicted" }
],
layout: {height: 350, title: "Predict Results", autosize: true}
};
window.dispatchEvent(new Event('resize'));
this.demo_4_loadingdata = false;
}
async onClickPredict() {
this.demo_5_loadingdata = true;
this.demo_5_div_display = true;
let inputs = this.data_sma_vec.map(function(inp_f) {
return inp_f['set'].map(function (val) { return val['price']; });
});
let pred_X = [inputs[inputs.length-1]];
let pred_y = await this.model.makePredictions(pred_X, this.trained_model['model']);
let timestamps_d = this.data_raw.map(function (val) {
return val['timestamp'];
}).splice((this.data_raw.length - this.input_windowsize), this.data_raw.length);
let last_date = new Date(timestamps_d[timestamps_d.length-1]);
let add_days = 1;
if(this.input_temporal_resolutions == 'Weekly'){
add_days = 7;
}
last_date.setDate(last_date.getDate() + add_days);
let next_date = await this.formatDate(last_date.toString());
let timestamps_e = [next_date];
this.demo_5_graph = {
data: [
{ x: timestamps_d, y: pred_X[0], name: "Latest Trends" },
{ x: [timestamps_d[timestamps_d.length-1], timestamps_e[0]], y: [pred_X[0][timestamps_d.length-1], pred_y[0]], name: "Predicted Price" },
],
layout: {height: 350, title: "Predict Results", autosize: true}
};
window.dispatchEvent(new Event('resize'));
this.demo_5_loadingdata = false;
}
makePredictions(X, model) {
const predictedResults = model.predict(tf.tensor2d(X, [X.length, X[0].length]).div(tf.scalar(10))).mul(10);
return Array.from(predictedResults.dataSync());
}
Я подозреваю, что проблема в столбце данных CSV. Столбец «Дата» в файле в днях имеет формат «гггг-мм-дд». Хотя столбец «Дата» в файле в часах или минутах имеет формат «гггг-мм-дд чч: мм: сс».
Заранее благодарим за помощь.