<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Model evaluation with pipeline
In this notebook, I will use pipeline to preprocess data, construct model and perform model evaluation with k-fold cross validation. The pipeline will do the following steps
Step1:  Create classifier pipeline
The pipeline preprocesses the data by scaling the feature variable's values to mean zero and unit variance.
The pipeline trains a SVM classifier on the data with C=1. C is the cost function for the margins. The higher the C, the less tolerant the model is for misclassification.
Step2:  Cross validation
Now apply the classifier pipeline to the feature and target data with KFold/StratifiedKFold cross validation.
Step3:  Model evaluation
To get an good measure of the model's accuracy, calculate the mean of the three scores as measure of model accuracy.
<ASSISTANT_TASK:>
Python Code:
from sklearn.datasets import load_iris
from sklearn.pipeline import make_pipeline
from sklearn import preprocessing
from sklearn import model_selection
from sklearn import svm
# load iris data
iris = load_iris()
X = iris.data
y = iris.target
Explanation: Model evaluation with pipeline
In this notebook, I will use pipeline to preprocess data, construct model and perform model evaluation with k-fold cross validation. The pipeline will do the following steps:
Split the raw data into k folds. Select one for testing and two for training.
Preprocess the data by scaling the training features.
Train a classifier on the training data.
Apply the classifier to the test data.
Record the accuracy score.
Repeat steps 1-5 for each fold.
Calculate the mean score for all the folds.
End of explanation
# Create a pipeline that scales the data then trains a support vector classifier
classifier_pipeline = make_pipeline(preprocessing.StandardScaler(), svm.SVC(C=1))
Explanation: Create classifier pipeline
The pipeline preprocesses the data by scaling the feature variable's values to mean zero and unit variance.
The pipeline trains a SVM classifier on the data with C=1. C is the cost function for the margins. The higher the C, the less tolerant the model is for misclassification.
End of explanation
scores = model_selection.cross_val_score(classifier_pipeline, X, y, cv=3)
Explanation: Cross validation
Now apply the classifier pipeline to the feature and target data with KFold/StratifiedKFold cross validation.
End of explanation
scores
scores.mean()
Explanation: Model evaluation
To get an good measure of the model's accuracy, calculate the mean of the three scores as measure of model accuracy.
End of explanation
<END_TASK>