def estimate_transition_matrix(df):
    transition_count = np.zeros((class_set, class_set))
    df = df.loc[(df['radar'] == df.radar.unique()[0])]
    sequences = df['file_index'].unique()
    for sequence_index in sequences:
        df_seq = df.loc[(df['file_index'] == sequence_index)].sort_values('time').reset_index(drop=True)
        previous_state = None
        for (i, row) in df_seq.iterrows():
            state = row['lable']
            if (not previous_state):
                previous_state = state
                continue
            transition_count[((state - 1), (previous_state - 1))] += 1
            previous_state = state
    transition_matrix = (transition_count / transition_count.sum(axis=0, keepdims=1))
    transition_matrix = (transition_matrix / transition_matrix.sum(axis=0, keepdims=1))
    return transition_matrix
def estimate_transition_matrix(df):
    transition_count = np.zeros((class_set, class_set))
    df = df.loc[(df['radar'] == df.radar.unique()[0])]
    sequences = df['file_index'].unique()
    for sequence_index in sequences:
        df_seq = df.loc[(df['file_index'] == sequence_index)].sort_values('time').reset_index(drop=True)
        previous_state = None
        for (i, row) in df_seq.iterrows():
            state = row['lable']
            if (not previous_state):
                previous_state = state
                continue
            transition_count[((state - 1), (previous_state - 1))] += 1
            previous_state = state
    transition_matrix = (transition_count / transition_count.sum(axis=0, keepdims=1))
    transition_matrix = (transition_matrix / transition_matrix.sum(axis=0, keepdims=1))
    return transition_matrix