# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/shubham7226/005_ShubhamBaldaniya/blob/main/Lab11_1.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + colab={"base_uri": "https://localhost:8080/"} id="2zlxXIxeTV34" outputId="92ba9d68-e32b-4a7b-c979-fd6bf6bfe6b7"
# %matplotlib inline
import pandas as pd
from sklearn import datasets
from sklearn.decomposition import PCA
from sklearn import svm,decomposition
import matplotlib.pyplot as plt
import numpy as np 

iris_dataset = datasets.load_iris()
iris_dataset.target_names

# + colab={"base_uri": "https://localhost:8080/"} id="pqbdGH2ATaQL" outputId="a3fc339a-03b6-4320-c54c-5559186b02b2"
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris_dataset.data,iris_dataset.target, random_state=5)
print(X_train.shape, X_test.shape)

# + colab={"base_uri": "https://localhost:8080/", "height": 268} id="KzitFquX7VUo" outputId="9a9e25a8-5589-4992-b80a-193ec77276ef"
# plotting scatters
plt.scatter(iris_dataset.data[:, 0], iris_dataset.data[:, 1], c=iris_dataset.target, s=25,cmap='spring');
plt.show()

# + colab={"base_uri": "https://localhost:8080/"} id="m_ZSidwnTcPS" outputId="af5e053f-630b-4016-d6c1-cb4000b8c3c1"
pca = decomposition.PCA(n_components=3, whiten=True, random_state=5)
pca.fit(X_train)

# + colab={"base_uri": "https://localhost:8080/"} id="vghAalMhTfDK" outputId="52710618-9ec0-4665-bec8-00827bfe8a10"
X_train_pca = pca.transform(X_train)
X_test_pca = pca.transform(X_test)
print(X_train_pca.shape)

clf = svm.SVC(C=3., gamma=0.005, random_state=5)
clf.fit(X_train_pca, y_train)

# + colab={"base_uri": "https://localhost:8080/"} id="QX0Sp99hTg0z" outputId="ac998ed9-a730-4d0b-de72-f4d517e5707e"
from sklearn import metrics
y_pred = clf.predict(X_test_pca)

print(metrics.classification_report(y_test, y_pred))

# + colab={"base_uri": "https://localhost:8080/"} id="Yh6VqpRNTiuL" outputId="ea876787-b4eb-4c3c-be67-0f88fef0a89b"
from sklearn.pipeline import Pipeline
clf = Pipeline([('pca', decomposition.PCA(n_components=3, whiten=True)), ('svm', svm.LinearSVC(C=3.0))])

clf.fit(X_train, y_train)

y_pred = clf.predict(X_test)
print(metrics.confusion_matrix(y_pred, y_test))

StarcoderdataJupyterScriptsDedupFiltered