Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120838679
helpers_modelweek.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jul 7, 11:02
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Jul 9, 11:02 (2 d)
Engine
blob
Format
Raw Data
Handle
27232106
Attached To
R9699 ML_students_works
helpers_modelweek.py
View Options
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
datetime
import
timedelta
from
helpers_clustering
import
create_weekly_matrix
def
weekly_model
(
energy_consumptions
,
normal_weeks
):
"""
Create a model week using the median value for every measure point in the week (672 points), using only the weeks
detected as normal by the clustering phase.
:param DataFrame energy_consumptions: formatted DataFrame containing measurements of energy consumption.
Index is of type DatetimeIndex,
column 'consumption' contains the measurement,
column 'week' contains the week code of the measurement.
:param vector normal_weeks: indexes of normal weeks
:output vector model_week: resulting model (length 672)
"""
# X = (num weeks, num data per week)
X
=
create_weekly_matrix
(
energy_consumptions
)
# Extract only normal weeks
X_model
=
X
[
normal_weeks
,
:]
# Compute the median for every measurement of the week (672 points) using t
# normal weeks
model_week
=
np
.
median
(
X_model
,
axis
=
0
)
return
model_week
Event Timeline
Log In to Comment