|
@@ -6,6 +6,43 @@ import matplotlib.pyplot as plt
|
|
|
import seaborn as sns
|
|
import seaborn as sns
|
|
|
import scipy
|
|
import scipy
|
|
|
|
|
|
|
|
|
|
+def basic_stats(x, y):
|
|
|
|
|
+ """
|
|
|
|
|
+ Print basic descriptive statistics for the predictor and binary response.
|
|
|
|
|
+
|
|
|
|
|
+ Parameters
|
|
|
|
|
+ ----------
|
|
|
|
|
+ x : array-like
|
|
|
|
|
+ Predictor values.
|
|
|
|
|
+ y : array-like
|
|
|
|
|
+ Binary response values, expected to contain 0/1.
|
|
|
|
|
+ """
|
|
|
|
|
+ x = np.asarray(x)
|
|
|
|
|
+ y = np.asarray(y)
|
|
|
|
|
+
|
|
|
|
|
+ if x.ndim != 1:
|
|
|
|
|
+ raise ValueError("x must be a 1D array")
|
|
|
|
|
+ if y.ndim != 1:
|
|
|
|
|
+ raise ValueError("y must be a 1D array")
|
|
|
|
|
+ if len(x) != len(y):
|
|
|
|
|
+ raise ValueError("x and y must have the same length")
|
|
|
|
|
+
|
|
|
|
|
+ for cls in np.unique(y):
|
|
|
|
|
+ if cls not in (0, 1):
|
|
|
|
|
+ raise ValueError("y must contain only binary values (0 and 1)")
|
|
|
|
|
+
|
|
|
|
|
+ print("Predictor (x) statistics:")
|
|
|
|
|
+ print(f" Mean: {np.mean(x[y==cls]):.4f}")
|
|
|
|
|
+ print(f" Std: {np.std(x[y==cls], ddof=1):.4f}")
|
|
|
|
|
+ print(f" Min: {np.min(x[y==cls]):.4f}")
|
|
|
|
|
+ print(f" Max: {np.max(x[y==cls]):.4f}")
|
|
|
|
|
+ print()
|
|
|
|
|
+
|
|
|
|
|
+ print("Response (y) statistics:")
|
|
|
|
|
+ unique, counts = np.unique(y, return_counts=True)
|
|
|
|
|
+ for cls, count in zip(unique, counts):
|
|
|
|
|
+ print(f" Class {cls}: {count} samples ({100 * count / len(y):.2f}%)")
|
|
|
|
|
+
|
|
|
def plot_pdf(
|
|
def plot_pdf(
|
|
|
data1,
|
|
data1,
|
|
|
data2,
|
|
data2,
|