In [90]:
import matplotlib

matplotlib.use('TkAgg')
%matplotlib inline
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [0, 3, 7])
plt.show()



In [91]:
import pandas as pd
import csv
import numpy as np
from math import sqrt
from sklearn.feature_extraction.text import CountVectorizer
countVector = CountVectorizer(min_df=1)
import re

In [92]:
# Gautam's video input
with open('./data/RAW_abhyudaya/final_gb1.csv') as f:
    reader = csv.reader(f)
    affectivavideooutput = list(reader)

with open('./data/RAW_abhyudaya/final_gb4.csv') as f:
    reader = csv.reader(f)
    affectivavideooutput2 = list(reader)
    
with open('./data/RAW_abhyudaya/final_gb6.csv') as f:
    reader = csv.reader(f)
    affectivavideooutput3 = list(reader)
    
with open('./data/RAW_abhyudaya/final_gb7.csv') as f:
    reader = csv.reader(f)
    affectivavideooutput4 = list(reader)

affectivavideooutput2.pop(0)
affectivavideooutput3.pop(0)
affectivavideooutput4.pop(0)

print len(affectivavideooutput)

affectivavideooutput.extend(affectivavideooutput2)
print len(affectivavideooutput)
affectivavideooutput.extend(affectivavideooutput3)
print len(affectivavideooutput)
affectivavideooutput.extend(affectivavideooutput4)

print len(affectivavideooutput)
print affectivavideooutput[0]


9467
11419
12972
14648
['', 'TimeStamp', 'interocularDistance', 'glasses', 'pitch', 'yaw', 'roll', 'joy', 'fear', 'disgust', 'sadness', 'anger', 'surprise', 'contempt', 'valence', 'engagement', 'smile', 'innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 'mouthOpen', 'smirk', 'eyeClosure', 'attention', 'eyeWiden', 'cheekRaise', 'lidTighten', 'dimpler', 'lipStretch', 'jawDrop', 'relaxed', 'smiley', 'laughing', 'kissing', 'disappointed', 'rage', 'smirk.1', 'wink', 'stuckOutTongueWinkingEye', 'stuckOutTongue', 'flushed', 'scream', 'FRUSTRATED', 'TIRED', 'ENGAGED', 'CLASS']

In [93]:
affectivavideooutput.pop(0)
affectivadataframe = pd.DataFrame(affectivavideooutput, 
                                columns = ['', 'TimeStamp', 'interocularDistance', 'glasses', 'pitch', 'yaw', 'roll', 'joy', 
                                           'fear', 'disgust', 'sadness', 'anger', 'surprise', 'contempt', 'valence', 
                                           'engagement', 'smile', 'innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 
                                           'upperLipRaise', 'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 
                                           'lipSuck', 'mouthOpen', 'smirk', 'eyeClosure', 'attention', 'eyeWiden',
                                           'cheekRaise', 'lidTighten', 'dimpler', 'lipStretch', 'jawDrop', 'relaxed',
                                           'smiley', 'laughing', 'kissing', 'disappointed', 'rage', 'smirk.1', 'wink', 
                                           'stuckOutTongueWinkingEye', 'stuckOutTongue', 'flushed',
                                           'scream', 'frustrated', 'tired', 'engaged', 'class'])
affectivadataframe[0:10]
#drop the columns that are outright irrelevant for data analysis
affectivadataframe = affectivadataframe.drop(['','TimeStamp'],axis=1)
#affectivadataframe[-10:]
print len(affectivadataframe)


14647

In [94]:
import statsmodels.api as sm
X= affectivadataframe[['smile','innerBrowRaise','browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'attention', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop','engaged','frustrated','tired']].copy()

for column in X.columns:
     X[column]=X[column].apply(lambda x:float(x.replace('"','').replace("\n",'').replace('nan','')))

X['engaged'] = X['engaged'].apply(lambda x:int(x))
X['frustrated'] = X['frustrated'].apply(lambda x:int(x))
X['tired'] = X['tired'].apply(lambda x:int(x))

In [95]:
import sklearn.utils
df = sklearn.utils.shuffle(X)
df = df.reset_index(drop=True)
df[0:10]


Out[95]:
smile innerBrowRaise browRaise browFurrow noseWrinkle upperLipRaise lipCornerDepressor chinRaise lipPucker lipPress ... attention eyeWiden cheekRaise lidTighten dimpler lipStretch jawDrop engaged frustrated tired
0 0.0001 0.0017 0.3675 0.0005 0.2961 0.0301 0.0000 0.0036 0.0228 0.0010 ... 68.7528 0.0005 0.0001 0.2042 0.0000 0.0005 36.6013 1 0 0
1 0.0000 0.3634 0.0438 0.0089 0.0068 0.0015 0.1021 0.0902 0.6553 0.0146 ... 95.4916 0.0020 0.0038 0.1071 0.1469 0.0009 0.0091 0 0 0
2 0.0001 0.0753 0.0125 0.9525 0.1256 0.0081 0.0015 2.9799 1.2893 1.3095 ... 98.2015 0.0001 0.0133 0.3133 0.6056 0.0117 0.1503 1 1 0
3 0.0002 0.0105 0.0106 0.0058 0.0116 0.0020 0.0064 0.4691 8.5714 0.6517 ... 97.5603 0.0005 0.0016 0.0483 0.2395 0.0874 0.4730 1 1 0
4 0.0000 0.0088 0.8570 0.3820 1.0644 2.8577 5.7884 0.0532 0.0826 0.0096 ... 93.0457 0.0024 0.0000 0.1442 0.6053 0.0143 0.0056 1 0 0
5 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ... 97.3836 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1 0 0
6 0.0000 0.0087 0.1313 0.0037 0.0394 0.0192 0.0003 0.0017 0.0068 0.0050 ... 64.9050 0.0008 0.0010 0.1322 0.0007 0.0005 0.9447 1 0 0
7 0.0000 0.0024 0.2030 0.1007 0.0020 0.0428 3.5119 0.0544 0.5347 0.2020 ... 61.6071 0.3619 0.0313 0.0785 0.4228 0.0010 2.7955 1 0 0
8 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ... 96.6665 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1 0 0
9 0.0000 0.0004 0.7481 0.0000 0.0005 0.0000 9.5452 0.0007 0.0006 0.0000 ... 84.1457 0.0306 0.0001 0.0001 0.0000 0.0000 1.8366 1 0 0

10 rows × 24 columns


In [96]:
df[14500:
  ]


Out[96]:
smile innerBrowRaise browRaise browFurrow noseWrinkle upperLipRaise lipCornerDepressor chinRaise lipPucker lipPress ... attention eyeWiden cheekRaise lidTighten dimpler lipStretch jawDrop engaged frustrated tired
14500 0.0000 0.0008 0.0165 0.0172 0.0609 0.0071 0.0018 0.0022 0.0584 1.0803 ... 91.8243 0.0001 0.1126 0.0542 0.0586 0.0014 3.1013 0 0 0
14501 0.0001 0.0045 0.6340 0.0000 0.0599 0.0001 0.0052 0.0001 0.0028 0.0090 ... 98.0259 0.0009 0.0037 0.0035 0.0085 2.6910 0.1792 1 0 1
14502 0.0000 27.5634 0.0024 20.2224 0.0604 0.0012 0.0179 0.0002 0.0012 0.0009 ... 98.1393 0.0000 0.0023 33.6673 0.0000 0.0006 48.4190 1 1 0
14503 0.0000 0.0387 0.0093 0.0113 0.0857 0.0004 0.0282 0.0015 3.5178 0.1063 ... 94.4079 0.0000 0.0004 0.0934 0.0311 0.0047 0.3625 1 0 0
14504 0.0000 1.0462 0.0048 0.0094 0.1233 0.0001 0.1123 0.0050 0.6011 0.0769 ... 96.3621 0.0000 0.0038 1.0997 0.0024 0.0002 0.1041 1 0 1
14505 0.0007 0.0003 26.0187 0.0026 23.0512 1.4254 0.0000 27.6334 0.0049 0.0239 ... 69.7431 0.0001 0.2205 2.8727 0.0015 0.0029 52.4628 1 0 0
14506 0.0000 0.0649 0.0214 0.0016 0.0128 0.0000 0.0184 0.0011 0.4892 1.1604 ... 92.8589 0.0000 0.0030 0.0740 0.1122 0.0103 0.0701 1 0 0
14507 0.0000 0.0031 0.0397 0.0006 0.0654 21.5068 0.0208 0.0210 0.3716 0.0078 ... 94.5310 0.0011 0.0006 0.0042 0.0032 0.0005 0.5236 1 0 0
14508 0.0000 0.0012 2.1497 0.0198 0.0005 0.0010 1.8910 2.7396 75.7016 7.1904 ... 60.9362 28.6035 0.1222 0.0189 0.1512 0.0142 10.5682 1 0 0
14509 0.0001 0.3074 0.2672 0.0002 0.0000 0.0000 0.0009 0.0582 0.0227 0.1250 ... 93.7928 1.1748 0.0001 0.0009 0.0757 0.0184 0.0131 0 1 1
14510 0.0000 0.8087 0.0056 0.0123 0.0831 0.0000 0.0252 0.0026 0.8287 0.0537 ... 96.9172 0.0001 0.0203 1.9960 0.0100 0.0006 0.1014 1 0 0
14511 0.0000 0.4036 0.2840 1.3854 0.1724 3.1730 2.6904 0.0615 0.1240 0.0010 ... 90.0325 0.0216 0.0005 0.1051 0.5122 0.0170 0.0103 1 0 0
14512 0.0003 0.0281 11.0056 0.0003 0.0360 0.0003 0.0088 0.2155 6.6739 0.3595 ... 98.1478 15.7086 0.0002 0.0003 0.1546 0.3520 0.0024 1 0 0
14513 0.0000 1.9575 0.0140 0.0009 0.0158 0.0000 0.0200 0.0036 0.6363 0.1396 ... 97.0519 0.0000 0.0040 0.8362 0.0602 0.0034 0.0100 1 0 0
14514 2.7713 0.3454 0.0465 0.0504 0.8209 0.0097 0.0000 0.0014 0.0007 3.9094 ... 97.3124 0.0068 0.0000 0.0511 78.7418 37.5404 0.0407 1 0 0
14515 0.0000 0.1214 0.0457 0.0630 0.0342 0.0201 0.0003 0.0387 0.0090 0.0332 ... 82.6869 0.0362 0.0004 0.0234 0.0100 0.0080 0.2096 0 0 0
14516 0.0018 0.2852 0.0403 19.5995 0.0810 0.0057 0.6327 0.0242 0.0014 0.1631 ... 89.9408 0.0133 0.0008 0.1661 99.0344 11.6718 0.0113 1 0 0
14517 0.0000 0.0096 0.0100 0.0157 0.0209 0.0051 0.0001 0.0066 0.0512 0.0746 ... 84.8188 0.0003 0.0462 0.0188 0.0072 0.0004 16.2080 0 0 0
14518 0.0000 0.0068 0.0162 0.0007 0.0180 7.6843 0.0319 0.0060 0.0967 0.1162 ... 91.5890 0.0040 0.0002 0.0020 0.0250 0.0001 6.0265 1 0 0
14519 0.0000 0.0000 4.4445 0.0000 0.0033 0.0003 0.0022 0.0003 0.0035 0.5019 ... 90.8181 0.0128 0.0018 0.0003 0.5889 0.0119 1.2682 1 0 0
14520 0.0002 9.0510 0.0039 1.0418 0.0195 0.0000 0.0021 0.0009 0.0014 2.2265 ... 98.1894 0.0000 0.0020 2.2337 32.1966 0.4488 0.0025 1 1 0
14521 0.0039 0.0172 0.0088 0.0045 0.0750 0.9990 0.0004 0.0019 1.2587 3.0679 ... 94.2124 0.0008 0.0009 0.0081 0.0379 0.0553 78.1031 1 0 0
14522 0.0000 0.0002 0.0667 0.0011 0.0002 0.0015 0.0001 0.0024 0.0111 0.0000 ... 74.5498 0.0050 0.3096 0.0435 0.0005 0.0000 29.2217 1 0 1
14523 0.0000 0.0053 0.0177 0.0202 0.0001 0.0000 0.0004 0.0103 0.0085 0.0063 ... 93.1198 0.0055 0.1696 0.0190 0.0098 0.0035 0.1394 1 1 1
14524 0.0001 0.0011 2.4706 0.0016 0.5313 3.0661 0.0035 0.0084 0.1499 0.0002 ... 88.0742 0.0089 0.0095 1.3669 0.0000 0.0023 0.1369 1 0 0
14525 0.1759 0.0164 62.3652 0.0019 0.9910 20.3902 0.0000 0.2730 0.2557 0.0389 ... 94.2820 0.0351 0.0083 0.1945 0.1083 0.0416 98.9027 1 0 0
14526 0.0000 0.1658 0.0431 0.0219 0.0050 0.0039 0.0029 0.0474 0.2278 0.1149 ... 87.8897 0.0034 0.0377 0.0125 0.0731 0.0007 0.4151 0 0 0
14527 0.0398 0.0005 0.0728 0.0003 0.4978 7.0772 0.0000 0.0094 0.1204 2.3865 ... 94.1496 0.0001 0.0215 0.0158 0.0113 0.0094 98.7633 1 0 0
14528 0.0001 0.0013 0.4914 0.0014 0.2736 0.0212 0.0000 0.0043 0.0399 0.0059 ... 64.7130 0.0017 0.0000 0.1430 0.0001 0.0017 24.9822 1 0 0
14529 0.0000 0.0001 0.0136 0.0509 0.0099 78.3798 0.2132 0.0585 0.0376 0.0097 ... 74.2435 1.0125 0.2013 0.0971 0.0029 0.0002 5.1452 1 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
14617 0.0013 0.0203 0.6237 0.0414 0.3083 0.0019 0.0000 0.0845 0.0193 0.0529 ... 64.7450 0.0013 0.0009 0.1123 0.0050 0.0060 4.9123 1 0 0
14618 0.0000 1.1197 0.0159 0.0002 0.0000 0.0000 0.0831 0.4178 3.8630 0.2139 ... 98.6951 0.0064 0.0003 0.0032 0.0430 0.0239 0.6924 0 0 0
14619 0.0000 0.0007 5.0382 0.0202 0.0005 0.0016 6.7808 41.0722 35.8196 2.9640 ... 66.6156 11.8541 0.5239 0.0186 0.1852 0.0094 5.4972 1 0 0
14620 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ... 95.6663 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1 0 0
14621 0.0000 0.0019 0.0436 1.7246 0.0068 0.0020 0.0061 0.0006 0.0078 0.0168 ... 95.4889 0.0004 0.0000 0.0096 0.1694 0.0288 1.5472 1 0 0
14622 0.0001 0.0487 3.6770 0.0038 2.9595 0.0657 0.0000 0.4679 0.0002 0.0024 ... 58.2133 0.0105 0.0001 0.0318 0.0006 0.5104 0.0021 1 0 0
14623 0.0000 0.7449 0.0105 0.3460 0.3147 3.8426 4.9292 0.2149 0.0939 40.5060 ... 97.4720 0.0037 0.1614 0.0315 98.5680 0.3245 0.0309 1 0 0
14624 0.0000 1.8529 0.0230 0.0246 0.0037 0.0016 0.2172 0.0304 0.8094 0.0083 ... 95.9182 0.0008 0.0000 0.0532 0.0290 0.0011 0.0053 0 0 0
14625 0.0000 0.0196 0.0496 0.0720 0.1098 0.0082 0.0018 0.0022 0.1625 0.0978 ... 83.4970 0.0003 0.0001 0.0313 0.0123 0.0713 0.0769 1 0 0
14626 0.0018 0.0011 0.0082 0.1022 0.0002 0.0000 0.0000 0.6928 0.0088 99.7341 ... 95.3634 0.0001 0.0000 0.1000 99.4546 22.5283 0.0023 1 1 0
14627 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ... 97.6130 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1 0 0
14628 0.0000 0.0136 0.0125 0.0152 0.0236 0.0030 0.0001 0.0111 0.0420 0.0918 ... 88.5641 0.0003 0.0387 0.0177 0.0214 0.0007 9.8183 0 0 0
14629 0.0003 0.0002 0.0163 0.0032 0.0000 0.0000 0.0160 6.7935 0.0021 9.0816 ... 45.1038 0.0021 4.9376 0.1224 98.1730 26.1617 0.0028 1 1 0
14630 0.0000 0.1443 0.0444 1.7161 0.0223 0.0001 0.0007 40.6486 0.4746 99.7812 ... 85.0699 0.3641 0.0003 0.0043 99.3796 0.0004 0.1741 1 0 0
14631 0.0000 0.1721 0.0065 0.0003 0.0026 0.0000 100.0000 17.0766 0.0151 2.3037 ... 96.9408 0.0160 0.0012 0.0094 0.3657 0.0000 0.0085 1 0 0
14632 0.0000 0.4936 1.3146 0.0114 0.1939 0.0027 0.1175 0.0006 0.0271 0.0619 ... 96.9949 0.0000 0.0002 0.0661 0.0612 0.0049 5.9838 1 0 1
14633 0.0000 0.8418 0.0172 43.7902 5.0040 0.0285 0.0424 0.0006 0.1116 0.0223 ... 95.6694 0.0000 0.0029 7.1041 0.0001 0.0001 24.9004 1 1 0
14634 0.0003 0.0024 0.0418 0.0009 0.1038 0.2223 0.0183 0.0007 0.0867 0.3808 ... 94.3297 0.0001 0.0052 0.0287 0.3983 0.0121 6.7284 1 0 0
14635 0.0000 12.9514 0.0055 0.0013 0.0215 0.0000 0.3027 0.3203 1.9982 0.0271 ... 97.6702 0.0000 0.0005 0.8127 0.0034 0.0008 0.0155 1 0 0
14636 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ... 97.3946 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1 0 0
14637 0.0000 0.0216 0.0115 0.0000 0.0058 0.0000 100.0000 0.7149 0.0176 0.0001 ... 97.1231 0.0183 0.0000 0.0019 0.0001 0.0000 0.0052 1 0 0
14638 0.0000 0.0111 0.0660 0.0118 0.0210 0.0763 0.0001 0.0004 0.0159 0.0034 ... 59.7040 0.0090 0.0000 0.0113 0.0003 0.0007 1.0531 1 0 0
14639 0.3849 0.0909 0.0186 0.0011 0.0106 0.0000 0.0010 0.0053 0.1406 95.5807 ... 93.1489 0.0001 0.0114 0.2369 89.5504 0.1711 0.0045 1 0 0
14640 0.0000 0.0015 0.0430 1.1320 0.0059 0.0030 0.0084 0.0014 0.0115 0.0349 ... 95.5180 0.0004 0.0000 0.0076 0.2017 0.0327 1.6301 1 0 0
14641 0.0000 0.0380 0.0506 6.5615 7.5569 0.0012 0.0628 0.0069 0.4060 1.8768 ... 90.2720 0.0000 0.0343 15.0457 0.0643 0.0014 0.9861 1 1 0
14642 0.0000 0.0001 0.1875 0.0033 0.0150 0.1271 0.0001 0.0593 3.2768 0.0513 ... 77.4417 0.0097 0.0003 0.0061 0.0283 0.0008 4.1499 1 0 0
14643 0.0051 0.0015 0.0121 0.0167 0.0353 0.0001 0.0000 0.4425 0.0047 1.1963 ... 95.2038 0.0000 0.0019 0.0481 85.6119 3.6602 1.5709 1 1 0
14644 0.0000 0.0003 0.0336 0.0004 0.0003 0.0000 0.0078 0.0018 4.3169 0.0009 ... 88.1091 2.8276 0.4366 0.0382 0.0004 0.0001 6.4508 0 0 0
14645 0.0005 0.0013 5.7142 0.0024 1.3520 0.0485 0.0001 0.0944 0.0009 0.0006 ... 68.1618 0.0000 0.0046 0.6779 0.0005 0.0089 39.6550 1 0 0
14646 0.0001 0.7301 0.0993 0.0002 0.0012 0.0000 0.0201 0.2024 0.0174 9.0114 ... 95.1172 0.3680 0.0025 0.0066 95.0373 16.3362 0.0000 1 1 0

147 rows × 24 columns


In [97]:
dftrain = df[0:13182]
dftest = df[13184:14646]
print len(dftrain)


13182

In [98]:
from sklearn.preprocessing import StandardScaler
explanatoryStd = dftrain[['smile','innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop']].copy() 
X_std = StandardScaler().fit_transform(explanatoryStd)
backtodf = pd.DataFrame(X_std, index=explanatoryStd.index, columns=explanatoryStd.columns)
Dependent = dftrain['frustrated']
logit = sm.Logit(Dependent,backtodf)
result = logit.fit()
print(result.summary())


Optimization terminated successfully.
         Current function value: 0.559984
         Iterations 8
                           Logit Regression Results                           
==============================================================================
Dep. Variable:             frustrated   No. Observations:                13182
Model:                          Logit   Df Residuals:                    13162
Method:                           MLE   Df Model:                           19
Date:                Thu, 08 Dec 2016   Pseudo R-squ.:                 -0.4850
Time:                        08:34:14   Log-Likelihood:                -7381.7
converged:                       True   LL-Null:                       -4971.0
                                        LLR p-value:                     1.000
======================================================================================
                         coef    std err          z      P>|z|      [95.0% Conf. Int.]
--------------------------------------------------------------------------------------
smile                  0.0212      0.021      0.993      0.321        -0.021     0.063
innerBrowRaise        -0.2947      0.030     -9.739      0.000        -0.354    -0.235
browRaise             -0.0247      0.024     -1.034      0.301        -0.072     0.022
browFurrow             0.0243      0.031      0.781      0.435        -0.037     0.085
noseWrinkle           -0.0377      0.031     -1.213      0.225        -0.099     0.023
upperLipRaise         -0.3559      0.033    -10.801      0.000        -0.421    -0.291
lipCornerDepressor    -0.1789      0.025     -7.086      0.000        -0.228    -0.129
chinRaise             -0.0722      0.033     -2.187      0.029        -0.137    -0.008
lipPucker              0.0787      0.020      3.946      0.000         0.040     0.118
lipPress               0.0592      0.031      1.900      0.057        -0.002     0.120
lipSuck                0.5327      0.035     15.349      0.000         0.465     0.601
mouthOpen             -0.0390      0.026     -1.506      0.132        -0.090     0.012
smirk                  0.0948      0.025      3.720      0.000         0.045     0.145
eyeClosure             0.1129      0.020      5.546      0.000         0.073     0.153
eyeWiden              -0.0073      0.020     -0.354      0.723        -0.047     0.033
cheekRaise             0.0007      0.022      0.034      0.973        -0.042     0.043
lidTighten             6.1850      0.157     39.359      0.000         5.877     6.493
dimpler                0.1512      0.030      5.046      0.000         0.092     0.210
lipStretch             0.0791      0.037      2.126      0.033         0.006     0.152
jawDrop               -0.0711      0.025     -2.836      0.005        -0.120    -0.022
======================================================================================

In [99]:
from sklearn import metrics
from math import sqrt 
from ggplot import *
count1 = 0
count0 = 0
count = 0
sum1 = 0.0
#dftest_std = StandardScaler().fit_transform(X_std = StandardScaler().fit_transform(explanatoryStd))
per = result.predict(dftest[['smile','innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop']] )

fpr, tpr, pr = metrics.roc_curve(dftest['frustrated'], per)
df = pd.DataFrame(dict(fpr=fpr, tpr=tpr))
ggplot(df, aes(x='fpr', y='tpr')) +\
    geom_line() +\
    geom_abline(linetype='dashed')


Out[99]:
<ggplot: (322371461)>

In [100]:
from numpy import *
import math
import matplotlib.pyplot as plt
#print 1-fpr
plt.plot(pr,1-fpr,'r',label= 'specificity')
plt.plot(pr,tpr,'b',label= 'sensivity')
plt.legend()


Out[100]:
<matplotlib.legend.Legend at 0x13164f350>

In [101]:
auc = metrics.auc(fpr,tpr)
print auc


0.816643338271

In [102]:
for i in pr:
    if i > 1:
        print i


1.99999996883

In [103]:
from sklearn.preprocessing import StandardScaler
explanatoryStd = dftrain[['smile','innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop']].copy() 
X_std = StandardScaler().fit_transform(explanatoryStd)
backtodf = pd.DataFrame(X_std, index=explanatoryStd.index, columns=explanatoryStd.columns)
Dependent = dftrain['engaged']
logit = sm.Logit(Dependent,backtodf)
result = logit.fit()
print(result.summary())


Optimization terminated successfully.
         Current function value: 0.667587
         Iterations 5
                           Logit Regression Results                           
==============================================================================
Dep. Variable:                engaged   No. Observations:                13182
Model:                          Logit   Df Residuals:                    13162
Method:                           MLE   Df Model:                           19
Date:                Thu, 08 Dec 2016   Pseudo R-squ.:                 -0.4559
Time:                        08:34:29   Log-Likelihood:                -8800.1
converged:                       True   LL-Null:                       -6044.3
                                        LLR p-value:                     1.000
======================================================================================
                         coef    std err          z      P>|z|      [95.0% Conf. Int.]
--------------------------------------------------------------------------------------
smile                  0.0164      0.022      0.744      0.457        -0.027     0.060
innerBrowRaise        -0.2026      0.023     -8.970      0.000        -0.247    -0.158
browRaise              0.0189      0.020      0.946      0.344        -0.020     0.058
browFurrow             0.2619      0.025     10.426      0.000         0.213     0.311
noseWrinkle           -0.0106      0.022     -0.489      0.625        -0.053     0.032
upperLipRaise         -0.0514      0.021     -2.401      0.016        -0.093    -0.009
lipCornerDepressor    -0.0209      0.020     -1.027      0.305        -0.061     0.019
chinRaise              0.1086      0.028      3.818      0.000         0.053     0.164
lipPucker             -0.2284      0.023    -10.064      0.000        -0.273    -0.184
lipPress               0.0400      0.029      1.390      0.165        -0.016     0.096
lipSuck               -0.2469      0.028     -8.775      0.000        -0.302    -0.192
mouthOpen              0.1871      0.023      8.289      0.000         0.143     0.231
smirk                 -0.1721      0.023     -7.373      0.000        -0.218    -0.126
eyeClosure            -0.1083      0.020     -5.514      0.000        -0.147    -0.070
eyeWiden               0.0364      0.019      1.939      0.052        -0.000     0.073
cheekRaise             0.0636      0.020      3.245      0.001         0.025     0.102
lidTighten            -0.1222      0.024     -5.191      0.000        -0.168    -0.076
dimpler                0.2822      0.030      9.536      0.000         0.224     0.340
lipStretch            -0.1231      0.028     -4.331      0.000        -0.179    -0.067
jawDrop                0.1014      0.022      4.613      0.000         0.058     0.144
======================================================================================

In [104]:
from sklearn import metrics
from math import sqrt 
from ggplot import *
count1 = 0
count0 = 0
count = 0
sum1 = 0.0

per = result.predict(dftest[['smile','innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop']] )

fpr, tpr, pr = metrics.roc_curve(dftest['engaged'], per)
df = pd.DataFrame(dict(fpr=fpr, tpr=tpr))
ggplot(df, aes(x='fpr', y='tpr')) +\
    geom_line() +\
    geom_abline(linetype='dashed')


Out[104]:
<ggplot: (322371465)>

In [105]:
from numpy import *
import math
import matplotlib.pyplot as plt
#print 1-fpr
plt.plot(pr,1-fpr,'r',label= 'specificity')
plt.plot(pr,tpr,'b',label= 'sensitivity')
plt.legend()


Out[105]:
<matplotlib.legend.Legend at 0x12e42e690>

In [77]:
from sklearn.preprocessing import StandardScaler
explanatoryStd = dftrain[['innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop']].copy() 
X_std = StandardScaler().fit_transform(explanatoryStd)
backtodf = pd.DataFrame(X_std, index=explanatoryStd.index, columns=explanatoryStd.columns)
Dependent = dftrain['tired']
logit = sm.Logit(Dependent,backtodf)
result = logit.fit()
print(result.summary())


Optimization terminated successfully.
         Current function value: 0.684854
         Iterations 4
                           Logit Regression Results                           
==============================================================================
Dep. Variable:                  tired   No. Observations:                13182
Model:                          Logit   Df Residuals:                    13163
Method:                           MLE   Df Model:                           18
Date:                Thu, 08 Dec 2016   Pseudo R-squ.:                  -2.530
Time:                        08:29:11   Log-Likelihood:                -9027.7
converged:                       True   LL-Null:                       -2557.3
                                        LLR p-value:                     1.000
======================================================================================
                         coef    std err          z      P>|z|      [95.0% Conf. Int.]
--------------------------------------------------------------------------------------
innerBrowRaise         0.0983      0.020      4.957      0.000         0.059     0.137
browRaise             -0.0406      0.020     -2.059      0.039        -0.079    -0.002
browFurrow            -0.0085      0.023     -0.377      0.707        -0.053     0.036
noseWrinkle            0.0004      0.021      0.018      0.986        -0.041     0.042
upperLipRaise          0.0109      0.021      0.524      0.600        -0.030     0.051
lipCornerDepressor    -0.0854      0.019     -4.382      0.000        -0.124    -0.047
chinRaise              0.0106      0.026      0.403      0.687        -0.041     0.062
lipPucker             -0.0430      0.018     -2.328      0.020        -0.079    -0.007
lipPress              -0.0858      0.027     -3.123      0.002        -0.140    -0.032
lipSuck                0.0334      0.025      1.359      0.174        -0.015     0.082
mouthOpen              0.1954      0.022      8.946      0.000         0.153     0.238
smirk                  0.0954      0.022      4.251      0.000         0.051     0.139
eyeClosure             0.1082      0.019      5.691      0.000         0.071     0.145
eyeWiden              -0.0059      0.018     -0.329      0.742        -0.041     0.029
cheekRaise             0.0536      0.019      2.772      0.006         0.016     0.091
lidTighten             0.0109      0.023      0.479      0.632        -0.034     0.056
dimpler               -0.0101      0.027     -0.370      0.711        -0.064     0.043
lipStretch            -0.0048      0.026     -0.183      0.855        -0.056     0.046
jawDrop               -0.0801      0.021     -3.754      0.000        -0.122    -0.038
======================================================================================

In [106]:
auc = metrics.auc(fpr,tpr)
print auc


0.58232405892

In [107]:
from sklearn import metrics
from math import sqrt 
from ggplot import *
count1 = 0
count0 = 0
count = 0
sum1 = 0.0

per = result.predict(dftest[['smile','innerBrowRaise', 'browRaise', 'browFurrow', 'noseWrinkle', 'upperLipRaise', 
                        'lipCornerDepressor', 'chinRaise', 'lipPucker', 'lipPress', 'lipSuck', 
                        'mouthOpen', 'smirk', 'eyeClosure', 'eyeWiden', 'cheekRaise',
                        'lidTighten', 'dimpler', 'lipStretch', 'jawDrop']] )

fpr, tpr, pr = metrics.roc_curve(dftest['tired'], per)
df = pd.DataFrame(dict(fpr=fpr, tpr=tpr))
ggplot(df, aes(x='fpr', y='tpr')) +\
    geom_line() +\
    geom_abline(linetype='dashed')


Out[107]:
<ggplot: (319607045)>

In [108]:
auc = metrics.auc(fpr,tpr)
print auc


0.472359607446

In [ ]: