Skip to content

Commit 139c26b

Browse files
diskretisieren der Daten und plotten
1 parent cd33568 commit 139c26b

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ poetry install
3939
# Install and activate the pre-commit hooks
4040
poetry run setup
4141
```
42+
#### Alternative
43+
Check the format by hand `poetry run pre-commit run --all-files`
4244

4345
## ▶️ Usage
4446

src/main.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1+
import matplotlib.pyplot as plt
2+
13
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()
318

419

520
def main():
621
df = load_raw_timeseries()
722
print(df)
8-
df = normalize_power(df, col="power")
23+
df = normalize_power(df)
24+
print(df)
25+
df = discretize_power(df)
926
print(df)
27+
plot_state_distribution(df)
1028

1129

1230
if __name__ == "__main__":

src/preprocessing/scaling.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import pandas as pd
23

34

@@ -16,3 +17,18 @@ def normalize_power(
1617

1718
df[col] = (df[col] - p_min) / denom
1819
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

0 commit comments

Comments
 (0)