Scikit-multilearn中MEKA的CM分类器使用报错求助
Let's break down your two issues with the MEKA CM classifier in scikit-multilearn and fix them one by one:
Issue 1: UnsupportedAttributeTypeException with J48
The root cause here is how MEKA's CM classifier works: it transforms multi-label problems into single-label tasks where each unique combination of labels becomes a "class" for the base classifier. J48 (Weka's decision tree) is designed for discrete/categorical classes, but CM was encoding these label combinations as numeric values by default—hence the error that J48 can't handle numeric classes.
To fix this, you just need to tell CM to treat the combined label class as nominal (categorical). Modify your first code snippet like this:
meka = Meka( meka_classifier="meka.classifiers.multilabel.meta.CM -nominal", weka_classifier="weka.classifiers.trees.J48", meka_classpath=meka_classpath # From download_meka ) print("Fit") meka.fit(X_train, y_train)
The -nominal flag forces CM to encode label combinations as categorical classes, which J48 can process without issues. Since BR works with your data, this is purely a CM-specific encoding tweak.
Issue 2: IndexError with command-line parameter string
Your second approach uses a full command-line style string for meka_classifier, but the syntax was off—specifically the way you nested parameters for the CC sub-classifier. MEKA/Weka uses -- (double dash) to separate parameters for nested classifiers, and extra spaces were confusing the scikit-multilearn parser, leading to the IndexError and empty classifier_dump.
Here's the corrected code:
meka = Meka( meka_classifier="meka.classifiers.multilabel.meta.CM -I 10 -W meka.classifiers.multilabel.CC -- -S 0 -W weka.classifiers.trees.J48", meka_classpath=meka_classpath # From download_meka ) print("Fit Data") meka.fit(X_train, y_train) print("Predict") prediction = meka.predict(x_test)
Key fixes:
- Added
--between CM's parameters and CC's parameters to properly nest the sub-classifier settings. - Removed the redundant
weka_classifierparameter (since you're already defining the full classifier chain inmeka_classifier). - Cleaned up extra spacing that was breaking the parser.
Extra Checks
- Double-check that your MEKA and Weka versions are compatible—mismatched versions can cause unexpected parsing or runtime bugs.
- Confirm
meka_classpathincludes all required MEKA JAR files (and their dependencies). A missing JAR could lead to silent failures or parsing issues.
内容的提问来源于stack exchange,提问作者SomeDude

