def test_classify_2016(self): model = train('./corpus/training/', 2) classification = classify(model, './corpus/test/2016/19.txt') expected_classification = { 'log p(y=2016|x)': -3800.4027665365134, 'log p(y=2020|x)': -3805.776535552692, 'predicted y': '2016' } self.compare_dicts(classification, expected_classification)
def test_classify_2020(self): model = train('./corpus/training/', 2) classification = classify(model, './corpus/test/2016/0.txt') expected_classification = { 'log p(y=2020|x)': -3906.351945884105, 'log p(y=2016|x)': -3916.458747858926, 'predicted y': '2020' } self.compare_dicts(classification, expected_classification)
def test_train(self): model = train('./EasyFiles/', 2) expected_model = { 'vocabulary': ['.', 'a'], 'log prior': { '2020': -0.916290731874155, '2016': -0.5108256237659905 }, 'log p(w|y=2020)': { '.': -1.6094379124341005, 'a': -2.302585092994046, None: -0.35667494393873267 }, 'log p(w|y=2016)': { '.': -1.7047480922384253, 'a': -1.2992829841302609, None: -0.6061358035703157 } } self.compare_dicts(model, expected_model)
def train_with_feature_set(self, feature_set, pred_blobs, real_blobs, feat_weight=False): X, Y = classify.create_training_set_from_feature_set(feature_set, pred_blobs, real_blobs) return classify.train(X, Y, self.clf, self.scaler, self.selector, feat_weight)
import serialread import preprocessing import feature import classify import sys import socket import numpy as np import time import bluetooth from scipy import signal trained = classify.train() bt_address = "20:16:08:04:80:97" # MAC address of our emotion recognition hardware. bt_port = 1 bt = bluetooth.BluetoothSocket(bluetooth.RFCOMM) print("Establishing Bluetooth connection...") bt.connect((bt_address, bt_port)) print("Bluetooth connection established.") print("Calibrating for your relaxed state. Please wait...") time.sleep(5) std_features_r = [0] # Extract features for 50 seconds when user is relaxed and uses the means and # standard deviations of the extracted, relaxed state features for normalization later on. while 0 in std_features_r: features_r = []