我正在使用 scikit-learn "permutation_test_score" 方法来评估我的估计器性能的重要性。不幸的是,我无法从 scikit-learn 文档中了解该方法是否实现了对数据的任何缩放。我使用通过 StandardScaler 标准化我的数据,将训练集标准化应用于测试集。
问问题
659 次
1 回答
1
该函数本身不应用任何缩放。
这是文档中的一个示例:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import permutation_test_score
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data
y = iris.target
n_classes = np.unique(y).size
# Some noisy data not correlated
random = np.random.RandomState(seed=0)
E = random.normal(size=(len(X), 2200))
# Add noisy data to the informative features for make the task harder
X = np.c_[X, E]
svm = SVC(kernel='linear')
cv = StratifiedKFold(2)
score, permutation_scores, pvalue = permutation_test_score(
svm, X, y, scoring="accuracy", cv=cv, n_permutations=100, n_jobs=1)
但是,您可能想要做的是传入应用缩放的permutation_test_score
a 。pipeline
例子:
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
pipe = Pipeline([('scaler', StandardScaler()), ('clf', SVC(kernel='linear'))])
score, permutation_scores, pvalue = permutation_test_score(
pipe, X, y, scoring="accuracy", cv=cv, n_permutations=100, n_jobs=1)
于 2018-07-12T08:49:32.813 回答