scikit-learn - 在 scikit-learn permutation_test_score 中进行缩放
问题描述
我正在使用 scikit-learn "permutation_test_score" 方法来评估我的估计器性能的重要性。不幸的是,我无法从 scikit-learn 文档中了解该方法是否实现了对数据的任何缩放。我使用通过 StandardScaler 标准化我的数据,将训练集标准化应用于测试集。
解决方案
该函数本身不应用任何缩放。
这是文档中的一个示例:
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)
推荐阅读
- encryption - 通过passlib.hash.pbkdf2_sha512在Node中生成PBKDF sha512 hash
- r - 如何处理变量长度不同的错误
- android - 如何使用 RxJava 从房间中获取数据
- laravel-5.8 - 使用 EmailAddress 作为列名时如何修复
- laravel - Bitbucket 管道 Laravel 与 MySQL php_network_getaddresses
- r - 使用 R 将每个字符行转换为字符串
- python - 如何在字符串中查找模式并在 HTML 代码中替换
- android - 如果使用 Dagger2 初始化对象,是否仍然需要检查其是否为空?
- c# - 我团队的一位高级开发人员告诉我,编写这样的 SQL 命令是安全的,“因为它是参数化的”,但我不明白如何
- corda - 如何修复在测试网错误中将cordapp部署到corda节点