SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
I have tried running this code below, and it is working, but the accuracy is less than expected.
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)
First, please add the output of the F1 score, Precision, ROC AUC, and Cohen kappa to the
code.
Second, please add or modify the code for a higher result.
I need coding only.
Thank you in advance.
I have tried running this code below- and it is working- but the accur.pdf

Contenu connexe

Similaire à I have tried running this code below- and it is working- but the accur.pdf

29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptxKASHYAPPATHAK7
 
Need helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfNeed helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfactexerode
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnnDebarko De
 
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
 
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
 
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
 
CE344L-200365-Lab6.pdf
CE344L-200365-Lab6.pdfCE344L-200365-Lab6.pdf
CE344L-200365-Lab6.pdfUmarMustafa13
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfssuserb4d806
 
Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01longtuan
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)TarunPaparaju
 
Machine Learning - Introduction
Machine Learning - IntroductionMachine Learning - Introduction
Machine Learning - IntroductionEmpatika
 
GANS Project for Image idetification.pdf
GANS Project for Image idetification.pdfGANS Project for Image idetification.pdf
GANS Project for Image idetification.pdfVivekanandaGN1
 
Learning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleLearning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleYvonne K. Matos
 
Tutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GANTutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GANWuhyun Rico Shin
 
Deep learning approach for intelligent intrusion detection system
Deep learning approach for intelligent intrusion detection systemDeep learning approach for intelligent intrusion detection system
Deep learning approach for intelligent intrusion detection systemVenkat Projects
 
Unsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleUnsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleAaron (Ari) Bornstein
 
Training course lect2
Training course lect2Training course lect2
Training course lect2Noor Dhiya
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
Jeroen Vloothuis Bend Kss To Your Will
Jeroen Vloothuis   Bend Kss To Your WillJeroen Vloothuis   Bend Kss To Your Will
Jeroen Vloothuis Bend Kss To Your WillVincenzo Barone
 

Similaire à I have tried running this code below- and it is working- but the accur.pdf (20)

29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx
 
Need helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfNeed helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdf
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnn
 
Viktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceViktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning Service
 
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
 
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
 
CE344L-200365-Lab6.pdf
CE344L-200365-Lab6.pdfCE344L-200365-Lab6.pdf
CE344L-200365-Lab6.pdf
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
 
Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
 
Machine Learning - Introduction
Machine Learning - IntroductionMachine Learning - Introduction
Machine Learning - Introduction
 
GANS Project for Image idetification.pdf
GANS Project for Image idetification.pdfGANS Project for Image idetification.pdf
GANS Project for Image idetification.pdf
 
Learning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleLearning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and Kaggle
 
Tutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GANTutorial: Image Generation and Image-to-Image Translation using GAN
Tutorial: Image Generation and Image-to-Image Translation using GAN
 
Deep learning approach for intelligent intrusion detection system
Deep learning approach for intelligent intrusion detection systemDeep learning approach for intelligent intrusion detection system
Deep learning approach for intelligent intrusion detection system
 
C3 w2
C3 w2C3 w2
C3 w2
 
Unsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleUnsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at Scale
 
Training course lect2
Training course lect2Training course lect2
Training course lect2
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Jeroen Vloothuis Bend Kss To Your Will
Jeroen Vloothuis   Bend Kss To Your WillJeroen Vloothuis   Bend Kss To Your Will
Jeroen Vloothuis Bend Kss To Your Will
 

Plus de 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
 

Plus de 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
 

Dernier

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Dernier (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

I have tried running this code below- and it is working- but the accur.pdf

  • 1. I have tried running this code below, and it is working, but the accuracy is less than expected. 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
  • 2. 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({
  • 3. '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())
  • 4. 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
  • 5. 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(
  • 6. 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:
  • 7. 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")
  • 8. # 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,
  • 9. 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()
  • 10. 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) First, please add the output of the F1 score, Precision, ROC AUC, and Cohen kappa to the code. Second, please add or modify the code for a higher result. I need coding only. Thank you in advance.