text_plain_output_1.png
from sklearn.cluster import KMeans

from sklearn.decomposition import PCA

from sklearn.metrics import auc

from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import StandardScaler

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)

plt.figure(figsize=(10, 9))
plt.plot(fpr, tpr, label='AUC= %0.2f' % lr_auc)
plt.plot([0, 1], [0, 1], linestyle='--')
plt.legend()