text_plain_output_1.png
from sklearn.decomposition import PCA

from sklearn.linear_model import LogisticRegression

from sklearn.model_selection import cross_val_score

from sklearn.model_selection import train_test_split, StratifiedKFold

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import StandardScaler

from sklearn.svm import SVC

import numpy as np # linear algebra

pipeline_1 = Pipeline([('scl', StandardScaler()), ('pca', PCA(n_components=2)), ('clf', LogisticRegression(random_state=1))])
pipeline_1.fit(X_train, y_train)
from sklearn.svm import SVC
pipeline_svm = Pipeline([('scl', StandardScaler()), ('clf', SVC(kernel='linear', C=0.05, random_state=1))])
pipeline_svm.fit(X_train, y_train)

skf = StratifiedKFold(random_state=1, n_splits=2)
resultados = []
for train, test in skf.split(X_train, y_train):
    pipeline_1.fit(X_train[train], y_train[train])
    resultado = pipeline_1.score(X_train[test], y_train[test])
    resultados.append(resultado)

from sklearn.model_selection import cross_val_score
resultados = cross_val_score(estimator=pipeline_1, X=X_train, y=y_train, cv=5, n_jobs=1)
print('CV accuracy scores: %s' % resultados)
print('CV accuracy: %.3f +/- %.3f' % (np.mean(resultados), np.std(resultados)))