-
Notifications
You must be signed in to change notification settings - Fork 3
/
DataPrep.R
35 lines (32 loc) · 1.54 KB
/
DataPrep.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
sampleData<- function(attackDat, label, numOfRows){
sampleDat<- cbind(attackDat[sample(1:nrow(attackDat),numOfRows),],label)
colnames(sampleDat)<- c(colnames(sampleDat)[-ncol(sampleDat)],'AttackType')
return(sampleDat)
}
getAttackSet<-function(pathToFolder,attackNames,attackColVals, sampleSize ){
attackVector<-NULL
for(i in 1:length(attackNames)){
path<- paste(pathToFolder,"Optimized_",attackNames[i],".csv",sep = "")
temp<- read.csv(path,header = T)
temp<- sampleData(temp,attackColVals[i],sampleSize)
attackVector<- rbind(attackVector,temp)
}
return(attackVector)
}
attackNames<- scan('DataAttackNames.txt', what = '',sep='\n')
folderPath<- "/home/appurvj/Dropbox/Coursework/RTest/"
attackSampleSize<- 200
normalSampleSize<-2000
misuseAttackSamples<-getAttackSet(folderPath,attackNames,attackNames, attackSampleSize)
anomalyAttackSamples<-getAttackSet(folderPath,attackNames, rep("Attack",length(attackNames)),attackSampleSize)
normalData<- read.csv(paste(folderPath, "Optimized_Normal.csv",sep=""), header = T)
misuseMaster<- sampleData(normalData, "Normal", normalSampleSize)
anomalyMaster<- sampleData(normalData, "Normal", normalSampleSize)
misuseMaster<- rbind(misuseMaster, misuseAttackSamples)
anomalyMaster<- rbind(anomalyMaster, anomalyAttackSamples)
print(dim(misuseMaster))
print(dim(anomalyMaster))
row.names(misuseMaster)<-NULL
row.names(anomalyMaster)<-NULL
write.csv(misuseMaster, paste(folderPath,"MisuseMasterDataSet.csv",sep=""), row.names = F)
write.csv(anomalyMaster, paste(folderPath,"AnomalyMasterDataSet.csv",sep=""),row.names = F)