You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ROCKET+SHAP用于时间序列分类时SHAP值偏低的原因排查

ROCKET+SHAP适配后SHAP值普遍偏低的原因排查

问题背景

我用ROCKET转换器搭配RidgeClassifierCV做多元时间序列分类,模型在数据上表现正常,但用sktime提供的ROCKET适配SHAP的workaround时,得到的SHAP值普遍极低(最大值约0.015)。

验证实验

为排查是否是自身数据的问题,我在sktime的两个示例数据集上做了测试:

1. basic_motions数据集

# Example Datset basic_motions
from sktime.datasets import load_basic_motions
X, y = load_basic_motions(return_X_y=True)

# Select train and test by hand
X_train = X[0:55]
y_train = y[0:55]

X_test = X[56:89]
y_test = y[56:89]

2. unit_test数据集

# Example Dataset unit_test
from sktime.datasets import load_unit_test
X_train, y_train = load_unit_test(split="train", return_X_y=True)
X_test, y_test = load_unit_test(split="test", return_X_y=True)

数据转换

将数据集转为3D numpy数组:

# Transform X_train etc. into 3D numpy array
from sktime.datatypes import convert_to
X_train_3d = convert_to(X_train, to_type="numpy3D")
X_test_3d = convert_to(X_test, to_type="numpy3D")

SHAP适配函数定义

使用的workaround函数如下:

# Define Explanation Function
def mvts_shap(X_train, X_test, y_train, y_test):
    
    # Encode string labels to integers
    label_encoder = LabelEncoder()
    y_train_encoded = label_encoder.fit_transform(y_train)
    y_test_encoded = label_encoder.transform(y_test)
    
    i, j, k = X_train.shape
    u, v, w = X_test.shape
    
    X_train_flat = X_train.reshape(i, j*k)
    
    def reshaper(inner_tensor):
        return inner_tensor.reshape(inner_tensor.shape[0], j, k)

    def inv_reshaper(inner_tensor):
        return inner_tensor.reshape(inner_tensor.shape[0], j*k)

    param = {
            'objective': 'binary:logistic',
            'tree_method': 'hist',
            'eval_metric': 'logloss',
            'seed': 888,
            'n_estimators': 500
           }

    pipe = Pipeline([
        ('reshaper_t', FunctionTransformer(reshaper, inverse_func=inv_reshaper)),
        ('tabulariser', MiniRocketMultivariate(num_kernels=588, n_jobs=-1, random_state=1837)),
        ('bst', xgb.XGBClassifier(**param))
    ])
    
    pipe.fit(X_train_flat, y_train_encoded)
    
    # Take only n random samples from training data
    masker = shap.maskers.Independent(X_train_flat, 55) #10 
    
    # Define Explainer
    explainer = shap.KernelExplainer(pipe.predict_proba, masker.data)   
    
    # Explanation on Full test data
    shap_output = explainer.shap_values(X_test.reshape(u, v*w))

    shap_tensor = shap_output[1].reshape(u, v, w)        
    
    return shap_tensor

实验结果

  • basic_motions数据集:SHAP值最大值约0.062,和我自身数据的情况一致
  • unit_test数据集:SHAP值最大值达0.286,显著更高

两者的主要差异是unit_test是单变量时间序列,但我测试basic_motions的单特征时,SHAP值依然偏低。

疑问

这种SHAP值普遍偏低的问题,是源于SHAP适配ROCKET的workaround本身,还是数据特性导致?ROCKET结合SHAP是否存在数据特征方面的限制?

内容的提问来源于stack exchange,提问作者pascal_

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 16:57:47