Esempio n. 1
0
class RNN(nn.Module):
    def __init__(self):
        super(RNN, self).__init__()

        self.rnn = nn.LSTM(input_size=1255, 
            hidden_size=2048, num_layers=2, batch_first=True, dropout=0.5)
        self.out_layer = nn.Linear(2048, 96)

    def forward(self, x):
        r_out, (h_n, h_c) = self.rnn(x, None)
        out = self.out_layer(r_out[:, -1, :])
        return out
#----------------------------------------------------------------------------------------------------
if __name__ == '__main__':
    print('Cutting dataset...')
    data = DataCut('data/x_96_by_7.xlsx', 'data/y_96.xlsx')
    data.cut()
    print('Data standardizating...')
    data_scaler = DataStandardScaler(data.train_xset, data.train_yset, 
        data.validation_xset, data.validation_yset)

    x_train_tensor = torch.from_numpy(np.array(data_scaler.x_train_standard)).float()
    y_train_tensor = torch.from_numpy(np.array(data_scaler.y_train_standard)).float()
    x_validation_tensor = torch.from_numpy(np.array(data_scaler.x_validation_standard)).float()
    y_validation_tensor = torch.from_numpy(np.array(data_scaler.y_validation_standard)).float()

    dataset = TDataset(data_tensor=x_train_tensor, target_tensor=y_train_tensor)

    BS = 64
    data_loader = Data.DataLoader(dataset=dataset, batch_size=BS, shuffle=True, drop_last=True)
Esempio n. 2
0
#coding=utf-8
from DataStandardScaler import *
from DataCut import *
from SummaryResults import *
from sklearn import svm
from sklearn.externals import joblib
import scipy.io as sio
from sklearn.multioutput import MultiOutputRegressor

print('Cutting dataset...')
data = DataCut('data13/x_96_by_13_with_week.xlsx', 'data13/y_96.xlsx')
data.cut()

print('Data standardizating...')
data_scaler = DataStandardScaler(data.train_xset, data.train_yset,
                                 data.validation_xset, data.validation_yset)

print('SVM training...')
# regressor = svm.SVR(C=0.1, gamma=0.01, max_iter=10000, kernel='rbf')
regressor = svm.SVR()
regressor = MultiOutputRegressor(regressor)
regressor.fit(data_scaler.x_train_standard, data_scaler.y_train_standard)

joblib.dump(regressor, 'models/svm_model.m')

print('Forecasting...')
y_fore_train = regressor.predict(data_scaler.x_train_standard)
y_fore_validation = regressor.predict(data_scaler.x_validation_standard)
data_scaler.reverse_trans(y_fore_train, y_fore_validation)
# data_scaler.reverse_trans(y_fore_validation=y_fore_validation, valid_only=1)
Esempio n. 3
0
#coding=utf-8
from DataStandardScaler import *
from DataCut import *
from SummaryResults import *
from sklearn.linear_model import LinearRegression
from sklearn.externals import joblib
import scipy.io as sio
from sklearn.multioutput import MultiOutputRegressor
# 前33个特征固定不动,滚动预测的时候对后12个lmp值进行滚动(从前往后依次为前1小时到前12小时)
print('Cutting dataset...')
data = DataCut('data/x_with_week.xlsx', 'data/y_96.xlsx')
data.cut()

print('Data standardizating...')
data_scaler = DataStandardScaler(data.train_xset, data.train_yset, 
    data.validation_xset, data.validation_yset)

print('Linear Regression training...')
regressor = LinearRegression(n_jobs = -1)
regressor = MultiOutputRegressor(regressor)
regressor.fit(data_scaler.x_train_standard, data_scaler.y_train_standard)
joblib.dump(regressor, 'models/linear_model.m')

print('Forecasting...')
print(data_scaler.x_train_standard)
input()
print(data_scaler.x_validation_standard)
input()
y_fore_train = regressor.predict(data_scaler.x_train_standard)
y_fore_validation = regressor.predict(data_scaler.x_validation_standard)
data_scaler.reverse_trans(y_fore_train, y_fore_validation)