Coder Social home page Coder Social logo

martinferianc / sentimentanalysis-eie3 Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 7.94 MB

Sentiment analysis from small grayscale pictures by decision forests done as a coursework for CO395

License: MIT License

Python 100.00%
decision-forest decision-trees machine-learning sentiment-analysis computer-vision

sentimentanalysis-eie3's Introduction

Sentiment analysis for grayscale small pictures of faces by decision forests

This project was a part of coursework for module CO395 Introduction to Machine Learning at Imperial College London

Specification

The task was to accept the 2D grayscale image as a 1D vector of features which have been used both for training and testing of decision forests which could classify emotions.

When training the decision trees on the data, we train six different trees that become binary classifiers on one specific emotion. These are then combined into a decision forest which is then used to classify the test data. The decision forests are then stored here after they have been generated and can therefore easily be loaded again.

Structure

.
├── README.md
├── forests
├── requirements.txt
├── src
├── trees
└── visual

forests contains the directory with the pre-trained forests. src contains the source code, trees contains the individual trees for each emotion. visual contains the visualisations of the learnt trees.

Testing

To test the trees, the trained trees should first be loaded from the disk or trained on the data.

The trained decision forests should be stored in the folder called forests. If that directory is not present, the trees will have to be retrained by following the guide on how to do that in the training section of the README.

The loadTrees function in test.py can be used to load a tree from the forests directory. This function first takes in the data type, which can be either 'noisy' or 'clean'. As a second argument it takes in the split from the cross validation that should be loaded, which can be a number from 0-9. If the split is of type None, or not present, then the full decision forest is returned.

Once the forest is loaded, it can be tested by using the testTrees function in test.py. This function takes in the forest that was loaded earlier and the test data that the forest should be tested on. It then returns the predicted labels to the input data.

There is a load_data function which when passed the file path to a .mat data file will return a tuple of the data and corresponding labels.

An example of how to use these functions can be seen below:

from preprocessing import load_data

X,Y = load_data("path/to/data_testing.mat")

from test import testTrees, loadTrees

forest = loadTrees("clean")
predicted_labels = testTrees(forest, X)

testTrees can also take in an optional parameter, which determines with which hyperparameter the decision forest chooses the right label. Two different parameters can be used for the label identification one being 'var' and the other being 'level'. By default, the decision forest will use the variance, by using the 'var' flag, to choose the correct label. These can be set as follows.

predicted_labels = testTrees(forest, X, "var")

or

predicted_labels = testTrees(forest, X, "level")

Training

To train the trees and store them, the main.py python file can be executed, after all the requirements have been installed using pip3. From the root of the repository, the following commands will generate the trees.

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
python main.py

This will perform cross-validation on all of the provided data, training all the trees required for this analysis, as well as training trees on all of the data. The .forest files decision_forest_clean.forest and decision_forest_noisy.forest are the final decision forests to be used on identifying real data.

Credits

Yann Herklotz, George Punter, Divyansh Manocha and Martin Ferianc at Imperial College London, 2018.

sentimentanalysis-eie3's People

Contributors

martinferianc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.