text_plain_output_1.png image_output_1.png
from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import LabelEncoder

from sklearn.tree import DecisionTreeClassifier

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)

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)))

x = df.drop(['class'], axis=1)
y = df['class']

from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier(random_state=0, max_depth=5)
dt.fit(x_train, y_train)

dt.score(x_train, y_train)

predictions = dt.predict(x_test)

print(dict(zip(df.columns, dt.feature_importances_)))