Advanced All Features
This comprehensive example calculates all available features in the library, demonstrating the full power of the EyeFeatures toolbox.
1"""
2Advanced All Features Example
3=============================
4
5This example calculates ALL available features in the library.
6It serves as a benchmark and a demonstration of the comprehensive capability of EyeFeatures.
7"""
8
9import pandas as pd
10
11from eyefeatures.features.dist import (
12 DFDist,
13 DTWDist,
14 EucDist,
15 EyeAnalysisDist,
16 HauDist,
17 MannanDist,
18 MultiMatchDist,
19 ScanMatchDist,
20 SimpleDistances,
21 TDEDist,
22)
23from eyefeatures.features.extractor import Extractor
24from eyefeatures.features.measures import (
25 CorrelationDimension,
26 FractalDimension,
27 FuzzyEntropy,
28 HHTFeatures,
29 HurstExponent,
30 LyapunovExponent,
31 PhaseEntropy,
32 RQAMeasures,
33 SaccadeUnlikelihood,
34 ShannonEntropy,
35 SpectralEntropy,
36)
37from eyefeatures.features.stats import (
38 FixationFeatures,
39 MicroSaccadeFeatures,
40 RegressionFeatures,
41 SaccadeFeatures,
42)
43
44# Load data
45fixations_df = pd.read_csv("data/fixations/fixations_subset.csv")
46print("Loaded fixations data:", fixations_df.shape)
47
48# Leave several texts(for speedup)
49fixations_df = fixations_df[fixations_df["tekst"].isin([1, 10, 17])]
50print("Selected data (several texts):", fixations_df.shape)
51
52
53# Initialize ALL transformers
54transformers = [
55 # Stats
56 FixationFeatures(),
57 SaccadeFeatures(),
58 RegressionFeatures(),
59 MicroSaccadeFeatures(),
60 # Measures
61 HurstExponent(coordinate="norm_pos_x", n_iters=5),
62 ShannonEntropy(),
63 SpectralEntropy(),
64 FuzzyEntropy(),
65 PhaseEntropy(),
66 LyapunovExponent(T=2),
67 FractalDimension(),
68 CorrelationDimension(),
69 SaccadeUnlikelihood(),
70 HHTFeatures(max_imfs=2),
71 RQAMeasures(),
72 # Distances
73 SimpleDistances(methods=["euc", "hau"]),
74 EucDist(),
75 HauDist(),
76 DTWDist(),
77 ScanMatchDist(t_bin=50),
78 MannanDist(),
79 EyeAnalysisDist(),
80 DFDist(),
81 TDEDist(k=1),
82 MultiMatchDist(),
83]
84
85extractor = Extractor(
86 features=transformers,
87 x="norm_pos_x",
88 y="norm_pos_y",
89 t="start_timestamp",
90 duration="duration",
91 dispersion="dispersion",
92 aoi="AOI",
93 pk=["Participant"],
94 path_pk=["Participant"],
95 return_df=True,
96)
97
98print("\nCalculating all features in the library (this may take a moment)...")
99features_df = extractor.fit_transform(fixations_df)
100
101for participant_id in (0, 1):
102 assert features_df.iloc[participant_id, :].isnull().sum() == 0
103
104print("\nCalculation complete.")
105print(f"Feature Matrix Shape: {features_df.shape}")
106print(f"Total Features Evaluated: {features_df.shape[1]}")
107
108assert features_df.shape[1] == 258