combined_ftest_5x2cv: accuracy vs error rates
Hi @rasbt, First of all thanks for the implementations and the teaching material. It is really appreciated. I want to use this test is r, so I was looking at your python implementation to get an idea. I would like to ask you a technical detail that is not clear to me: I saw that in your function "combined_ftest_5x2cv", in a classification case, you use the "accuracy" as the default scoring. When looking at the papers Dietterich 1998 and Alpaydin 1998, they mentioned this scoring ($p_i^{(j)}$) as "error rates" or "observed proportion of test examples misclassified by algorithm". Are you using the "accuracy" scoring because the math at the end does not change (considering accuracy = 1-error rate, and the difference between the algorithms cancel this "1-" operation) ?
Thanks in advance Best Alberto
Your implementation: `` if scoring is None: if estimator1._estimator_type == "classifier": scoring = "accuracy" <-- HERE elif estimator1._estimator_type == "regressor": scoring = "r2" else: raise AttributeError("Estimator must " "be a Classifier or Regressor.") if isinstance(scoring, str): scorer = get_scorer(scoring) else: scorer = scoring
variances = [] differences = []
def score_diff(X_1, X_2, y_1, y_2): estimator1.fit(X_1, y_1) estimator2.fit(X_1, y_1) est1_score = scorer(estimator1, X_2, y_2) <-- HERE est2_score = scorer(estimator2, X_2, y_2) <-- HERE score_diff = est1_score - est2_score <-- HERE return score_diff ´´
For fixed train/test splits and fitted predictions, yes: accuracy and misclassification rate give the same combined F statistic and p-value, up to floating-point rounding.
If e_A = 1 - a_A and e_B = 1 - a_B, their difference is d_error = e_A - e_B = -(a_A - a_B) = -d_accuracy. Negating both differences in each repetition also negates their mean, leaving both the squared-difference numerator and the within-repetition variance unchanged. These are exactly the quantities used by the current implementation.
Here is a runnable comparison using the bundled Iris data and an explicit positive misclassification-rate scorer:
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from mlxtend.data import iris_data
from mlxtend.evaluate import combined_ftest_5x2cv
X, y = iris_data()
def misclassification_rate(estimator, X, y):
return np.mean(estimator.predict(X) != y)
def evaluate(scoring):
return combined_ftest_5x2cv(
LogisticRegression(max_iter=1000, random_state=1),
DecisionTreeClassifier(random_state=1),
X,
y,
scoring=scoring,
random_seed=1,
)
accuracy_result = evaluate("accuracy")
error_result = evaluate(misclassification_rate)
assert np.isfinite([accuracy_result, error_result]).all()
np.testing.assert_allclose(accuracy_result, error_result, rtol=1e-12, atol=1e-12)
print("accuracy:", accuracy_result)
print("error rate:", error_result)
Output on that revision (MLxtend 0.25.0, scikit-learn 1.9.1, NumPy 2.5.3, SciPy 1.18.1, Python 3.13.16, macOS):
accuracy: (1.1395348837209298, 0.4704629478124442)
error rate: (1.1395348837209305, 0.4704629478124438)
random_seed fixes the splits, not estimator randomness, so the example creates fresh estimators and fixes their random_state too. This equivalence does not generally extend to a different metric such as F1, and the combined F test does not indicate which algorithm is better.
Focused verification: the three existing test_combined_ftest_5x2cv.py tests and two diagnostic controls pass, including identical predictions across all 20 scorer calls, reversed per-split differences, and the default-accuracy/F1 controls. The existing tests emit convergence warnings at their unchanged max_iter=100; the example above uses 1000. No library changes or full-suite validation are claimed.
AI disclosure: this clarification and example were prepared and verified autonomously with AI; no independent human review has been performed.