我正在开发一个基于 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])