我有多变量时间序列数据,希望使用孤立森林算法检测异常值。希望从gridSearchCV中获取最佳参数,以下是gridSearch CV的代码片段。
以下代码片段加载输入数据集。
df = pd.read_csv("train.csv")
df.drop(['dataTimestamp','Anomaly'], inplace=True, axis=1)
X_train = df
y_train = df1[['Anomaly']] ( Anomaly column is labelled data).
定义孤立森林的参数。
clf = IsolationForest(random_state=47, behaviour='new', score="accuracy")
param_grid = {'n_estimators': list(range(100, 800, 5)), 'max_samples': list(range(100, 500, 5)), 'contamination': [0.1, 0.2, 0.3, 0.4, 0.5], 'max_features': [5,10,15], 'bootstrap': [True, False], 'n_jobs': [5, 10, 20, 30]}
f1sc = make_scorer(f1_score)
grid_dt_estimator = model_selection.GridSearchCV(clf, param_grid,scoring=f1sc, refit=True,cv=10, return_train_score=True)
grid_dt_estimator.fit(X_train, y_train)
执行fit后,出现以下错误:
ValueError:目标是多类别但平均值为'binary'。请选择另一个平均设置。
请问有人可以指导我这是怎么回事,我尝试了average ='weight',但仍然没有成功,我在做错什么吗? 请告诉我如何获得F-score。
即使将其更改为-1和1,我仍然收到相同的错误 Counter({-1: 250, 1: 250})
TypeError:f1_score()缺少2个必需的位置参数:'y_true'和'y_pred' - BigDataScientistIsolationForest
无监督情况下的scoring
参数将是什么? - hafiz031