<jupyter_start><jupyter_text>Wine Quality Classifier Status: In process  LOAD THE FEATURE DATA<jupyter_code>import pandas as pd
import numpy as np

X = pd.read_csv('../../../data/preprocessed_data/X.csv', sep=',')

print ('Feature data, shape:\nX: {}'.format(X.shape))
X.head()<jupyter_output>Feature data, shape:
X: (178, 13)<jupyter_text>DATA OVERVIEW<jupyter_code>y = pd.read_csv('../../../data/preprocessed_data/y.csv', sep=',')

print ('Target data, shape:\ny: {}'.format(X.shape))
y.head()<jupyter_output>Target data, shape:
y: (178, 13)<jupyter_text>SPLIT THE DATA<jupyter_code>from sklearn.model_selection import train_test_split

# set the seed for reproducibility
np.random.seed(127)

# split the dataset into 2 training and 2 testing sets
X_train, X_test, y_train, y_test = train_test_split(X.values, y.values, test_size=0.2, random_state=13)

print('Data shapes:\n')
print('X_train : {}\ny_train : {}\n\nX_test : {}\ny_test : {}'.format(np.shape(X_train),
                                                                      np.shape(y_train),
                                                                      np.shape(X_test),
                                                                      np.shape(y_test)))<jupyter_output>Data shapes:

X_train : (142, 13)
y_train : (142, 3)

X_test : (36, 13)
y_test : (36, 3)<jupyter_text>DEFINE NETWORK PARAMETERS<jupyter_code># define number of attributes
n_features = X_train.shape[1]    
n_classes = y_train.shape[1]

# count number of samples in each set of data
n_train = X_train.shape[0]
n_test = X_test.shape[0]

# define amount of neurons
n_layer_in = n_features  # 11 neurons in input layer
n_layer_h1 = 50          # first   hidden layer
n_layer_h2 = 50          # second  hidden layer
n_layer_out = n_classes  # 7 neurons in input layer

sigma_init = 0.01   # For randomized initialization<jupyter_output><empty_output><jupyter_text>MODEL ARCHITECTURE<jupyter_code>from keras.models import Sequential
from keras.layers import Dense
from keras.callbacks import History 

model = Sequential()
model.add(Dense(n_layer_h1, activation='relu', input_shape=(n_features,)))
model.add(Dense(n_layer_h2, activation='relu'))
model.add(Dense(n_classes, activation='softmax'))

# add model's configuration
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])

# add history function to 
history = History()
model.fit(X_train, y_train, epochs=100, callbacks=[history])<jupyter_output>Using TensorFlow backend.<jupyter_text>EVALUATE TESTING SET<jupyter_code># Evaluate the model on the test data using `evaluate`
results = model.evaluate(X_test, y_test)

print('\nEvaluate on test data \n\n(loss), (accuracy) :\n{}'.format(results))<jupyter_output>36/36 [==============================] - 0s 82us/step

Evaluate on test data 

(loss), (accuracy) :
[0.18283655908372667, 0.9722222222222222]<jupyter_text>PRINTING RAW OUTPUT<jupyter_code>predictions = model.predict(X_test)
predictions<jupyter_output><empty_output><jupyter_text>PRINTING RESULTS<jupyter_code>dataframe = pd.DataFrame(np.argmax(predictions,1), columns=['Prediction'])
dataframe['Target'] = np.argmax(y_test, 1)
dataframe['Hit'] = np.equal(dataframe.Target, dataframe.Prediction)
print('\n\nPrinting results :\n\n', dataframe)
print(history.history.keys())<jupyter_output>dict_keys(['acc', 'loss'])<jupyter_text>VISUALIZE THE RESULTS<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

# set up legend
blue_patch = mpatches.Patch(color='blue', label='Train Accuracy [Maximize]')
plt.legend(handles=[blue_patch])

#plot the data
plt.plot(history.history['acc'], color='blue')
plt.ylabel('score');<jupyter_output><empty_output><jupyter_text>VISUALIZE THE LOSS EVOLUTION<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

# set up legend
green_patch = mpatches.Patch(color='green', label='Avg Loss [Minimize]')
plt.legend(handles=[green_patch])

#plot the data
plt.plot(history.history['loss'], color='green')

plt.xlabel('epochs')
plt.ylabel('score');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13788939869596717, 'fraction_numerical': 0.02414875633904854, 'mean_word_length': 4.842031029619182, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '268469', 'license': 'MIT', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1431, 'n_words': 296, 'path': 'python/just_easy_and_simple/simple-mlp-classification-keras-wine.ipynb', 'repo_name': 'igerardoh/wine-quality-classification', 'size': '4141'}