This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install -q statsmodels | |
import numpy as np | |
import pandas as pd | |
import statsmodels.api as sm | |
import statsmodels.formula.api as smf | |
data = sm.datasets.get_rdataset('dietox', 'geepack').data | |
md = smf.mixedlm("Weight ~ Time", data, groups=data["Pig"], re_formula="~Time") | |
mdf = md.fit(method=["lbfgs"]) | |
print(mdf.summary()) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f,axes = plt.subplots(2,3, figsize=(10,5)) | |
for faces_ix, face_id in enumerate(df_clean.face_id.unique()[::-1]): | |
df_clean.query(f'face_id=={face_id}').plot.scatter(x='gaze_angle_x', y='gaze_angle_y', ax=axes[0][faces_ix]) | |
axes[0][faces_ix].scatter(0,0, marker='x', color = 'k') # draw origin. | |
axes[0][faces_ix].set(xlim=[-2,2], ylim=[-2,2], title=f'Gaze movement of face_id=={face_id}') | |
df_clean.query(f'face_id=={face_id}')[['gaze_angle_x', 'gaze_angle_y']].plot(ax=axes[1][faces_ix]) | |
axes[1][faces_ix].set(ylim=[-1.5,1.5]) | |
plt.tight_layout() | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Threshold data by 80% | |
df_clean = df[df.confidence>=.80] | |
# Plot all Action Unit time series. | |
au_regex_pat = re.compile(r'^AU[0-9]+_r$') | |
au_columns = df.columns[df.columns.str.contains(au_regex_pat)] | |
print("List of AU columns:", au_columns) | |
f,axes = plt.subplots(6, 3, figsize=(10,12), sharex=True, sharey=True) | |
axes = axes.flatten() | |
for au_ix, au_col in enumerate(au_columns): | |
sns.lineplot(x='frame', y=au_col, hue='face_id', data=df_clean, ax=axes[au_ix]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
x_regex_pat = re.compile(r'^x_[0-9]+$') | |
y_regex_pat = re.compile(r'^y_[0-9]+$') | |
x_locs = df.columns[df.columns.str.contains(x_regex_pat)] | |
y_locs = df.columns[df.columns.str.contains(y_regex_pat)] | |
palette = sns.color_palette("RdBu_r", 4) | |
avg_face_df = pd.DataFrame({'x_locs':df[x_locs].mean(axis=1), 'y_locs':df[y_locs].mean(axis=1), 'face_id': df.face_id}) | |
ax = sns.scatterplot(x='x_locs', y='y_locs', hue = 'face_id', data=avg_face_df, marker="+", palette=palette) | |
ax.set(xlim=[0, 1920], ylim=[1080,0], title="Before thresholding"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df.groupby('face_id').mean()['confidence'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See how many unique faces there are | |
print("Number of unique faces: ", len(df.face_id.unique()), "\nList of face_id's: ", df.face_id.unique()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
%config InlineBackend.figure_format = 'retina' | |
import pandas as pd, seaborn as sns | |
sns.set_style('white') | |
import matplotlib.pyplot as plt | |
# Load data | |
df = pd.read_csv('processed/video.csv') | |
# Remove empty spaces in column names. | |
df.columns = [col.replace(" ", "") for col in df.columns] |