<jupyter_start><jupyter_text>Importing library<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Importing dataset<jupyter_code>from sklearn import datasets
iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['flower'] = iris.target
df.head()
iris.target_names<jupyter_output><empty_output><jupyter_text>Exploring the dataset<jupyter_code>df.groupby(['flower']).mean()<jupyter_output><empty_output><jupyter_text>Features plot for different flowers.<jupyter_code>for i, feature in enumerate(iris.feature_names):
    plt.figure(i + 1)
    for j, flower in enumerate(iris.target_names):
        plt.figure(figsize=(10, 10))
        plt.subplot(310 + j + 1)
        plt.hist(df[df['flower'] == j]['sepal length (cm)'], rwidth=0.8, bins=5)
        plt.title(flower)
        plt.xlabel(feature)
        plt.ylabel('Size')
plt.show()<jupyter_output><empty_output><jupyter_text>Correlation map<jupyter_code>plt.figure(figsize=(10,10))
sns.heatmap(df.corr(), linewidths=0.8, square=True)<jupyter_output><empty_output><jupyter_text>Training and testing<jupyter_code>X = df.drop(['flower'], axis=1)
y = df['flower']

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3)<jupyter_output><empty_output><jupyter_text>Logitic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression

clf = LogisticRegression()
clf = clf.fit(X_train, y_train)
print("Train score:", clf.score(X_train, y_train))
print("Test score:", clf.score(X_test, y_test))<jupyter_output>Train score: 0.961904761905
Test score: 0.911111111111<jupyter_text>Logistic Regression performs well.  Naive Bayes<jupyter_code>from sklearn.naive_bayes import GaussianNB

clf = GaussianNB()
clf = clf.fit(X_train, y_train)
print("Train score:", clf.score(X_train, y_train))
print("Test score:", clf.score(X_test, y_test))<jupyter_output>Train score: 0.961904761905
Test score: 0.955555555556<jupyter_text>Clearly Naive Bayes performs decently well, perhaps due to features following gaussian distribution.  Decision Tree Classifier<jupyter_code>from sklearn.tree import DecisionTreeClassifier

clf = DecisionTreeClassifier()
clf = clf.fit(X_train, y_train)
print("Train score:", clf.score(X_train, y_train))
print("Test score:", clf.score(X_test, y_test))<jupyter_output>Train score: 1.0
Test score: 0.911111111111<jupyter_text>Decision Tree Classifier performs well. Perhaps less number of features ensure it doesn't overfit.  Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier()
clf = clf.fit(X_train, y_train)
print("Train score:", clf.score(X_train, y_train))
print("Test score:", clf.score(X_test, y_test))<jupyter_output>Train score: 0.980952380952
Test score: 0.955555555556<jupyter_text>Random Forest performs well.  Neural Network<jupyter_code>from sklearn.neural_network import MLPClassifier

clf = MLPClassifier(hidden_layer_sizes=(3, 2))
clf = clf.fit(X_train, y_train)
print("Train score:", clf.score(X_train, y_train))
print("Test score:", clf.score(X_test, y_test))<jupyter_output>Train score: 0.666666666667
Test score: 0.6<jupyter_text>Neural Network performs poorly given small training size.  SVM Classifier<jupyter_code>from sklearn.svm import SVC

clf = SVC()
clf = clf.fit(X_train, y_train)
print("Train score:", clf.score(X_train, y_train))
print("Test score:", clf.score(X_test, y_test))<jupyter_output>Train score: 0.990476190476
Test score: 1.0<jupyter_text>SVM Classifier performs exceedingly well.  Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix
plt.figure(figsize=(10, 10))
sns.heatmap(confusion_matrix(y_test, clf.predict(X_test)), annot=True, fmt="d", square=True, cbar=False, cmap='Reds')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12149770759042282, 'fraction_numerical': 0.038206826286296486, 'mean_word_length': 7.7461024498886415, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 5, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '408531', 'license': 'MIT', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1443, 'n_words': 281, 'path': 'Iris Dataset.ipynb', 'repo_name': 'abhishek0318/ml-playground', 'size': '3926'}