<jupyter_start><jupyter_text>Load IRIS dataset<jupyter_code>#Import scikit-learn dataset library
from sklearn import datasets

# Import other supporting libs

import pandas as pd
import numpy as np

# Generic for data prep and evaluating
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
#Load dataset
iris = datasets.load_iris()
# print the label species(setosa, versicolor,virginica)
print(iris.target_names)

# print the names of the four features
print(iris.feature_names)
data=pd.DataFrame({
    'sepal length':iris.data[:,0],
    'sepal width':iris.data[:,1],
    'petal length':iris.data[:,2],
    'petal width':iris.data[:,3],
    'species':iris.target
})
data.head()
data.info()
x=data[['sepal length', 'sepal width', 'petal length', 'petal width']]  
y=data['species']
# Get a subset for taining and testing
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=0)<jupyter_output><empty_output><jupyter_text>Try different classifier models<jupyter_code># Import models to explore
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.neural_network import MLPClassifier
def train_test_model(model, x_train, x_test, y_train, y_test):
    
    # Train model
    model.fit(x_train, y_train)
    # Predicted values for train and test
    y_pred_train = model.predict(x_train)
    y_pred_test = model.predict(x_test)
    print("Number of mislabeled points out of a total %d points on test: %d"
       % (x_test.shape[0], (y_test != y_pred_test).sum()))
    print("Number of mislabeled points out of a total %d points on training: %d"
       % (x_train.shape[0], (y_train != y_pred_train).sum())) 
    
    # Check via CM
    CM = confusion_matrix(y_test, y_pred_test)
    print ("Confusion Matrix on test:")
    print (CM)
    
# Check via NBC
model = GaussianNB()
train_test_model(model, x_train, x_test, y_train, y_test)
# Check via GBC
model = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,max_depth=1, random_state=0)
train_test_model(model, x_train, x_test, y_train, y_test)
# Check via Random Forest
model = RandomForestClassifier(max_depth=2, random_state=0)
train_test_model(model, x_train, x_test, y_train, y_test)
# Check via NN - MLP
model = MLPClassifier(random_state=1, max_iter=300)
train_test_model(model, x_train, x_test, y_train, y_test)<jupyter_output>Number of mislabeled points out of a total 30 points on test: 0
Number of mislabeled points out of a total 120 points on training: 4
Confusion Matrix on test:
[[11  0  0]
 [ 0 13  0]
 [ 0  0  6]]
{'fraction_non_alphanumeric': 0.10123272319760926, 'fraction_numerical': 0.014942099364960777, 'mean_word_length': 5.286384976525822, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '418855', 'license': 'MIT', 'n_tokens_mistral': 959, 'n_tokens_neox': 929, 'n_words': 262, 'path': 'sample-code/l6-l7-l8-supervised-ml/Supervised-NaiveBayes-GradientBoost-NN-Classification.ipynb', 'repo_name': 'biplav-s/course-d2d-ai', 'size': '2677'}