写出EEMD+STL+XGBoost+LightGBM+ConvLSTM的读取csv数据的多输入单输出的时序训练及预测代码,其中,前80%数据为测试集,后20%为测试集
时间: 2023-03-09 13:19:43 浏览: 212
基于EEMD和iPLS的球磨机负荷参数集成建模方法
EEMD:from pyeemd import EEMD
import pandas as pd#读取csv文件
data = pd.read_csv('data.csv')#分割训练集和测试集
train_data = data.iloc[:int(len(data)*0.8)]
test_data = data.iloc[int(len(data)*0.8):]#实例化EEMD
eemd = EEMD()#训练
eemd.fit(train_data)#预测
pred = eemd.predict(test_data)#输出预测结果
print(pred)STL:import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression#读取csv文件
data = pd.read_csv('data.csv')#分割训练集和测试集
train_data = data.iloc[:int(len(data)*0.8)]
test_data = data.iloc[int(len(data)*0.8):]#实例化STL
stl = LinearRegression()#训练
stl.fit(train_data)#预测
pred = stl.predict(test_data)#输出预测结果
print(pred)XGBoost:import xgboost as xgb
import pandas as pd#读取csv文件
data = pd.read_csv('data.csv')#分割训练集和测试集
train_data = data.iloc[:int(len(data)*0.8)]
test_data = data.iloc[int(len(data)*0.8):]#实例化XGBoost
xgboost = xgb.XGBRegressor()#训练
xgboost.fit(train_data)#预测
pred = xgboost.predict(test_data)#输出预测结果
print(pred)LightGBM:import lightgbm as lgb
import pandas as pd#读取csv文件
data = pd.read_csv('data.csv')#分割训练集和测试集
train_data = data.iloc[:int(len(data)*0.8)]
test_data = data.iloc[int(len(data)*0.8):]#实例化LightGBM
lightgbm = lgb.LGBMRegressor()#训练
lightgbm.fit(train_data)#预测
pred = lightgbm.predict(test_data)#输出预测结果
print(pred)ConvLSTM:import tensorflow as tf
import pandas as pd
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import ConvLSTM2D#读取csv文件
data = pd.read_csv('data.csv')#分割训练集和测试集
train_data = data.iloc[:int(len(data)*0.8)]
test_data = data.iloc[int(len(data)*0.8):]#实例化ConvLSTM
model = Sequential()
model.add(ConvLSTM2D(filters=64, kernel_size=(3,3), input_shape=(data.shape[1], data.shape[2], 1), padding='same', return_sequences=True))#训练
model.compile(loss='mse', optimizer='adam')
model.fit(train_data, epochs=100)#预测
pred = model.predict(test_data)#输出预测结果
print(pred)
阅读全文