所以我想使用cleanlab来改进may分类器。以下是一些示例数据
x=np.linspace(0,3,500)
X_true=np.array([randint(1,10)*np.sin(x) for _ in range(100)])
X_false=np.array([randint(1,10)*np.tan(x) for i in range(100)])
y=[True for _ in range (100)]+[False for _ in range (100)]
df=pd.concat([pd.DataFrame(X_true),pd.DataFrame(X_false)])
df['y']=y
df = df.sample(frac=1).reset_index(drop=True)
X=df.drop('y', axis=1).to_numpy()
y=df['y'].to_numpy()这将为具有标签True的sin函数和具有标签False的tan函数创建时间序列的数据集。为了创建一些标签错误,我们将前20个目标设置为True
y[:20]=True现在,我使用sktime分类器来查找每个时间序列的标签,它工作得很好
>>> X=from_2d_array_to_nested(X)
>>> clf=TimeSeriesForestClassifier(n_jobs=-1).fit(X,y)
>>> clf.score(X,y)
0.95但是,我想使用cleanlab来通知分类器,他的一些训练标签可能不正确
>>> LearningWithNoisyLabels(clf=TimeSeriesForestClassifier()).fit(X,y)但是这会导致一个KeyError
KeyError: "None of [Int64Index([ 1, 2, 4, 5, 6, 7, 11, 13, 15, 17,\n ...\n 186, 187, 188, 190, 191, 192, 194, 196, 198, 199],\n dtype='int64', length=160)] are in the [columns]"由于LearningWithNoisyLabels正在为我使用其他分类器,所以我猜sktime分类器有问题,但我不确定
版本信息:
>>> cleanlab.__version__, sktime.__version__
('0.1.1', '0.5.3')导入:
>>> from cleanlab.classification import LearningWithNoisyLabels
>>> from sktime.utils.data_processing import from_2d_array_to_nested
>>> from sktime.classification.all import TimeSeriesForestClassifier发布于 2021-03-10 00:04:53
问题是,在LearningWithNoisyLabels(..).fit()期间,函数cleanlab.latent_estimation.estimate_confident_joint_and_cv_pred_proba抛出了一个异常,因为它不能正确处理sktime特性格式。from_2d_array_to_nested()的结果是一个包含1列的pd.DataFrame,每个单元格中有一个pd.Series。
但是,如果我们在以普通np.array为输入的管道中定义TimeSeriesForestClassifier,一切都会正常工作。
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import FunctionTransformer
clf=make_pipeline(FunctionTransformer(from_2d_array_to_nested),
TimeSeriesForestClassifier())
clf_clean=LearningWithNoisyLabels(clf)
clf_clean.fit(X,y)https://stackoverflow.com/questions/66532527
复制相似问题