SlideShare a Scribd company logo
1 of 10
Download to read offline
I want you to add the output of the F1 score, Precision, ROC AUC, and Cohen kappa to fit in the
code below, and please consider the code provided.
import os
import numpy as np
import pandas as pd
import keras
import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import load_img
from keras.utils import to_categorical
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import random
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, MaxPool2D , Dropout, Flatten, Dense,
Activation, BatchNormalization
from keras.callbacks import EarlyStopping, ReduceLROnPlateau
from sklearn.utils import class_weight
import keras,os
from keras.models import Sequential
from keras.layers import Dense, Conv2D, MaxPool2D , Flatten
from keras.preprocessing.image import ImageDataGenerator
import numpy as np
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint, EarlyStopping
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score,
cohen_kappa_score, roc_auc_score
print(os.listdir("D:RansomSecondApproachRansomware_Detection_using
_CNNMixImages"))
# Define Constants
FAST_RUN = False
IMAGE_WIDTH=256 # 150 accept maybe 256
IMAGE_HEIGHT=256 # maybe 256
IMAGE_SIZE=(IMAGE_WIDTH, IMAGE_HEIGHT)
IMAGE_CHANNELS=3 # maybe not need
physical_devices = tf.config.experimental.list_physical_devices('GPU')
print(physical_devices)
if physical_devices:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
# Prepare Traning Data
filenames = os.listdir("D:RansomSecondApproachRansomware_Detection_using
_CNNMixImages")
categories = []
for filename in filenames:
category = filename.split('l')[0]
if category == 'image_benign_':
categories.append(0)
else:
categories.append(1)
df = pd.DataFrame({
'filename': filenames,
'category': categories
})
print(df.head())
print(df.tail())
# in collab it will work
df['category'].value_counts().plot.bar()
model = Sequential()
model.add(Conv2D(16, (3, 3), activation='relu', input_shape=(IMAGE_WIDTH,
IMAGE_HEIGHT, IMAGE_CHANNELS)))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.5))
model.add(Dense(2, activation='softmax')) # 2 because we have cat and dog classes
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# Callbacks
## Early Stop To prevent over fitting we will stop the learning after 10 epochs and val_loss value
not decreased
earlystop = EarlyStopping(patience=10)
# Learning Rate Reduction
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc',
patience=2,
verbose=1,
factor=0.5,
min_lr=0.00001)
callbacks = [earlystop, learning_rate_reduction]
#Prepare data
df["category"] = df["category"].replace({0: 'benign', 1: 'malware'})
train_df, validate_df = train_test_split(df, test_size=0.20, random_state=42)
train_df = train_df.reset_index(drop=True)
validate_df = validate_df.reset_index(drop=True)
total_train = train_df.shape[0]
total_validate = validate_df.shape[0]
batch_size= 15 # defualt 15
# Traning Generator
# Defualt
train_datagen = ImageDataGenerator(
rotation_range=15,
rescale=1./255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=True,
width_shift_range=0.1,
height_shift_range=0.1
)
###############################################
# Augmenting the training data
train_generator = train_datagen.flow_from_dataframe(
train_df,
"D:RansomSecondApproachRansomware_Detection_using _CNNMixImages",
x_col='filename',
y_col='category',
target_size=IMAGE_SIZE,
class_mode='categorical',
batch_size=batch_size
)
# Validation Generator
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = validation_datagen.flow_from_dataframe(
validate_df,
"D:RansomSecondApproachRansomware_Detection_using _CNNMixImages",
x_col='filename',
y_col='category',
target_size=IMAGE_SIZE,
class_mode='categorical',
batch_size=batch_size
)
# See how our generator work
example_df = train_df.sample(n=1).reset_index(drop=True)
example_generator = train_datagen.flow_from_dataframe(
example_df,
"D:RansomSecondApproachRansomware_Detection_using _CNNMixImages",
x_col='filename',
y_col='category',
target_size=IMAGE_SIZE,
class_mode='categorical'
)
# in collab it will work
plt.figure(figsize=(12, 12))
for i in range(0, 15):
plt.subplot(5, 3, i+1)
for X_batch, Y_batch in example_generator:
image = X_batch[0]
plt.imshow(image)
break
plt.tight_layout()
plt.show()
# compile
epochs = 1 # if FAST_RUN else 50
history = model.fit(
train_generator,
epochs=epochs,
validation_data=validation_generator,
validation_steps=total_validate//batch_size,
steps_per_epoch=total_train//batch_size,
# class_weight=class_weights, # add
# shuffle=True,
callbacks=callbacks
)
model.save_weights("model.h5")
# Virtualize Training
##in collab
# fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12))
# ax1.plot(history.history['loss'], color='b', label="Training loss")
# ax1.plot(history.history['val_loss'], color='r', label="validation loss")
# ax1.set_xticks(np.arange(1, epochs, 1))
# ax1.set_yticks(np.arange(0, 1, 0.1))
# ax2.plot(history.history['acc'], color='b', label="Training accuracy")
# ax2.plot(history.history['val_acc'], color='r',label="Validation accuracy")
# ax2.set_xticks(np.arange(1, epochs, 1))
# legend = plt.legend(loc='best', shadow=True)
# plt.tight_layout()
# plt.show()
# Prepare Testing Data
test_filenames = os.listdir("D:RansomSecondApproachRansomware_Detection_using
_CNNMixImages")
test_df = pd.DataFrame({
'filename': test_filenames
})
nb_samples = test_df.shape[0]
# Create Testing Generator
# output Found 12500 images in kaggle.
test_gen = ImageDataGenerator(rescale=1./255)
test_generator = test_gen.flow_from_dataframe(
test_df,
"D:RansomSecondApproachRansomware_Detection_using _CNNMixImages",
x_col='filename',
y_col=None,
class_mode=None,
target_size=IMAGE_SIZE,
batch_size=batch_size,
shuffle=False
)
# Predict
predict = model.predict_generator(test_generator, steps=np.ceil(nb_samples/batch_size))
test_df['category'] = np.argmax(predict, axis=-1)
label_map = dict((v,k) for k,v in train_generator.class_indices.items())
test_df['category'] = test_df['category'].replace(label_map)
test_df['category'] = test_df['category'].replace({ 0: 'benign', 1: 'malware' })
# Virtaulize Result
# Compute the average training and validation accuracy
avg_train_acc = np.mean(history.history['accuracy'])
avg_val_acc = np.mean(history.history['val_accuracy'])
# Print the average training and validation accuracy
print("Average training accuracy:", avg_train_acc)
print("Average validation accuracy:", avg_val_acc)
#in collab
test_df['category'].value_counts().plot.bar()
# See predicted result with images
# in collab
sample_test = test_df.head(18)
sample_test.head()
plt.figure(figsize=(12, 24))
for index, row in sample_test.iterrows():
filename = row['filename']
category = row['category']
img = load_img("D:RansomSecondApproachRansomware_Detection_using
_CNNMixImages" +filename, target_size=IMAGE_SIZE)
plt.subplot(6, 3, index+1)
plt.imshow(img)
plt.xlabel(filename + '(' + "{}".format(category) + ')' )
plt.tight_layout()
plt.show()
# Submission
submission_df = test_df.copy()
submission_df['id'] = submission_df['filename'].str.split('.').str[0]
submission_df['label'] = submission_df['category']
submission_df.drop(['filename', 'category'], axis=1, inplace=True)
submission_df.to_csv('submission.csv', index=False)

More Related Content

Similar to I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf

29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptxKASHYAPPATHAK7
 
Assignment 6.1.pdf
Assignment 6.1.pdfAssignment 6.1.pdf
Assignment 6.1.pdfdash41
 
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfUsing the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfacteleshoppe
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django ormDenys Levchenko
 
Unit tests and mocks
Unit tests and mocksUnit tests and mocks
Unit tests and mocksAyla Khan
 
GANS Project for Image idetification.pdf
GANS Project for Image idetification.pdfGANS Project for Image idetification.pdf
GANS Project for Image idetification.pdfVivekanandaGN1
 
Python program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docxPython program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docxLukeQVdGrantg
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)TarunPaparaju
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnnDebarko De
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsBram Vogelaar
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Thomas Fan
 
Viktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceViktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceLviv Startup Club
 
Angular Unit Testing NDC Minn 2018
Angular Unit Testing NDC Minn 2018Angular Unit Testing NDC Minn 2018
Angular Unit Testing NDC Minn 2018Justin James
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con djangoTomás Henríquez
 
Into React-DOM.pptx
Into React-DOM.pptxInto React-DOM.pptx
Into React-DOM.pptxRan Wahle
 
From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerGuy Hadash
 

Similar to I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf (20)

29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx
 
Assignment 6.1.pdf
Assignment 6.1.pdfAssignment 6.1.pdf
Assignment 6.1.pdf
 
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfUsing the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdf
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django orm
 
Unit tests and mocks
Unit tests and mocksUnit tests and mocks
Unit tests and mocks
 
GANS Project for Image idetification.pdf
GANS Project for Image idetification.pdfGANS Project for Image idetification.pdf
GANS Project for Image idetification.pdf
 
Python program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docxPython program to build deep learning algorithm using a CNNs model to.docx
Python program to build deep learning algorithm using a CNNs model to.docx
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnn
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloads
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
 
Viktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceViktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning Service
 
Angular Unit Testing NDC Minn 2018
Angular Unit Testing NDC Minn 2018Angular Unit Testing NDC Minn 2018
Angular Unit Testing NDC Minn 2018
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
 
Dive Into PyTorch
Dive Into PyTorchDive Into PyTorch
Dive Into PyTorch
 
Kendoui
KendouiKendoui
Kendoui
 
Into React-DOM.pptx
Into React-DOM.pptxInto React-DOM.pptx
Into React-DOM.pptx
 
From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow Eager
 
Itsjustangular
ItsjustangularItsjustangular
Itsjustangular
 

More from GordonF2XPatersonh

import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
import java-lang-Comparable-  -- new Main-String-() public class Main-.pdfimport java-lang-Comparable-  -- new Main-String-() public class Main-.pdf
import java-lang-Comparable- -- new Main-String-() public class Main-.pdfGordonF2XPatersonh
 
In 2022- Jacques paid the following interest- Interest on home mortgag.pdf
In 2022- Jacques paid the following interest- Interest on home mortgag.pdfIn 2022- Jacques paid the following interest- Interest on home mortgag.pdf
In 2022- Jacques paid the following interest- Interest on home mortgag.pdfGordonF2XPatersonh
 
In 2020- the world was made aware of the highly contagious and occasio.pdf
In 2020- the world was made aware of the highly contagious and occasio.pdfIn 2020- the world was made aware of the highly contagious and occasio.pdf
In 2020- the world was made aware of the highly contagious and occasio.pdfGordonF2XPatersonh
 
Implement an extended version of the Caesar cipher that users the char.pdf
Implement an extended version of the Caesar cipher that users the char.pdfImplement an extended version of the Caesar cipher that users the char.pdf
Implement an extended version of the Caesar cipher that users the char.pdfGordonF2XPatersonh
 
Implement FIFO queue using two stacks in Python- Methods should have O.pdf
Implement FIFO queue using two stacks in Python- Methods should have O.pdfImplement FIFO queue using two stacks in Python- Methods should have O.pdf
Implement FIFO queue using two stacks in Python- Methods should have O.pdfGordonF2XPatersonh
 
import java-util-ArrayList- public class Bus { private String na.pdf
import java-util-ArrayList-   public class Bus {     private String na.pdfimport java-util-ArrayList-   public class Bus {     private String na.pdf
import java-util-ArrayList- public class Bus { private String na.pdfGordonF2XPatersonh
 
Imagine a natural area near your hometown that has been identified as.pdf
Imagine a natural area near your hometown that has been identified as.pdfImagine a natural area near your hometown that has been identified as.pdf
Imagine a natural area near your hometown that has been identified as.pdfGordonF2XPatersonh
 
If you wish to estimate a population mean with a sampling distribution.pdf
If you wish to estimate a population mean with a sampling distribution.pdfIf you wish to estimate a population mean with a sampling distribution.pdf
If you wish to estimate a population mean with a sampling distribution.pdfGordonF2XPatersonh
 
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdfigate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdfGordonF2XPatersonh
 
If you have a dataset with n-42- mean is 50- the standard deviation is.pdf
If you have a dataset with n-42- mean is 50- the standard deviation is.pdfIf you have a dataset with n-42- mean is 50- the standard deviation is.pdf
If you have a dataset with n-42- mean is 50- the standard deviation is.pdfGordonF2XPatersonh
 
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdfIf you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdfGordonF2XPatersonh
 
If X has a binomial random variable with probability distribution f(x).pdf
If X has a binomial random variable with probability distribution f(x).pdfIf X has a binomial random variable with probability distribution f(x).pdf
If X has a binomial random variable with probability distribution f(x).pdfGordonF2XPatersonh
 
If we look at the diagram below we notice that there are soveral chara.pdf
If we look at the diagram below we notice that there are soveral chara.pdfIf we look at the diagram below we notice that there are soveral chara.pdf
If we look at the diagram below we notice that there are soveral chara.pdfGordonF2XPatersonh
 
If total assets decrease- then which of the following statements is tr.pdf
If total assets decrease- then which of the following statements is tr.pdfIf total assets decrease- then which of the following statements is tr.pdf
If total assets decrease- then which of the following statements is tr.pdfGordonF2XPatersonh
 
If two different accountants were to estimate the percentage of custom.pdf
If two different accountants were to estimate the percentage of custom.pdfIf two different accountants were to estimate the percentage of custom.pdf
If two different accountants were to estimate the percentage of custom.pdfGordonF2XPatersonh
 
If the radius of the Earth were to increase by a factor of 4 while its.pdf
If the radius of the Earth were to increase by a factor of 4 while its.pdfIf the radius of the Earth were to increase by a factor of 4 while its.pdf
If the radius of the Earth were to increase by a factor of 4 while its.pdfGordonF2XPatersonh
 
If the government suddenly decided to include the non-civilian employe.pdf
If the government suddenly decided to include the non-civilian employe.pdfIf the government suddenly decided to include the non-civilian employe.pdf
If the government suddenly decided to include the non-civilian employe.pdfGordonF2XPatersonh
 
If the Earth's P-wave velocities were faster than they actually are- t.pdf
If the Earth's P-wave velocities were faster than they actually are- t.pdfIf the Earth's P-wave velocities were faster than they actually are- t.pdf
If the Earth's P-wave velocities were faster than they actually are- t.pdfGordonF2XPatersonh
 
If the Earth was made-up entirely of crustal rocks- then what would th.pdf
If the Earth was made-up entirely of crustal rocks- then what would th.pdfIf the Earth was made-up entirely of crustal rocks- then what would th.pdf
If the Earth was made-up entirely of crustal rocks- then what would th.pdfGordonF2XPatersonh
 
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdfIf the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdfGordonF2XPatersonh
 

More from GordonF2XPatersonh (20)

import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
import java-lang-Comparable-  -- new Main-String-() public class Main-.pdfimport java-lang-Comparable-  -- new Main-String-() public class Main-.pdf
import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
 
In 2022- Jacques paid the following interest- Interest on home mortgag.pdf
In 2022- Jacques paid the following interest- Interest on home mortgag.pdfIn 2022- Jacques paid the following interest- Interest on home mortgag.pdf
In 2022- Jacques paid the following interest- Interest on home mortgag.pdf
 
In 2020- the world was made aware of the highly contagious and occasio.pdf
In 2020- the world was made aware of the highly contagious and occasio.pdfIn 2020- the world was made aware of the highly contagious and occasio.pdf
In 2020- the world was made aware of the highly contagious and occasio.pdf
 
Implement an extended version of the Caesar cipher that users the char.pdf
Implement an extended version of the Caesar cipher that users the char.pdfImplement an extended version of the Caesar cipher that users the char.pdf
Implement an extended version of the Caesar cipher that users the char.pdf
 
Implement FIFO queue using two stacks in Python- Methods should have O.pdf
Implement FIFO queue using two stacks in Python- Methods should have O.pdfImplement FIFO queue using two stacks in Python- Methods should have O.pdf
Implement FIFO queue using two stacks in Python- Methods should have O.pdf
 
import java-util-ArrayList- public class Bus { private String na.pdf
import java-util-ArrayList-   public class Bus {     private String na.pdfimport java-util-ArrayList-   public class Bus {     private String na.pdf
import java-util-ArrayList- public class Bus { private String na.pdf
 
Imagine a natural area near your hometown that has been identified as.pdf
Imagine a natural area near your hometown that has been identified as.pdfImagine a natural area near your hometown that has been identified as.pdf
Imagine a natural area near your hometown that has been identified as.pdf
 
If you wish to estimate a population mean with a sampling distribution.pdf
If you wish to estimate a population mean with a sampling distribution.pdfIf you wish to estimate a population mean with a sampling distribution.pdf
If you wish to estimate a population mean with a sampling distribution.pdf
 
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdfigate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
 
If you have a dataset with n-42- mean is 50- the standard deviation is.pdf
If you have a dataset with n-42- mean is 50- the standard deviation is.pdfIf you have a dataset with n-42- mean is 50- the standard deviation is.pdf
If you have a dataset with n-42- mean is 50- the standard deviation is.pdf
 
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdfIf you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
 
If X has a binomial random variable with probability distribution f(x).pdf
If X has a binomial random variable with probability distribution f(x).pdfIf X has a binomial random variable with probability distribution f(x).pdf
If X has a binomial random variable with probability distribution f(x).pdf
 
If we look at the diagram below we notice that there are soveral chara.pdf
If we look at the diagram below we notice that there are soveral chara.pdfIf we look at the diagram below we notice that there are soveral chara.pdf
If we look at the diagram below we notice that there are soveral chara.pdf
 
If total assets decrease- then which of the following statements is tr.pdf
If total assets decrease- then which of the following statements is tr.pdfIf total assets decrease- then which of the following statements is tr.pdf
If total assets decrease- then which of the following statements is tr.pdf
 
If two different accountants were to estimate the percentage of custom.pdf
If two different accountants were to estimate the percentage of custom.pdfIf two different accountants were to estimate the percentage of custom.pdf
If two different accountants were to estimate the percentage of custom.pdf
 
If the radius of the Earth were to increase by a factor of 4 while its.pdf
If the radius of the Earth were to increase by a factor of 4 while its.pdfIf the radius of the Earth were to increase by a factor of 4 while its.pdf
If the radius of the Earth were to increase by a factor of 4 while its.pdf
 
If the government suddenly decided to include the non-civilian employe.pdf
If the government suddenly decided to include the non-civilian employe.pdfIf the government suddenly decided to include the non-civilian employe.pdf
If the government suddenly decided to include the non-civilian employe.pdf
 
If the Earth's P-wave velocities were faster than they actually are- t.pdf
If the Earth's P-wave velocities were faster than they actually are- t.pdfIf the Earth's P-wave velocities were faster than they actually are- t.pdf
If the Earth's P-wave velocities were faster than they actually are- t.pdf
 
If the Earth was made-up entirely of crustal rocks- then what would th.pdf
If the Earth was made-up entirely of crustal rocks- then what would th.pdfIf the Earth was made-up entirely of crustal rocks- then what would th.pdf
If the Earth was made-up entirely of crustal rocks- then what would th.pdf
 
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdfIf the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
 

Recently uploaded

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 

Recently uploaded (20)

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 

I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf

  • 1. I want you to add the output of the F1 score, Precision, ROC AUC, and Cohen kappa to fit in the code below, and please consider the code provided. import os import numpy as np import pandas as pd import keras import tensorflow as tf from keras.preprocessing.image import ImageDataGenerator from keras.utils import load_img from keras.utils import to_categorical from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import random from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D, MaxPool2D , Dropout, Flatten, Dense, Activation, BatchNormalization from keras.callbacks import EarlyStopping, ReduceLROnPlateau from sklearn.utils import class_weight import keras,os from keras.models import Sequential from keras.layers import Dense, Conv2D, MaxPool2D , Flatten from keras.preprocessing.image import ImageDataGenerator import numpy as np from keras.optimizers import Adam
  • 2. from keras.callbacks import ModelCheckpoint, EarlyStopping from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, cohen_kappa_score, roc_auc_score print(os.listdir("D:RansomSecondApproachRansomware_Detection_using _CNNMixImages")) # Define Constants FAST_RUN = False IMAGE_WIDTH=256 # 150 accept maybe 256 IMAGE_HEIGHT=256 # maybe 256 IMAGE_SIZE=(IMAGE_WIDTH, IMAGE_HEIGHT) IMAGE_CHANNELS=3 # maybe not need physical_devices = tf.config.experimental.list_physical_devices('GPU') print(physical_devices) if physical_devices: tf.config.experimental.set_memory_growth(physical_devices[0], True) # Prepare Traning Data filenames = os.listdir("D:RansomSecondApproachRansomware_Detection_using _CNNMixImages") categories = [] for filename in filenames: category = filename.split('l')[0] if category == 'image_benign_': categories.append(0) else: categories.append(1)
  • 3. df = pd.DataFrame({ 'filename': filenames, 'category': categories }) print(df.head()) print(df.tail()) # in collab it will work df['category'].value_counts().plot.bar() model = Sequential() model.add(Conv2D(16, (3, 3), activation='relu', input_shape=(IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_CHANNELS))) model.add(BatchNormalization()) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Conv2D(32, (3, 3), activation='relu')) model.add(BatchNormalization()) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(BatchNormalization()) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(512, activation='relu'))
  • 4. model.add(BatchNormalization()) model.add(Dropout(0.5)) model.add(Dense(2, activation='softmax')) # 2 because we have cat and dog classes model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # Callbacks ## Early Stop To prevent over fitting we will stop the learning after 10 epochs and val_loss value not decreased earlystop = EarlyStopping(patience=10) # Learning Rate Reduction learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', patience=2, verbose=1, factor=0.5, min_lr=0.00001) callbacks = [earlystop, learning_rate_reduction] #Prepare data df["category"] = df["category"].replace({0: 'benign', 1: 'malware'}) train_df, validate_df = train_test_split(df, test_size=0.20, random_state=42) train_df = train_df.reset_index(drop=True) validate_df = validate_df.reset_index(drop=True) total_train = train_df.shape[0] total_validate = validate_df.shape[0] batch_size= 15 # defualt 15 # Traning Generator
  • 5. # Defualt train_datagen = ImageDataGenerator( rotation_range=15, rescale=1./255, shear_range=0.1, zoom_range=0.2, horizontal_flip=True, width_shift_range=0.1, height_shift_range=0.1 ) ############################################### # Augmenting the training data train_generator = train_datagen.flow_from_dataframe( train_df, "D:RansomSecondApproachRansomware_Detection_using _CNNMixImages", x_col='filename', y_col='category', target_size=IMAGE_SIZE, class_mode='categorical', batch_size=batch_size ) # Validation Generator validation_datagen = ImageDataGenerator(rescale=1./255)
  • 6. validation_generator = validation_datagen.flow_from_dataframe( validate_df, "D:RansomSecondApproachRansomware_Detection_using _CNNMixImages", x_col='filename', y_col='category', target_size=IMAGE_SIZE, class_mode='categorical', batch_size=batch_size ) # See how our generator work example_df = train_df.sample(n=1).reset_index(drop=True) example_generator = train_datagen.flow_from_dataframe( example_df, "D:RansomSecondApproachRansomware_Detection_using _CNNMixImages", x_col='filename', y_col='category', target_size=IMAGE_SIZE, class_mode='categorical' ) # in collab it will work plt.figure(figsize=(12, 12)) for i in range(0, 15): plt.subplot(5, 3, i+1)
  • 7. for X_batch, Y_batch in example_generator: image = X_batch[0] plt.imshow(image) break plt.tight_layout() plt.show() # compile epochs = 1 # if FAST_RUN else 50 history = model.fit( train_generator, epochs=epochs, validation_data=validation_generator, validation_steps=total_validate//batch_size, steps_per_epoch=total_train//batch_size, # class_weight=class_weights, # add # shuffle=True, callbacks=callbacks ) model.save_weights("model.h5") # Virtualize Training ##in collab # fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12)) # ax1.plot(history.history['loss'], color='b', label="Training loss")
  • 8. # ax1.plot(history.history['val_loss'], color='r', label="validation loss") # ax1.set_xticks(np.arange(1, epochs, 1)) # ax1.set_yticks(np.arange(0, 1, 0.1)) # ax2.plot(history.history['acc'], color='b', label="Training accuracy") # ax2.plot(history.history['val_acc'], color='r',label="Validation accuracy") # ax2.set_xticks(np.arange(1, epochs, 1)) # legend = plt.legend(loc='best', shadow=True) # plt.tight_layout() # plt.show() # Prepare Testing Data test_filenames = os.listdir("D:RansomSecondApproachRansomware_Detection_using _CNNMixImages") test_df = pd.DataFrame({ 'filename': test_filenames }) nb_samples = test_df.shape[0] # Create Testing Generator # output Found 12500 images in kaggle. test_gen = ImageDataGenerator(rescale=1./255) test_generator = test_gen.flow_from_dataframe( test_df, "D:RansomSecondApproachRansomware_Detection_using _CNNMixImages", x_col='filename', y_col=None,
  • 9. class_mode=None, target_size=IMAGE_SIZE, batch_size=batch_size, shuffle=False ) # Predict predict = model.predict_generator(test_generator, steps=np.ceil(nb_samples/batch_size)) test_df['category'] = np.argmax(predict, axis=-1) label_map = dict((v,k) for k,v in train_generator.class_indices.items()) test_df['category'] = test_df['category'].replace(label_map) test_df['category'] = test_df['category'].replace({ 0: 'benign', 1: 'malware' }) # Virtaulize Result # Compute the average training and validation accuracy avg_train_acc = np.mean(history.history['accuracy']) avg_val_acc = np.mean(history.history['val_accuracy']) # Print the average training and validation accuracy print("Average training accuracy:", avg_train_acc) print("Average validation accuracy:", avg_val_acc) #in collab test_df['category'].value_counts().plot.bar() # See predicted result with images # in collab sample_test = test_df.head(18)
  • 10. sample_test.head() plt.figure(figsize=(12, 24)) for index, row in sample_test.iterrows(): filename = row['filename'] category = row['category'] img = load_img("D:RansomSecondApproachRansomware_Detection_using _CNNMixImages" +filename, target_size=IMAGE_SIZE) plt.subplot(6, 3, index+1) plt.imshow(img) plt.xlabel(filename + '(' + "{}".format(category) + ')' ) plt.tight_layout() plt.show() # Submission submission_df = test_df.copy() submission_df['id'] = submission_df['filename'].str.split('.').str[0] submission_df['label'] = submission_df['category'] submission_df.drop(['filename', 'category'], axis=1, inplace=True) submission_df.to_csv('submission.csv', index=False)