A library for calculating features suitable for context recognition
Project description
Calculating features
Usage
-
Install the library with:
pip install build python -m build
Alternative:
pip install pep517 python -m pep517.build .
-
Basic usage is:
from cr_features.helper_functions import empatica1d_to_array, convert_to2d, frequency_features, hrv_features, gsr_features
from cr_features.calculate_features import calculate_features
import pandas as pd
pathToHrvCsv = "example_data/S2_E4_Data/BVP.csv"
windowLength = 500
# get an array of values from HRV empatica file
hrv_data, startTimeStamp, sampleRate = empatica1d_to_array(pathToHrvCsv)
# Convert the HRV data into 2D array
hrv_data_2D = convert_to2d(hrv_data, windowLength)
# Create a list with feature names
featureNames = []
featureNames.extend(hrv_features)
featureNames.extend(frequency_features)
pd.set_option('display.max_columns', None)
# Calculate features
calculatedFeatures = calculate_features(hrv_data_2D, fs=int(sampleRate), feature_names=featureNames)
- More usage examples are located in usage_examples.ipynb file
Features
- Features are returned (from calculateFeatures() function) in a Pandas DataFrame object.
- In the case if a feature couldn't be calculated (for example, if input signal is invalid), NaN value is returned.
- Further in this section, the list with descriptions of all possible features is presented.
GSR features:
These features are useful for 1D GSR(EDA) signals
mean
: mean of the signalstd
: standard deviation of signalq25
: 0.25 quantileq75
: 0.75 quantileqd
: q75 - q25deriv
: sum of gradients of the signalpower
: power of the signal (mean of squared signal)numPeaks
: number of EDA peaksratePeaks
: average number of peaks per secondpowerPeaks
: power of peaks (mean of signal at indexes of peaks)sumPosDeriv
: sum of positive derivatives divided by number of all derivativespropPosDeriv
: proportion of positive derivatives per all derivativesderivTonic
: sum of gradients of the tonicsigTonicDifference
: mean of tonic subtracted from signalfreqFeats
:maxPeakAmplitudeChangeBefore
: maximum peak amplitude change before peakmaxPeakAmplitudeChangeAfter
: maximum peak amplitude change after peakavgPeakAmplitudeChangeBefore
: average peak amplitude change before peakavgPeakAmplitudeChangeAfter
: average peak amplitude change after peakavgPeakChangeRatio
: avg_peak_increase_time / avg_peak_decrease_timemaxPeakIncreaseTime
: maximum peak increase timemaxPeakDecreaseTime
: maximum peak decrease timemaxPeakDuration
: maximum peak durationmaxPeakChangeRatio
: max_peak_increase_time / max_peak_decrease_timeavgPeakIncreaseTime
: average peak increase timeavgPeakDecreaseTime
: average peak decreade timeavgPeakDuration
: average peak durationmaxPeakResponseSlopeBefore
: maximum peak response slope before peakmaxPeakResponseSlopeAfter
: maximum peak response slope after peaksignalOverallChange
: maximum difference between samples (max(sig)-min(sig))changeDuration
: duration between maximum and minimum valueschangeRate
: change_duration / signal_overall_changesignificantIncrease
:significantDecrease
:
HRV features:
These features are useful for 1D HRV(BVP) signals.
If number of RR intervals (numRR) is less than length of sample / (2 * sampling rate)
(30 BPM) or greater than length of sample / (sampling rate / 4)
(240 BPM), BPM value is incorrect and thus, all other HRV features are set to NaN.
meanHr
: mean heart rateibi
: mean interbeat intervalsdnn
: standard deviation of the ibisdsd
: standard deviation of the differences between all subsequent R-R intervalsrmssd
: root of the mean of the list of squared differencespnn20
: the proportion of NN20 intervals to all intervalspnn50
: the proportion of NN50 intervals to all intervalssd
:sd2
:sd1/sd2
: sd / sd2 rationumRR
: number of RR intervals
Accelerometer features:
These features are useful for 3D signals from accelerometer
meanLow
: mean of low-pass filtered signalareaLow
: area under the low-pass filtered signaltotalAbsoluteAreaBand
: sum of absolute areas under the band-pass filtered x, y and z signaltotalMagnitudeBand
: square root of sum of squared band-pass filtered x, y and z componentsentropyBand
: entropy of band-pass filtered signalskewnessBand
: skewness of band-pass filtered signalkurtosisBand
: kurtosis of band-pass filtered signalpostureDistanceLow
: calculates difference between mean values for a given sensor (low-pass filtered)absoluteMeanBand
: mean of band-pass filtered signalabsoluteAreaBand
: area under the band-pass filtered signalquartilesBand
: quartiles of band-pass filtered signalinterQuartileRangeBand
: inter quartile range of band-pass filtered signalvarianceBand
: variance of band-pass filtered signalcoefficientOfVariationBand
: dispersion of band-pass filtered signalamplitudeBand
: difference between maximum and minimum sample of band-pass filtered signaltotalEnergyBand
: total magnitude of band-pass filtered signaldominantFrequencyEnergyBand
: ratio of energy in dominant frequencymeanCrossingRateBand
: the number of signal crossings with mean of band-pass filtered signalcorrelationBand
: Pearson's correlation between band-pass filtered axisquartilesMagnitudesBand
: quartiles at 25%, 50% and 75% per band-pass filtered signalinterQuartileRangeMagnitudesBand
: interquartile range of band-pass filtered signalareaUnderAccelerationMagnitude
: area under acceleration magnitudepeaksDataLow
: number of peaks, sum of peak values, peak avg, amplitude avgsumPerComponentBand
: sum per component of band-pass filtered signalvelocityBand
: velocity of the band-pass filtered signalmeanKineticEnergyBand
: mean kinetic energy 1/2*mV^2 of band-pass filtered signaltotalKineticEnergyBand
: total kinetic energy 1/2*mV^2 for all axes (band-pass filtered)squareSumOfComponent
: squared sum of componentsumOfSquareComponents
: sum of squared componentsaverageVectorLength
: mean of magnitude vectoraverageVectorLengthPower
: square mean of magnitude vectorrollAvgLow
: maximum difference of low-pass filtered roll samplespitchAvgLow
: maximum difference of low-pass filtered pitch samplesrollStdDevLow
: standard deviation of roll (calculated from low-pass filtered signal)pitchStdDevLow
: standard deviation of pitch (calculated from low-pass filtered signal)rollMotionAmountLow
: amount of wrist roll (from low-pass filtered signal) motionrollMotionRegularityLow
: regularity of wrist roll motionmanipulationLow
: manipulation of low-pass filtered signalsrollPeaks
: number of roll peaks, sum of roll peak values, roll peak avg, roll amplitude avgpitchPeaks
: number of pitch peaks, sum of pitch peak values, pitch peak avg, pitch amplitude avgrollPitchCorrelation
: correlation between roll and peak (obtained from low-pass filtered signal)
Gyroscope features:
These features are useful for 3D signals from gyroscope
meanLow
: mean of low-pass filtered signalareaLow
: area under the low-pass filtered signaltotalAbsoluteAreaLow
: sum of absolute areas under the low-pass filtered x, y and z signaltotalMagnitudeLow
: square root of sum of squared band-pass filtered x, y and z componentsentropyLow
: entropy of low-pass filtered signalskewnessLow
: skewness of low-pass filtered signalkurtosisLow
: kurtosis of low-pass filtered signalquartilesLow
: quartiles of low-pass filtered signalinterQuartileRangeLow
: inter quartile range of low-pass filtered signalvarianceLow
: variance of low-pass filtered signalcoefficientOfVariationLow
: dispersion of low-pass filtered signalamplitudeLow
: difference between maximum and minimum sample of low-pass filtered signaltotalEnergyLow
: total magnitude of low-pass filtered signaldominantFrequencyEnergyLow
: ratio of energy in dominant frequencymeanCrossingRateLow
: the number of signal crossings with mean of low-pass filtered signalcorrelationLow
: Pearson's correlation between low-pass filtered axisquartilesMagnitudeLow
: quartiles at 25%, 50% and 75% per low-pass filtered signalinterQuartileRangeMagnitudesLow
: interquartile range of band-pass filtered signalareaUnderMagnitude
: area under magnitudepeaksCountLow
: number of peaks in low-pass filtered signalaverageVectorLengthLow
: mean of low-pass filtered magnitude vectoraverageVectorLengthPowerLow
: square mean of low-pass filtered magnitude vector
Generic features:
These are generic features, useful for many different types of signals
autocorrelations
: autocorrelations of the given signal with lags 5, 10, 20, 30, 50, 75 and 100countAboveMean
: number of values in signal that are higher than the mean of signalcountBelowMean
: number of values in signal that are lower than the mean of signalmaximum
: maximum value of the signalminimum
: minimum value of the signalmeanAbsChange
: the mean of absolute differences between subsequent time series valueslongestStrikeAboveMean
: longest part of signal above meanlongestStrikeBelowMean
: longest part of signal below meanstdDev
: standard deviation of the signalmedian
: median of the signalmeanChange
: the mean over the differences between subsequent time series valuesnumberOfZeroCrossings
: number of crossings of signal on 0absEnergy
: the absolute energy of the time series which is the sum over the squared valueslinearTrendSlope
: a linear least-squares regression for the values of the time series versus the sequence from 0 to length of the time series minus oneratioBeyondRSigma
: ratio of values that are more than r*std(x) (so r sigma) away from the mean of signal. r in this case is 2.5binnedEntropy
: entropy of binned valuesnumOfPeaksAutocorr
: number of peaks of autocorrelationsnumberOfZeroCrossingsAutocorr
: number of crossings of autocorrelations on 0areaAutocorr
: area under autocorrelationscalcMeanCrossingRateAutocorr
: the number of autocorrelation crossings with meancountAboveMeanAutocorr
: umber of values in signal that are higher than the mean of autocorrelationsumPer
: sum per componentsumSquared
: squared sum per componentsquareSumOfComponent
: square sum of componentsumOfSquareComponents
:sum of square components
Frequency features:
These are frequency features, useful for many different types of signals. The signal is converted to power spectral density signal and features are calculated on this signal
fqHighestPeakFreqs
: three frequencies corresponding to the largest peaks added to featuresfqHighestPeaks
: three largest peaks added to featuresfqEnergyFeat
: energy calculated as the sum of the squared FFT component magnitudes, and normalizedfqEntropyFeat
: entropy of the FFT of the signalfqHistogramBins
: Binned distribution (histogram)fqAbsMean
: absolute mean of the raw signalfqSkewness
: skewness of the power spectrum of the datafqKurtosis
: kurtosis of the power spectrum of the datafqInterquart
: inter quartile range of the raw signal
Contributors
Several people contributed to making this library, both to its implemenetation and feature design: Vito Janko, Matjaž Bostič, Gašper Slapničar, Junoš Lukan, Nina Reščič, Simon Stankoski, Boža Cvetković, Mitja Luštrek
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cr-features-0.1.7.tar.gz
.
File metadata
- Download URL: cr-features-0.1.7.tar.gz
- Upload date:
- Size: 74.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1fa845ff7a066db3f4db7c42d2503ec48bc93b9b6585579e4cb06f36ee2eaaa |
|
MD5 | fd39c6183fa7b7475eaa0537362e51e0 |
|
BLAKE2b-256 | 49688073cee4d763001aae00f2c1eb1dbe7bf98b6f13e089d64a9ee3ec83d8c6 |