python Albon k-fold

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Albon k-fold相关的知识,希望对你有一定的参考价值。

# from Chris Albon
# https://chrisalbon.com/machine-learning/cross-validaton.html

#create pipeline
# Create standardizer
standardizer = StandardScaler()

# Create logistic regression
logit = LogisticRegression()

# Create a pipeline that standardizes, then runs logistic regression
pipeline = make_pipeline(standardizer, logit)

# Create k-Fold cross-validation
kf = KFold(n_splits=10, shuffle=True, random_state=1)

# Do k-fold cross-validation
cv_results = cross_val_score(pipeline, # Pipeline
                             X, # Feature matrix
                             y, # Target vector
                             cv=kf, # Cross-validation technique
                             scoring="accuracy", # Loss function
                             n_jobs=-1) # Use all CPU scores
# Calculate mean
cv_results.mean()

以上是关于python Albon k-fold的主要内容,如果未能解决你的问题,请参考以下文章

K-fold 交叉验证查询

K-fold Train

如何在情感分析中添加混淆矩阵和k-fold 10折

K-Fold 如何防止模型中的过度拟合

在 k-Fold 交叉验证中,是不是为 Sklearn 中的每个折叠启动了一个新模型?

用于文本分类的神经网络中的 K-Fold