File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ poetry install
39
39
# Install and activate the pre-commit hooks
40
40
poetry run setup
41
41
```
42
+ #### Alternative
43
+ Check the format by hand ` poetry run pre-commit run --all-files `
42
44
43
45
## ▶️ Usage
44
46
Original file line number Diff line number Diff line change
1
+ import matplotlib .pyplot as plt
2
+
1
3
from src .preprocessing .loader import load_raw_timeseries
2
- from src .preprocessing .scaling import normalize_power
4
+ from src .preprocessing .scaling import discretize_power , normalize_power
5
+
6
+
7
+ def plot_state_distribution (df ):
8
+
9
+ counts = df ["state" ].value_counts ().sort_index ()
10
+
11
+ plt .figure ()
12
+ plt .bar (counts .index , counts .values )
13
+ plt .xlabel ("State" )
14
+ plt .ylabel ("Anzahl Einträge" )
15
+ plt .title ("Verteilung der Einträge nach State" )
16
+ plt .xticks (counts .index )
17
+ plt .show ()
3
18
4
19
5
20
def main ():
6
21
df = load_raw_timeseries ()
7
22
print (df )
8
- df = normalize_power (df , col = "power" )
23
+ df = normalize_power (df )
24
+ print (df )
25
+ df = discretize_power (df )
9
26
print (df )
27
+ plot_state_distribution (df )
10
28
11
29
12
30
if __name__ == "__main__" :
Original file line number Diff line number Diff line change
1
+ import numpy as np
1
2
import pandas as pd
2
3
3
4
@@ -16,3 +17,18 @@ def normalize_power(
16
17
17
18
df [col ] = (df [col ] - p_min ) / denom
18
19
return df
20
+
21
+
22
+ def discretize_power (
23
+ df : pd .DataFrame ,
24
+ * ,
25
+ col : str = "power" ,
26
+ state_col : str = "state" ,
27
+ ) -> pd .DataFrame :
28
+ taus = np .array ([(k / 10 ) ** 2 for k in range (1 , 10 )], dtype = float )
29
+
30
+ values = df [col ].to_numpy ()
31
+ states = np .searchsorted (taus , values , side = "right" )
32
+
33
+ df [state_col ] = states
34
+ return df
You can’t perform that action at this time.
0 commit comments