-
Notifications
You must be signed in to change notification settings - Fork 1
/
statistical_features.py
53 lines (50 loc) · 1.69 KB
/
statistical_features.py
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
51
52
53
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as ss
class Features:
"""
Class containing methods that return statistical features of the data
data : (arr) array of the data that need to get statistical features from
"""
def __init__(self, data) -> None:
self.data = data
def get_skewness(self, bias=False):
"""
Parameters
----------
bias : (bool), whether bias is included in skewness
Returns
-------
skewness value in float
"""
return ss.skew(self.data, bias=bias)
def get_kurtosis(self, bias=False):
"""
Parameters
----------
bias : (bool) whether bias is included in kurtosis
Returns
-------
Kurtosis value in float
"""
return ss.kurtosis(self.data, bias=bias)
def summarize(self):
"""
Returns
-------
Print all summary statistics of the data passed to __init__ function
Summary statistics include: mean, median, standard deviation, mode, range, skewness, and kurtosis
"""
mean = np.average(self.data)
median = np.median(self.data)
sd = np.std(self.data)
mode = ss.mode(self.data)
range = np.max(self.data) - np.min(self.data)
print('Mean: ' + str(mean) + '\n' +
'Median: ' + str(median) + '\n' +
'Mode: ' + str(mode) + '\n' +
'Range: ' + str(range) + '\n' +
"Standard Deviation: " + str(sd) + '\n' +
'Skewness: ' + str(self.get_skewness()) + '\n' +
'Kurtosis: ' + str(self.get_kurtosis()) + '\n')