-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_train.py
33 lines (27 loc) · 1.09 KB
/
final_train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import scipy.io as sio
import time
from sklearn.externals import joblib
from numpy import *
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import classification_report,confusion_matrix
"""
function fear_factor gives a value between 0 and 1 on how scared the person is
@parameter matrix is a list of alpha-theta waves
@returns a float between 0 and 1
"""
def fear_factor(matrix):#the matrix has some nan values. this needs to be fixed first
#convert the matrix into string and replace all nan strings with 0.0
matrix = str(matrix)
matrix = matrix.replace('nan', '0.0')
#X (1D) list created that has strings of the float values of matrix
X = matrix[1:-1].split(',')
#X is converted to a list of floats
X=list(map(float, X))
#import the trained ANN
mlp = joblib.load('trained_matrix1.pkl')
#converting X to a 2D matrix and predicting the value of fear
predictions = mlp.predict_proba([X])
#return the values of fear as a float to keep conversion safe
return predictions[0][0]