text_plain_output_1.png
from sklearn.cluster import KMeans

from sklearn.decomposition import PCA

from sklearn.metrics import auc

from sklearn.metrics import roc_curve

from sklearn.metrics import roc_curve, auc

from sklearn.naive_bayes import GaussianNB

from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import StandardScaler

from sklearn.tree import DecisionTreeClassifier

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

data = pd.read_csv('../input/mushrooms.csv')

data.shape

from sklearn.preprocessing import LabelEncoder
lbl = LabelEncoder()

for col in data.columns:
    data[col] = lbl.fit_transform(data[col])

y = data['class']
x = data.iloc[:, 1:23]

x.shape

x.head

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x = sc.fit_transform(x)

from sklearn.decomposition import PCA
pca = PCA()
x_pca = pca.fit_transform(x)

new_pca = PCA(n_components=17)

x_new = new_pca.fit_transform(x)

from sklearn.cluster import KMeans
k_means = KMeans(n_clusters=2)

k_means.fit_predict(x_new)

colors = ['r', 'g']

from sklearn.metrics import auc
lr_auc = auc(fpr, tpr)

from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
gnb.fit(x_train, y_train)
gnb_predict = gnb.predict(x_test)
gnb_predict_prob = gnb.predict_proba(x_test)

fpr, tpr, thresholds = roc_curve(y_test, gnb_predict_prob[:, 1])
gnb_auc = auc(fpr, tpr)

from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier(max_depth=10)

dt.fit(x_train, y_train)
dt_predict = dt.predict(x_test)
dt_predict_prob = dt.predict_proba(x_test)

from sklearn.metrics import roc_curve, auc
fpr, tpr, thresholds = roc_curve(y_test, dt_predict_prob[:, 1])
dt_auc = auc(fpr, tpr)

plt.figure(figsize=(10, 9))
plt.plot(fpr, tpr, label='AUC %0.2f' % dt_auc)
plt.plot([0, 1], [0, 1], linestyle='--')
plt.xlabel('False Positive rate')
plt.ylabel('True Positive rate')
plt.legend()
plt.grid()