<jupyter_start><jupyter_text>Q9Implement a multi-channel 1D deep CNN architecture (as shown in Fig. 1) for the seven-class classificationtask. The input and the class labels are given in. mat file format. There is a total of 17160 number ofinstances present in both input and class-label data files. The input data for each instance is amultichannel time series (12-channel) with size as (12 ×800). The class label for each multichannel timeseries instance is given in the class_label.mat file. You can select the training and test instances usinghold-out cross-validation (70% training, 10% validation, and 20% testing). The architecture of the multichannel deep CNN is given as follows. The number of filters, length of each filter, and number of neuronsin the fully connected layers are shown in the following figure. Evaluate individual accuracy and overallaccuracy. (Packages such as Scikitlearn, keras, tensorflow, pytorch etc. are allowed)<jupyter_code>!pip install mat4py
import keras 
import tensorflow as tf
import sklearn
import numpy as np
import pandas as pd
import scipy.io as sio 
import matplotlib.pyplot as plt

from sklearn import preprocessing
from sklearn.metrics import classification_report,confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
from tensorflow.keras.models import Sequential,Model
from tensorflow.keras.layers import Input, Dense, Activation, Flatten, Conv1D, Dropout,MaxPooling1D,MaxPool1D
from tensorflow.keras.optimizers import SGD,Adam
from tensorflow.keras.utils import to_categorical
from sklearn.utils import shuffle
from mat4py import loadmat
data_feats = sio.loadmat('input.mat')
data_feats = pd.DataFrame(data_feats["x"])
data_feats = (np.asarray(data_feats)).T

data_labels=sio.loadmat('class_label.mat') 
data_labels=np.asarray(data_labels["y"])
X_feats = []
for i in range(len(data_feats)):
  X_feats.append(data_feats[i][0])
X_feats=np.asarray(X_feats)
X_feats=X_feats.transpose(0,2,1)
for i in range(len(X_feats)):
  X_feats[i]=preprocessing.normalize(X_feats[i])
Y_labels = []
for i in range(len(data_labels)):
  Y_labels.append(data_labels[i][0]-1)
Y_labels=np.asarray(Y_labels)
training_data_X, testing_data_X, training_data_Y, testing_data_Y = train_test_split(X_feats, Y_labels, test_size = 2/10, train_size = 8/10, random_state = 0)
training_data_X, validation_data_X, training_data_Y, validation_data_Y = train_test_split(training_data_X, training_data_Y, test_size=1/8, train_size=7/8, random_state = 0)
model = Sequential()
model.add(Conv1D(kernel_size=7, filters=20, activation='relu', input_shape=(800,12)))
model.add(MaxPooling1D(pool_size = 3, strides = 3))
model.add(Conv1D(kernel_size = 7, filters = 60, activation = 'relu'))
model.add(MaxPooling1D(pool_size = 3, strides = 3))
model.add(Dropout(0.7))
model.add(Conv1D(filters = 120, kernel_size = 7))
model.add(Conv1D(filters = 120, kernel_size = 7))
model.add(Flatten())
model.add(Dense(2000, activation = 'relu'))
model.add(Dense(700))
model.add(Dense(50))
model.add(Dense(7, activation = 'sigmoid'))
model.summary()
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
history=model.fit(training_data_X, training_data_Y, epochs=10, batch_size=1000, validation_data = (validation_data_X, validation_data_Y))
print(history)<jupyter_output>Epoch 1/10
13/13 [==============================] - 56s 4s/step - loss: 3.3170 - accuracy: 0.2605 - val_loss: 1.5590 - val_accuracy: 0.4266
Epoch 2/10
13/13 [==============================] - 54s 4s/step - loss: 1.1386 - accuracy: 0.6311 - val_loss: 0.5840 - val_accuracy: 0.7686
Epoch 3/10
13/13 [==============================] - 54s 4s/step - loss: 0.3544 - accuracy: 0.8902 - val_loss: 0.0763 - val_accuracy: 0.9808
Epoch 4/10
13/13 [==============================] - 54s 4s/step - loss: 0.1103 - accuracy: 0.9632 - val_loss: 0.0387 - val_accuracy: 0.9854
Epoch 5/10
13/13 [==============================] - 55s 4s/step - loss: 0.0723 - accuracy: 0.9756 - val_loss: 0.0038 - val_accuracy: 1.0000
Epoch 6/10
13/13 [==============================] - 54s 4s/step - loss: 0.0146 - accuracy: 0.9969 - val_loss: 0.0011 - val_accuracy: 1.0000
Epoch 7/10
13/13 [==============================] - 54s 4s/step - loss: 0.0055 - accuracy: 0.9992 - val_loss: 3.0739e-04 - val_accuracy: 1.0000
Epoch 8/10
13/13[...]<jupyter_text>BITS F312 - Neural Network and Fuzzy Logic  NNFL Assignment 2<jupyter_code>from google.colab import drive
drive.mount('/content/drive')
# Changing directory to the directory containing dataset
%cd drive/MyDrive/NNFL/Data_A2/
# listing datasets
%ls -l
# libraries required
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
from pprint import pprint
# supressing warnings
import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14701030927835051, 'fraction_numerical': 0.06494845360824743, 'mean_word_length': 5.832394366197183, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '437621', 'license': 'MIT', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1638, 'n_words': 454, 'path': 'Assignment 2/NNFL_Q9.ipynb', 'repo_name': 'AmiteshBadkul/nnfl', 'size': '4850'}