<jupyter_start><jupyter_text>Confusion MatricsWe can going to Beyond accuracy score and introduce better way to judge , how well our model is !!<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam, SGD
df = pd.read_csv('/content/drive/My Drive/Google Colab/Neural Network/Keras/My_Code_Keras/user_visit_duration.csv')
df.head()
model = Sequential()
model.add(Dense(1, input_shape=(1,), activation='sigmoid'))
model.compile(SGD(lr=0.5), 'binary_crossentropy', metrics=['accuracy'])
model.summary()
x = df[['Time (min)']].values
y = df['Buy'].values

model.fit(x, y, epochs=25)<jupyter_output>Epoch 1/25
100/100 [==============================] - 0s 256us/step - loss: 0.3816 - acc: 0.8200
Epoch 2/25
100/100 [==============================] - 0s 172us/step - loss: 0.3811 - acc: 0.8200
Epoch 3/25
100/100 [==============================] - 0s 168us/step - loss: 0.3813 - acc: 0.8200
Epoch 4/25
100/100 [==============================] - 0s 171us/step - loss: 0.3859 - acc: 0.8300
Epoch 5/25
100/100 [==============================] - 0s 151us/step - loss: 0.3848 - acc: 0.8200
Epoch 6/25
100/100 [==============================] - 0s 164us/step - loss: 0.3976 - acc: 0.8000
Epoch 7/25
100/100 [==============================] - 0s 185us/step - loss: 0.3799 - acc: 0.8300
Epoch 8/25
100/100 [==============================] - 0s 169us/step - loss: 0.3812 - acc: 0.8300
Epoch 9/25
100/100 [==============================] - 0s 175us/step - loss: 0.3824 - acc: 0.8300
Epoch 10/25
100/100 [==============================] - 0s 173us/step - loss: 0.3835 - acc: 0.8200
Epoch 11/25
100/100 [========[...]<jupyter_text>Confusion Matrics* Over All Accuracy : (Total Positive + Total Negetive) / Total  (TP + TN) / total* Precision : TP / test yes* Recall : TP / actual yes* F1 : 2 * (P*R) / (P+R)<jupyter_code>y_pred = model.predict(x)
y_class_pred = y_pred> 0.5
from sklearn.metrics import confusion_matrix
confusion_matrix(y, y_class_pred)
def pretty_confusion_matrix(y, y_pred, labels=["False", "True"]):
  cm = confusion_matrix(y, y_pred)
  pred_labels = ['Predicted '+ l for l in labels]
  df = pd.DataFrame(cm, index=labels, columns=pred_labels)
  return df
pretty_confusion_matrix(y, y_class_pred, ['Not Buy' , 'Buy'])
from sklearn.metrics import precision_score, recall_score, f1_score
print("Precision score :\t{:0.3f}".format(precision_score(y, y_class_pred))," 43 / (43+11)")
print("Recall score :\t\t{:0.3f}".format(recall_score(y, y_class_pred)), " 43 / (43+7)")
print("F1 score :\t\t{:0.3f}".format(f1_score(y, y_class_pred)), " 2*(P*R) / (P+R)")
from sklearn.metrics import classification_report
print(classification_report(y, y_class_pred))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.24673490998941053, 'fraction_numerical': 0.09601129544652312, 'mean_word_length': 5.094623655913979, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '232620', 'license': 'MIT', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1018, 'n_words': 254, 'path': 'Code/5-Confusion_Matrix.ipynb', 'repo_name': 'shahinvx/Keras_Basic', 'size': '2833'}