Ctrl + M for making heading
# import the neccassry libraries and mount the drive first
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow import keras
import [Link] as plt
from [Link] import Sequential
from [Link] import layers
from [Link] import mean_absolute_error
from [Link] import mean_squared_error
from [Link] import StandardScaler
from sklearn.model_selection import train_test_split
from [Link] import drive
from sklearn import preprocessing
[Link]('/content/drive')
Shift + Enter
for cell execution
[Link]()
Viewing the first 5 lines/ rows
[Link]()
provides a concise summary of a DataFrame. It displays information about the DataFrame, such as the
number of rows and columns, the data types of each column, the number of non-null values, and the
memory usage
[Link].value_counts()
For counting number of unique values in the target column.
The resulting object will be in descending order so that the first element is the most frequently-
occurring element. Excludes NA values by default.
i.e. 1 1000
0 500
[Link]()
The info() method prints information about the DataFrame.
The information contains the number of columns, column labels, column data types, memory
usage, range index, and the number of cells in each column (non-null values).
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=42)
Here,
X_train: is Input for Training Set (Total Data of Training Set)
X_test: is input for Test Set
y_train: is Label for Training Set
y_test: is Label for Test Set
print ("X_train: ", X_train)
print ("y_train: ", y_train)
print("X_test: ", X_test)
print ("y_test: ", y_test)
# Add a Flatten layer to flatten the input data
[Link]([Link](input_shape=(13, 1)))
Flatten layer make these 13 dimensions () into Column Vector
# Add one or more Dense layers
[Link]([Link](64, activation='relu'))
Dense means every member of the previous layer (Every member of column
Vector is connected with 64 neurons.
# You can add more hidden layers if needed
[Link]([Link](32, activation='relu'))
Above 64 neurons are connected to every member of the 32 neurons.
# Add the output layer with a single neuron and sigmoid activation for
binary classification
[Link]([Link](1, activation='sigmoid'))
Above 32 neurons are connected to only one neuron.
import numpy as np
import [Link] as plt
from [Link] import Conv1D, Activation, SpatialDropout1D
from [Link] import LayerNormalization, concatenate, Flatten
from [Link] import Adam
from [Link] import Input, Model
from [Link] import Dense
from [Link] import Precision, Recall, TruePositives, TrueNegatives, FalsePositives,
FalseNegatives, AUC
from [Link] import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix,
roc_auc_score, roc_curve
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow import keras
from [Link] import layers
# Define the ANN model
model = [Link]()
# Add a Flatten layer to flatten the input data
[Link]([Link](input_shape=(13, 1)))
# Add one or more Dense layers
[Link]([Link](64, activation='relu'))
# You can add more hidden layers if needed
[Link]([Link](32, activation='relu'))
# Add the output layer with a single neuron and sigmoid activation for binary classification
[Link]([Link](1, activation='sigmoid'))
# Define additional performance metrics
metrics = [
'accuracy',
Precision(name='precision'),
Recall(name='recall'),
AUC(name='auc')
# Compile the model with the specified metrics
[Link](loss='binary_crossentropy', optimizer='adam', metrics=metrics)
In Keras, compiling the model means configuring the learning process. It's where you define the
optimizer, loss function, and metrics that you want to use. The optimizer is the algorithm that adjusts
the weights of the network to minimize the loss function.
random_state = 1 Controls the shuffling applied to the data before applying the split.
The Merge layer
Multiple Sequential instances can be merged into a single output via a Merge layer. The output
is a layer that can be added as first layer in a new Sequential model. For instance, here's a
model with two separate input branches getting merged:
from [Link] import Merge
left_branch = Sequential()
left_branch.add(Dense(32, input_dim=784))
right_branch = Sequential()
right_branch.add(Dense(32, input_dim=784))
merged = Merge([left_branch, right_branch], mode='concat')
final_model = Sequential()
final_model.add(merged)
final_model.add(Dense(10, activation='softmax'))
[Link]