Skip to content
Snippets Groups Projects
Commit 069644ba authored by leufen1's avatar leufen1
Browse files

New functions to extract categorical data

parent c43e1ade
No related branches found
No related tags found
No related merge requests found
import numpy as np
def most_common_value(values):
"""Get most common value from array"""
return np.bincount(values.astype(int)).argmax()
def relative_frequency(values, decimals=6, bins=0):
"""Get the relative frequency of each possible class"""
if bins > 0:
f = np.round(np.bincount(values.astype(int), minlength=int(bins)) / len(values), decimals)
else:
f = np.round(np.bincount(values.astype(int)) / len(values), decimals)
return f
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment