Predict power consumption using linear regression
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to predict power consumption per hour with this data using linear regression.
How can i do this?
댓글 수: 0
채택된 답변
Star Strider
2022년 10월 28일
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')
VN = T1.Properties.VariableNames;
nrDays = nnz(T1.time == 24)
mdl = fitlm(T1.time, T1.('power_consumption(MW)'))
[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
추가 답변 (1개)
Florian Bidaud
2022년 10월 28일
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!