【发布时间】:2019-12-13 17:07:19
【问题描述】:
我有一个时间序列数据集,如下所示,我为每个传感器记录了 2 个时间序列。 Label 列描述了传感器是否有故障(即0 或1)。
sensor, time-series 1, time-series 2, Label
x1, [38, 38, 35, 33, 32], [18, 18, 12, 11, 09], 1
x2, [33, 32, 35, 36, 32], [13, 12, 15, 16, 12], 0
and so on ..
目前,我正在考虑来自两个时间序列的不同特征(例如,最小值、最大值、中值、斜率等),并考虑在 sklearn 中的随机森林分类器中对它们进行如下分类。
df = pd.read_csv(input_file)
X = df[[myfeatures]]
y = df['Label']
#Random Forest classifier
clf=RandomForestClassifier(random_state = 42, class_weight="balanced", criterion = 'gini', max_depth = 3, max_features = 'auto', n_estimators = 500)
k_fold = StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
output = cross_validate(clf, X, y, cv=k_fold, scoring = 'roc_auc', return_estimator =True)
for idx,estimator in enumerate(output['estimator']):
print("Features sorted by their score for estimator {}:".format(idx))
feature_temp_importances = pd.DataFrame(estimator.feature_importances_,
index = mylist,
columns=['importance']).sort_values('importance', ascending=False)
print(feature_temp_importances)
但是,我的结果非常低。我想知道是否可以将时间序列数据原样提供给random forest 分类器。例如,将x1 特征赋予为[38, 38, 35, 33, 32], [18, 18, 12, 11, 09]。如果可能的话,我想知道如何在 sklearn 中做到这一点?
如果需要,我很乐意提供更多详细信息。
【问题讨论】:
-
你试过滞后吗?
-
@BlueSheepToken 感谢您的评论。我是时间序列分类的新手。所以,我不确定你所说的滞后是什么意思。你能给我更多的细节吗? :)
标签: python scikit-learn classification random-forest