# Artificial Neural Network - ANN

# Import libraries
import numpy as np
import pandas as pd
import tensorflow as tf
tf.__version__

# Import dataset
dataset = pd.read_('')
X = dataset.iloc[:,:].values
y = dataset.iloc[:,:].values
print(X)
print(y)

# Data Preprocessing
## Encode categorical data

### Label Encoding 
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
X[:] = le.fit_transform(X[:])
print(X)

### One Hot Encoding 
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
print(X)

# Split the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# Build the ANN
## Initialize the ANN
ann = tf.keras.models.Sequential()

## Add the input layer and the first hidden layer
ann.add(tf.keras.layers.Dense(units=6, activation='relu'))

## Add the second hidden layer
ann.add(tf.keras.layers.Dense(units=6, activation='relu'))

## Add the output layer
ann.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))

# Train the ANN
## Compile the ANN
ann.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

## Train the ANN on the Training set
ann.fit(X_train, y_train, batch_size = 32, epochs = 100)

# Evaluating the model and Make Prediction
# Predict the Test set results
y_pred = ann.predict(X_test)
y_pred = (y_pred > 0.5)
print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))

# Evaluate Confusion Matrix
from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)
