Spaces:
Runtime error
Runtime error
File size: 2,016 Bytes
381c43b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import numpy as np
from scipy.stats import skew, kurtosis
class StatisticalMeasures:
"""
A class dedicated to computing various statistical measures on a given feature array.
This utility class provides a method to compute a predefined set of statistical measures
which are commonly used in data analysis and feature extraction.
Methods:
--------
compute_statistical_measures(feature_array, measures=None):
Computes selected statistical measures from a provided numerical array.
"""
@staticmethod
def compute_statistical_measures(feature_array, measures=None):
if measures is None:
measures = ['mean', 'std', 'var', 'min', 'max', 'range', '25th_percentile', '50th_percentile', '75th_percentile', 'skew', 'kurtosis']
stats = {}
if 'mean' in measures:
stats['mean'] = np.mean(feature_array)
if 'std' in measures:
stats['std'] = np.std(feature_array)
if 'var' in measures:
stats['var'] = np.var(feature_array)
if 'min' in measures:
stats['min'] = np.min(feature_array)
if 'max' in measures:
stats['max'] = np.max(feature_array)
if 'range' in measures:
stats['range'] = np.ptp(feature_array)
if '25th_percentile' in measures:
stats['25th_percentile'] = np.percentile(feature_array, 25)
if '50th_percentile' in measures:
stats['50th_percentile'] = np.percentile(feature_array, 50)
if '75th_percentile' in measures:
stats['75th_percentile'] = np.percentile(feature_array, 75)
if 'skew' in measures and len(np.unique(feature_array)) > 1:
stats['skew'] = skew(feature_array)
else:
stats['skew'] = np.nan
if 'kurtosis' in measures and len(np.unique(feature_array)) > 1:
stats['kurtosis'] = kurtosis(feature_array)
else:
stats['kurtosis'] = np.nan
return stats
|