Python Machine Learning Algorithm to Recognize Kno

2019-09-21 00:34发布

问题:

I have two sets of data. These data are logged voltages of two points A and B in a circuit. Voltage A is the main component of the circuit, and B is a sub-circuit. Every positive voltage in B is (1) considered a B event and (2) known to be composite of A. I have included sample data where there is a B voltage event, 4,4,0,0,4,4. A real training data set would have many more available data.

How can I train a Python machine learning algorithm to recognize B events given only A data?

Example data:

V(A), V(B)
0, 0
2, 0
5, 4
3, 4
1, 0
3, 4
4, 4
1, 0
0, 0
2, 0
5, 0
7, 0
2, 0
5, 4
9, 4
3, 0
5, 0
4, 4
6, 4
3, 0
2, 0

回答1:

An idea:

from sklearn.ensemble import RandomForestClassifier

n = 5
X = [df.A.iloc[i:i+n] for i in df.index[:-n+1]] 
labels = (df.B > 0)[n-1:]

model = RandomForestClassifier()
model.fit(X, labels)
model.predict(X)

What this does is, it takes the previous n observations as predictors for the 'B' value. On this small data set it achieves 0.94 accuracy (could be overfitting).

EDIT: Corrected a small alignment error.