add some mathematical functions ; mostly from the math lessons themselfs
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from typing import List
|
||||
|
||||
def r_boxplot(arr: List[float], label: str) -> None:
|
||||
data = np.asarray(arr, dtype=float)
|
||||
p = np.percentile(data, [0, 25, 50, 75, 100])
|
||||
|
||||
fig, ax = plt.subplots(figsize=(6, 2.5))
|
||||
ax.boxplot(data, positions=[1], vert=False, patch_artist=True, widths=0.6)
|
||||
|
||||
labels = ["0%", "25%", "50%", "75%", "100%"]
|
||||
for val, lab in zip(p, labels):
|
||||
ax.axvline(val, color="#ff0000", linestyle="--", linewidth=0.8, alpha=0.9)
|
||||
|
||||
ax.text(0.5, 1.15, label, transform=ax.transAxes,
|
||||
ha="center", va="bottom", fontsize=10, fontweight="bold", color="black")
|
||||
|
||||
ax.set_yticks([1])
|
||||
ax.xaxis.grid(True, linestyle="--", alpha=0.3)
|
||||
|
||||
fig.tight_layout()
|
||||
fig.subplots_adjust(top=0.78)
|
||||
plt.show()
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,13 @@
|
||||
# helper for standard deviation
|
||||
# book page: 235
|
||||
# AGPL-3.0
|
||||
import numpy as np
|
||||
|
||||
def r_stddev(lst: list, r_dtype) -> float:
|
||||
r_arr = np.asarray(lst)
|
||||
return float(np.std(r_arr, dtype=r_dtype))
|
||||
|
||||
def implemenentation():
|
||||
print(r_stddev(sorted([6,4,9,5,7,11,5,3,7,5,4]),float))
|
||||
|
||||
implemenentation()
|
||||
Reference in New Issue
Block a user