"""
# Classification of poisonous and edible mushrooms
* Objectives 
    
    * Visualizing the data in the dataset
    * Building two models for prediction and comparing results
    
    * We are going to build the models based on :

        * MLP (Multi layer perceptron)
        * Random Forest
    
"""
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn.ensemble import RandomForestClassifier
"""
# Visualizing the data and importing it.
"""
df=pd.read_csv(r'../input/mushroom-classification/mushrooms.csv')
df.describe()
df.head()

for col_name in df.columns:
    unique,counts=np.unique(df[col_name],return_counts=True)
    plt.figure(figsize=(12,6))
    plt.title(col_name)
    plt.bar(unique,counts)
    plt.ylabel('Number of ocurrences')
    plt.xlabel('Possible occurences')
    plt.show()
"""
# Preparing the Data
"""
"""
Transforming the data from categorical to numerical using pandas.
"""
for col_name in df.columns:
    if(df[col_name].dtype == 'object'):
        df[col_name]= df[col_name].astype('category')
        df[col_name] = df[col_name].cat.codes
"""
Organizing the data to build the model
"""
y=df.pop('class')
x=df.values
x_train,x_tst,y_train,y_tst=train_test_split(x,y)
"""
# Building our MLP model with scikit-learn and showing the score 
"""
model=MLPClassifier(max_iter=10000).fit(x_train,y_train)
print(model.score(x_tst,y_tst))
"""
Congratulations in this case you will most likely not die. The MLP algorithm had a perfect prediction. 
"""
"""
# Building our random forest model
"""
"""
In this case we changed the values that the model should predict just to make it more fun 
"""
x_train,x_tst,y_train,y_tst=train_test_split(x,y)
model=RandomForestClassifier().fit(x_train,y_train)
print(model.score(x_tst,y_tst))
"""
It is your lucky day again you would not die =). The random forest algorithm predicted perfectly
"""
"""
**If you enjoyed this notebook please give it a up and feel free to leave a comment any help to make this notebook nicer would be amazing thank you for your attention**
"""