<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Title
Step1:  Load Iris Dataset
Step2:  Create Pipeline With Model Selection Search Space
Notice that we include both multiple possible learning algorithms and multiple possible hyperparameter values to search over.
Step3:  Create Model Selection Using Grid Search
Step4:  Conduct Model Selection Using Grid Search
Step5:  View Best Model And Its Best Hyperparameters
Step6:  Predict Using Best Model
<ASSISTANT_TASK:>
Python Code:
# Load libraries
import numpy as np
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
# Set random seed
np.random.seed(0)
Explanation: Title: Model Selection Using Grid Search
Slug: model_selection_tuning_using_grid_search
Summary: How to conduct grid search for model selection in scikit-learn for machine learning in Python. 
Date: 2017-09-18 12:00
Category: Machine Learning
Tags: Model Selection
Authors: Chris Albon
<a alt="Model Selection Using Grid Search" href="https://machinelearningflashcards.com">
    <img src="model_selection_tuning_using_grid_search/Model_Selection_print.png" class="flashcard center-block">
</a>
Preliminaries
End of explanation
# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target
Explanation: Load Iris Dataset
End of explanation
# Create a pipeline
pipe = Pipeline([('classifier', RandomForestClassifier())])
# Create space of candidate learning algorithms and their hyperparameters
search_space = [{'classifier': [LogisticRegression()],
                 'classifier__penalty': ['l1', 'l2'],
                 'classifier__C': np.logspace(0, 4, 10)},
                {'classifier': [RandomForestClassifier()],
                 'classifier__n_estimators': [10, 100, 1000],
                 'classifier__max_features': [1, 2, 3]}]
Explanation: Create Pipeline With Model Selection Search Space
Notice that we include both multiple possible learning algorithms and multiple possible hyperparameter values to search over.
End of explanation
# Create grid search 
clf = GridSearchCV(pipe, search_space, cv=5, verbose=0)
Explanation: Create Model Selection Using Grid Search
End of explanation
# Fit grid search
best_model = clf.fit(X, y)
Explanation: Conduct Model Selection Using Grid Search
End of explanation
# View best model
best_model.best_estimator_.get_params()['classifier']
Explanation: View Best Model And Its Best Hyperparameters
End of explanation
# Predict target vector
best_model.predict(X)
Explanation: Predict Using Best Model
End of explanation
<END_TASK>