Deviations from trajectory

deviations(df=None, traces=None)

Calculate the Mean Absolute Deviation (MAD) for the given DataFrame.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘y’ column.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

Returns:

A dictionary with keys as (sessionId) and values as dictionaries with ‘mad_mean’ (mean of maximum absolute deviations), ‘mad_max’ (maximum absolute deviation across all traces), ‘mad_min’ (minimum absolute deviation across all traces) and ‘aad’ (average absolute deviation).

Return type:

dict

direction_changes(df=None, traces=None, per_traces=False, per_user=False, threshold=0.7853981633974483)

Calculate the number of direction changes in the given DataFrame.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘x’ and ‘y’ columns.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

  • per_traces (bool?) – Defaults to False. Whether to return the result for each trace separately. If False, returns the total count as an integer.

  • per_user (bool?) – Defaults to False. If True, then it computes the number of direction changes for each user. The main difference with per traces is that this option does not segment the DataFrame, computing the total number of changes through the DataFrame.

Returns:

An integer if per_traces and per_user is False. dict (dict[str,list[int]]): A dictionary if per_traces is True or if per_user is True, with sessionIds as keys and the number of direction changes on each trace as an integer.

Return type:

int (int)

x_flips(df=None, traces=None, threshold=0.1, per_traces=False, per_user=False)

Calculate the number of x-direction flips in the given DataFrame.

Note

Metric Context Specificity: If performed by trace, it will sum the flips of all traces in a session. A session that has a flip between the end of a trace and the beginning of the next one will not be counted as a flip as computations are done trace by trace, so if you want to consider those flips, you should compute them on the whole dataframe or consider the traces as a single one.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘x’ and ‘y’ columns.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

  • threshold (float) – The threshold for considering a flip.

  • per_traces (bool?) – Defaults to False. Whether to return the result for each trace separately. If False, returns the total count as an integer.

  • per_user (bool?) – Defaults to False. If True, then it computes the number of direction changes for each user. The main difference with per traces is that this option does not segment the DataFrame, computing the total number of changes through the DataFrame.

Returns:

The number of x-direction flips or a dictionary with the count for each session if per_traces and per_user are False. dict (dict[str,list[int]]): A dictionary if per_traces is True or if per_user is True, with sessionIds as keys and the number of direction changes on each trace as an integer.

Return type:

int

y_flips(df=None, traces=None, threshold=0.1, per_traces=False, per_user=False)

Calculate the number of y-direction flips in the given DataFrame.

Note

Metric Context Specificity: If performed by trace, it will sum the flips of all traces in a session. A session that has a flip between the end of a trace and the beginning of the next one will not be counted as a flip as computations are done trace by trace, so if you want to consider those flips, you should compute them on the whole dataframe or consider the traces as a single one.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘x’ and ‘y’ columns.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

  • threshold (float) – The threshold for considering a flip.

  • per_traces (bool?) – Defaults to False. Whether to return the result for each trace separately. If False, returns the total count as an integer.

  • per_user (bool?) – Defaults to False. If True, then it computes the number of direction changes for each user. The main difference with per traces is that this option does not segment the DataFrame, computing the total number of changes through the DataFrame.

Returns:

The number of y-direction flips or a dictionary with the count for each session.

Return type:

int | dict