如何使用线性判别分析基于序列值进行预测

时间:2019-08-29 20:01:29

标签: python analysis linear-discriminant

我正在研究一个基于EMG信号预测手部运动的程序。到目前为止,我有一个CSV文件用作LDA程序的数据库。我发现的问题实际上是可以通过程序预测的。有没有一种方法可以根据我从串行端口(传感器)获得的值来预测手指的运动?


import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
import serial as ser

names = ['Finger', 'Val1', 'Val2', 'Val3']
dataset = pd.read_csv('EmgSig.csv', names=names)

X = dataset.iloc[:, 1:3].values
y = dataset.iloc[:, 0].values

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

lda = LDA(n_components=1)
X_train = lda.fit_transform(X_train, y_train)
X_test = lda.transform(X_test)

classifier = RandomForestClassifier(max_depth=2, random_state=0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)

cm = confusion_matrix(y_test, y_pred)
print(cm)
print('Accuracy' + str(accuracy_score(y_test, y_pred)))

while True:
        data = ser.readline()
        decode = (data[0:len(data)-2].decode("utf-8"))
        datasplit = decode.split('-')
        Val1 = int(datasplit[0])
        Val2 = int(datasplit[1])
        Val3 = int(datasplit[2])

0 个答案:

没有答案