Predict power consumption using linear regression

5 Ansichten (letzte 30 Tage)
Hkl
Hkl am 28 Okt. 2022
Kommentiert: Star Strider am 28 Okt. 2022
I want to predict power consumption per hour with this data using linear regression.
How can i do this?

Akzeptierte Antwort

Star Strider
Star Strider am 28 Okt. 2022
There are 89 days in the data, so the data ‘wrap’ to 24 hours.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1172328/data2022.csv', 'VariableNamingRule','preserve')
T1 = 2159×5 table
time power_consumption(MW) temperature(¡ÆC) humidity(%) insolation(MJ/m2) ____ _____________________ ________________ ___________ _________________ 1 808.08 3.3 66 0 2 776.95 3.2 59 0 3 753.25 3 62 0 4 750.78 2.5 61 0 5 753.73 2.2 67 0 6 768.75 2.2 68 0 7 790.86 1.5 71 0 8 801.18 0.9 74 0.01 9 760.35 2 71 0.21 10 631.42 6.3 52 0.91 11 562.01 7.7 42 1.5 12 524.11 8.5 41 1.93 13 503.51 8.2 40 2 14 527.51 8.7 42 1.83 15 554.49 8.2 40 1.41 16 636.05 7.5 42 0.56
VN = T1.Properties.VariableNames;
nrDays = nnz(T1.time == 24)
nrDays = 89
mdl = fitlm(T1.time, T1.('power_consumption(MW)'))
mdl =
Linear regression model: y ~ 1 + x1 Estimated Coefficients: Estimate SE tStat pValue ________ _______ ______ __________ (Intercept) 698.61 5.0312 138.86 0 x1 5.2509 0.35226 14.906 6.6857e-48 Number of observations: 2159, Error degrees of freedom: 2157 Root Mean Squared Error: 113 R-squared: 0.0934, Adjusted R-Squared: 0.093 F-statistic vs. constant model: 222, p-value = 6.69e-48
[y,yci] = predict(mdl, T1.time);
figure
plot(T1.time, T1.('power_consumption(MW)'), '.')
hold on
plot(T1.time, y, '-r')
plot(T1.time, yci, '--r')
hold off
grid
xlabel(VN{1})
ylabel(strrep(VN{2},'_','\_'))
.
  4 Kommentare
Hkl
Hkl am 28 Okt. 2022
I appreciate it.
Star Strider
Star Strider am 28 Okt. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Florian Bidaud
Florian Bidaud am 28 Okt. 2022
Hi,
You can use the function polyfit with x being the time and y being the power consumption, you will have to choose n to fit your data as you want. In your data, I guess when the time comes back to 1 it means it's another day ? Then you will need to change 1,2,3,..., 23 to 25,26,27,....47 for the second day and so on

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by