Package: gazeclassifier
The Python packagegazeclassifierprovides functions to decide if given gaze points represent a saccade, fixation, or some unknown pattern.The packagegazeclassifieris developed atInfant Cognition Laboratoryat University of Tampere.1. InstallWithpip:$ pip install gazeclassifierCompatible with Python 2.6, 2.7, 3.3, 3.4, and 3.5.2. UsageImport the lib:>>> import gazeclassifier as gazeDefine gaze points as pointlists:>>> g1 = [[0,0], [0,0], [1,1], [2,2], [2,2]]  # a saccade
>>> g2 = [[1,1], [1,1], [1,1], [1,1], [1,1]]  # a fixation
>>> g3 = [[1,1], [2,2], [0,0], [4,4], [1,1]]  # an unknownCreate a classifier. It is already pretrained and therefore able topredict:>>> gc = gaze.GazeClassifier()
>>> gc.predict(g1)
'saccade'
>>> gc.predict(g2)
'fixation'
>>> gc.predict(g3)
'unknown'Internally,predictfirst extracts features from pointlists before classification. The features can be extracted explicitly withextract_featuresandextract_raw_features:>>> gaze.extract_features(g1)
{
  'saccade_reaction': 1,
  'saccade_duration': 3,
  'saccade_mse': 0.000623,
  'fixation_mse': 0.232406
}

>>> gaze.extract_raw_features(g1)
{
  'saccade': {
    'source_points': [[0,0]],
    'saccade_points': [[0,0], [1,1], [2,2]],
    'target_points': [[2,2]],
    'mean_squared_error': 0.000623
  },
  'fixation': {
    'centroid': [[1.0,1.0]]
    'mean_squared_error': 0.232406,
  }
}As an alternative for using the default pretrained classifier, you can train one:>>> training_data = [g1, g2, g3]
>>> classes = ['saccade', 'fixation', 'unknown']
>>> gc = gaze.GazeClassifier()
>>> gc.fit(training_data, classes)The trained classifier has same API as the default:>>> gc.predict(g1)
'saccade'3. API3.1. gazeclassifier.predict(pointlist)Parameters:pointlist: a list of [x, y] points i.e. a list of listsOR alternatively the result dict fromextract_features.
This is convenient if you need access to the features and want to
preventpredictto re-extract them.Return a string which can be one of the following:'saccade': gaze travels from point A to B and otherways stays still'fixation': gaze has mainly stayed still'unknown': gaze cannot be regarded as any of the above3.2. gazeclassifier.extract_features(pointlist)Parameters:pointlist: a list of [x, y] points i.e. a list of listsReturn a dict that contains mean error and details for each hypothesis. The dict can be fed intoclassifyfor classification.3.3. gazeclassifier.extract_raw_features(pointlist)Parameters:pointlist: a list of [x, y] points i.e. a list of listsReturn a dict that contains mean error and details for each hypothesis. The dict can be fed intopredictfor classification.3.4. gazeclassifier.GazeClassifier()A new untrained classifier.3.5. gazeclassifier.GazeClassifier#fit(pointlists, classes)3.6. gazeclassifier.GazeClassifier#predict(pointlist_or_features)3.7. gazeclassifier.versionThe current version string:>>> gazeclassifier.version
'1.2.3'4. For developersTips for the developers of the package.4.1. Use GitTo develop, clone the repository from GitHub:$ git clone https://github.com/infant-cognition-tampere/gazeclassifier-pyMake changes to files, add them to commit, and do commit:(edit README.rst)
$ git add README.rst
$ git commit -m "Improved documentation"List files that are not added or not committed:$ git statusPush local commits to GitHub:$ git pushIgnore some files by editing.gitignore:$ nano .gitignore4.2. VirtualenvManage python versions and requirements by using virtualenv:$ virtualenv -p python3.5 gazeclassifier-py
$ cd gazeclassifier-py
$ source bin/activate
...
$ deactivate4.3. TestingFollowinstructions to install pyenvand then either run quick tests:$ python3.5 setup.py testor run comprehensive tests for multiple Python versions listed intox.ini:$ pyenv local 2.6.9 2.7.10 3.3.6 3.4.3 3.5.0
$ eval "$(pyenv init -)"
$ pyenv rehash
$ toxInstall new pyenv environments for example by:$ pyenv install 3.5.0Validate README.rst athttp://rst.ninjs.org/4.4. Publishing to PyPIFollowpython packaging instructions:Create an unpacked sdist:$ python setup.py sdistCreate a universal wheel:$ python setup.py bdist_wheel--universalGo toPyPI and register the project by filling the package formby uploadinggazeclassifier.egg-info/PKG_INFOfile.Upload the package with twine:Sign the dist:$ gpg--detach-sign-adist/gazeclassifier-1.2.3*Upload:twine uploaddist/gazeclassifier-1.2.3*(will ask your PyPI password)Package published!Updating the package takes same steps except the 3rd.4.5 Version releaseChange version string ingazeclassifier/version.pyandsetup.pyto'1.2.3'Run tox tests. See4.3. Testing.Git commit:$ git commit--all-m"v1.2.3 release"Create tag:$ git tag-a1.2.3-m"v1.2.3 stable"Push commits and tags:$ git push && git push--tagsPublish to PyPI. See4.4. Publishing to PyPI.5. VersioningSemantic Versioning 2.0.06. LicenseMIT License