text_html_output_1.png
from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import LabelEncoder

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('../input/mushroom-classification/mushrooms.csv')

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df = df.apply(LabelEncoder().fit_transform)

f, ax = plt.subplots(1, 2, figsize = (15, 7))
df['class'].value_counts().plot.bar(ax=ax[0])
df['class'].value_counts().plot.pie(ax=ax[1], autopct = "%.2f%%");

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df = df.apply(LabelEncoder().fit_transform)

pca_2d = PCA(n_components=2)
pca_3d = PCA(n_components=3)

PCs_2d = pd.DataFrame(pca_2d.fit_transform(df.drop(['class'], axis=1)))
PCs_3d = pd.DataFrame(pca_3d.fit_transform(df.drop(['class'], axis=1)))

PCs_2d.columns = ['PC1_2d', 'PC2_2d']
PCs_3d.columns = ['PC1_3d', 'PC2_3d', 'PC3_3d']

from mpl_toolkits.mplot3d import Axes3D
x = PCs_3d.iloc[:, 1]
y = PCs_3d.iloc[:, 2]
c = df['class']
ax.scatter(x, y, c=c, cmap='coolwarm')
plt.title('First 3 Principal Components')
ax.set_ylabel('PC2')
ax.set_xlabel('PC1')
ax.set_zlabel('PC3')
plt.legend()