<jupyter_start><jupyter_text>Support Vector Machine ProjectIn this project, we'll use the famous iris dataset. This dataset is a multivariate dataset introduced by <NAME> in 1936 as an example of discriminant analysis.The dataset consists of 50 samples fro each of tree species of Iris (Iris setosa, Iris Virginia, and Iris versicolor), so 150 total samples. Four features were measured from each sample: the length and the width of the sepals and petals, in centimeters.The three classes in the Iris dataset:    Iris-setosa (n=50)    Iris-versicolor (n=50)    Iris-virginica (n=50)The four features of the Iris dataset:    sepal length in cm    sepal width in cm    petal length in cm    petal width in cm  Import Libraries<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Get the Data<jupyter_code>iris = sns.load_dataset('iris')
iris.head()<jupyter_output><empty_output><jupyter_text>EAD<jupyter_code>sns.set_style('darkgrid')
sns.pairplot(data=iris, hue='species')
setosa = iris[iris['species'] == 'setosa']

sns.kdeplot(setosa['sepal_width'], setosa['sepal_length'],
                cmap='plasma', shade=True, shade_lowest=False)<jupyter_output><empty_output><jupyter_text>Train Test Split<jupyter_code>from sklearn.model_selection import train_test_split
X = iris.drop('species', axis=1)
y = iris['species']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.35)<jupyter_output><empty_output><jupyter_text>Train a ModelNow its time to train a Suppoert Vector Machine Classifier<jupyter_code>from sklearn.svm import SVC
svc = SVC()
svc.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code>predictions = svc.predict(X_test)
from sklearn.metrics import confusion_matrix, classification_report
print(confusion_matrix(y_test, predictions))
print(classification_report(y_test, predictions))<jupyter_output>precision    recall  f1-score   support

     setosa       1.00      1.00      1.00        23
 versicolor       0.92      1.00      0.96        12
  virginica       1.00      0.94      0.97        18

avg / total       0.98      0.98      0.98        53<jupyter_text>We can note that our model is pretty good! Let's see if we can tune the parameters to try to get even better (unlikely, and we probably would be satisfied with these results in real like because the data set is quite small, but I just want we to practice using GridSearch)  Gridsearch<jupyter_code>from sklearn.model_selection import GridSearchCV
param_grid = {'C':[0.1, 1, 10, 100, 1000], 'gamma':[1, 0.1, 0.01, 0.001, 0.0001]}
grid = GridSearchCV(SVC(), param_grid, refit=True, verbose=3)

grid.fit(X_train, y_train)
grid_predictions = grid.predict(X_test)
print(confusion_matrix(y_test, grid_predictions))
print(classification_report(y_test, grid_predictions))<jupyter_output>precision    recall  f1-score   support

     setosa       1.00      1.00      1.00        23
 versicolor       0.92      0.92      0.92        12
  virginica       0.94      0.94      0.94        18

avg / total       0.96      0.96      0.96        53
{'fraction_non_alphanumeric': 0.08616921635966282, 'fraction_numerical': 0.04277240087418046, 'mean_word_length': 3.998439937597504, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '346808', 'license': 'MIT', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1057, 'n_words': 313, 'path': 'notebooks/projects/SVM-Project.ipynb', 'repo_name': 'jralbbuquerque/ds-machine-learning', 'size': '3214'}