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

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn import datasets
from sklearn import decomposition 

# +
# %matplotlib inline

pd.set_option('display.max_columns', None)
# -

dataset = datasets.load_iris()

# +
X = pd.DataFrame(data=dataset.data, columns=dataset.feature_names)
y = pd.Series(data=dataset.target, name='species')

pd.concat([X, y], axis=1).sample(10)
# -

pca = decomposition.PCA(n_components=2)
X_decomposed = pd.DataFrame(data=pca.fit_transform(X), columns=['comp_1', 'comp_2'])

X_decomposed.sample(5)

fig = plt.figure(figsize=(8,8))
ax = plt.axes(projection='3d')
ax.scatter3D(X_decomposed['comp_1'], X_decomposed['comp_2'], y, c=y, cmap='Greens')
ax.set_xlabel('comp 1')
ax.set_ylabel('comp 2')
ax.set_zlabel('species')
ax.set_title('Iris Dataset Decomposed in 3D', fontweight='semibold')
plt.show()



StarcoderdataJupyterScriptsDedupFiltered