<jupyter_start><jupyter_text>Ensemble Learning and Cross ValidationKey Terms: XGBoost, AdaBoost, KFold, **<NAME>**<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
%matplotlib inline
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = (18,10)
from sklearn import model_selection
from sklearn.ensemble import AdaBoostClassifier
from google.colab import drive
drive.mount('/content/gdrive')
cd gdrive
cd 'My Drive'
cd 'Colab Notebooks'
df = pd.read_csv('pima-indians-diabetes.csv')
df.head()
array = df.values
X = array[:,0:8]
Y = array[:,8]
seed =7 
num_trees = 30
kfold = model_selection.KFold(n_splits=10,random_state=seed)
model = AdaBoostClassifier(n_estimators=num_trees,random_state=seed)
results = model_selection.cross_val_score(model,X,Y,cv=kfold)
print(results)
print(results.mean())
from sklearn import svm
from xgboost import XGBClassifier
clf = XGBClassifier()

seed =7 
num_trees = 30
kfold = model_selection.KFold(n_splits=10,random_state=seed)
model = XGBClassifier(n_estimators=num_trees,random_state=seed)
results = model_selection.cross_val_score(model,X,Y,cv=kfold)
print(results)
print('---------------------')
print(results.mean())<jupyter_output>/usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_split.py:296: FutureWarning: Setting a random_state has no effect since shuffle is False. This will raise an error in 0.24. You should leave random_state to its default (None), or set shuffle=True.
  FutureWarning<jupyter_text>Cross Validation<jupyter_code>from sklearn.datasets import load_iris
iris_data = load_iris()
print(iris_data)
data_input = iris_data.data
data_output = iris_data.target
print(data_input)
print('-------------------------------')
print(data_output)
from sklearn.model_selection import KFold
kf = KFold (n_splits =5, shuffle = True)
print('Train Set        Test Set      ')
for train_set, test_set in kf.split(data_input):
  print(train_set,test_set)
from sklearn.ensemble import RandomForestClassifier
rf_class = RandomForestClassifier(n_estimators=10)
from sklearn.model_selection import cross_val_score
print(cross_val_score(rf_class,data_input, data_output, scoring='accuracy',cv=10))
accuracy = cross_val_score(rf_class,data_input, data_output, scoring='accuracy',cv=10).mean()*100
print('Accuracy of Random Forest is: ', accuracy, '%')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1231404958677686, 'fraction_numerical': 0.014462809917355372, 'mean_word_length': 6.472222222222222, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '308938', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 861, 'n_tokens_neox': 829, 'n_words': 186, 'path': 'ML_Ensemble_Learning.ipynb', 'repo_name': 'kapilkn/ML', 'size': '2429'}