电力系统短期负荷预测(Python代码+数据+详细文章讲解)

 👨‍🎓个人主页:研学社的博客 

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🌈3 Python代码+数据+文章详细讲解

🎉4 参考文献


💥1 概述

本文包括以下5个部分

模型构建: 

训练出模型,然后就可以预测任意一天的96个时刻点的负荷。

📚2 运行结果

  预测日:

部分代码:

max_tempe = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '最高温度'), [2]].values / 20
min_tempe = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '最低温度'), [2]].values / 20
avg_tempe = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '平均温度'), [2]].values / 20
humidity = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '湿度'), [2]].values / 100
weather_data = np.concatenate([max_tempe, min_tempe, avg_tempe, humidity]).reshape((1, -1))


type_of_day = np.eye(7)[date.dayofweek]
holiday = np.eye(2)[int(is_holiday(date))]
time_data = np.concatenate([type_of_day, holiday]).reshape((1, -1))


features = np.concatenate([load_data, weather_data, time_data], axis=1).reshape(1, 685)
features = Tensor(features)

print('Loading model...')
net = load('./model.pt', map_location='cpu')

print('Start predicting...')
net.eval()
labels = net(features).detach().numpy() * 7000
print('=========预测==============')
max_tempe = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '最高温度'), [2]].values / 20
min_tempe = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '最低温度'), [2]].values / 20
avg_tempe = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '平均温度'), [2]].values / 20
humidity = df_weather.loc[(df_weather[0] == predict_date) & (df_weather[1] == '湿度'), [2]].values / 100
weather_data = np.concatenate([max_tempe, min_tempe, avg_tempe, humidity]).reshape((1, -1))


type_of_day = np.eye(7)[date.dayofweek]
holiday = np.eye(2)[int(is_holiday(date))]
time_data = np.concatenate([type_of_day, holiday]).reshape((1, -1))


features = np.concatenate([load_data, weather_data, time_data], axis=1).reshape(1, 685)
features = Tensor(features)

print('Loading model...')
net = load('./model.pt', map_location='cpu')

print('Start predicting...')
net.eval()
labels = net(features).detach().numpy() * 7000
print('=========预测==============')

🌈3 Python代码+数据+文章详细讲解

🎉4 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]陆继翔,张琪培,杨志宏,涂孟夫,陆进军,彭晖.基于CNN-LSTM混合神经网络模型的短期负荷预测方法[J].电力系统自动化,2019,43(08):131-137.

[2]罗澍忻,陆秋瑜,靳冰洁,麻敏华.考虑相关因素的长短时记忆网络短期负荷预测方法[J].机电工程技术,2019,48(12):126-129.

[3]王增平,赵兵,纪维佳,高欣,李晓兵.基于GRU-NN模型的短期负荷预测方法[J].电力系统自动化,2019,43(05):53-62.

[4] 牛腾腾.电力系统短期负荷预测  2017,011048 

  • 5
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 38
    评论
下面是一个简单的线性回归模型用于短期电力负荷预测Python 代码示例: ```python import pandas as pd import numpy as np from sklearn.linear_model import LinearRegression # 读取数据 data = pd.read_csv('load_data.csv') # 特征工程 data['hour'] = pd.to_datetime(data['time']).dt.hour data['weekday'] = pd.to_datetime(data['time']).dt.weekday data['month'] = pd.to_datetime(data['time']).dt.month data['day'] = pd.to_datetime(data['time']).dt.day data['year'] = pd.to_datetime(data['time']).dt.year data['lag1'] = data['load'].shift(1) data['lag2'] = data['load'].shift(2) data['lag3'] = data['load'].shift(3) # 去掉缺失值 data.dropna(inplace=True) # 划分训练集和测试集 train_data = data[data['year'] < 2019] test_data = data[data['year'] == 2019] # 选择特征和目标变量 x_train = train_data[['hour', 'weekday', 'month', 'day', 'lag1', 'lag2', 'lag3']] y_train = train_data['load'] x_test = test_data[['hour', 'weekday', 'month', 'day', 'lag1', 'lag2', 'lag3']] y_test = test_data['load'] # 训练模型 model = LinearRegression() model.fit(x_train, y_train) # 预测 y_pred = model.predict(x_test) # 评估模型 from sklearn.metrics import mean_squared_error, r2_score print("MSE:", mean_squared_error(y_test, y_pred)) print("R2 score:", r2_score(y_test, y_pred)) ``` 这段代码做了以下几件事情: 1. 读取电力负荷数据文件 `load_data.csv`。 2. 对时间戳进行特征工程,提取出小时、星期几、月份、日期和年份等特征,并添加滞后项作为特征。 3. 去掉缺失值。 4. 划分训练集和测试集。 5. 选择特征和目标变量。 6. 训练线性回归模型。 7. 进行预测。 8. 评估模型的性能,使用 MSE 和 R2 score 作为评估指标。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 38
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值