Question: whats wrong with this code? import numpy as np def main ( filename , filter _ value,type _ of _ card ) :
whats wrong with this code?
import numpy as np
def mainfilenamefiltervalue,typeofcard:
read dataset and stores transaction records"""
datareadcsvfilename
#ALANA MAKE SURE U READ THIS LATER
filtereddatafilterdatadatafiltervalue,typeofcard
displayresultsfiltereddata
def readcsvfilename:
data
with openfilenamer as file:
readercsvreaderfile
nextreader
for row in reader:
data.appendrow
return data
def filterdatadatafiltervalue,typeofcard:
filtereddata
for row in data:
if filtervalue in row and typeofcard in row:
filtereddata.appendrow
return filtereddata
def displayresultsfiltereddata:
for row in filtereddata:
printrow
def taskdatafiltervalue,typeofcard:
data contains records
filtervalue is an area name
typeofcard is name of card provider
return list containing values to decimal"""
answer
#finding cosine difference between normal & malicious transactions
#based on IPvalidityscore
normaltransactiondatadataTransactiontype"'normal'IPvalidityscore"
maltransactiondatadataTransactiontype"'malicious'IPvalidityscore"
#treat transactions as vectors
normalvectornpmeannormaltransaction
malvectornpmeanmaltransaction
dotproductnpdotnormalvectormalvector
#find norm of 'normal' transaction and 'malicious' transaction vectors
normnormalnplinalg.normnormalvector
normmalnplinalg.normmalvector
#plug into formula for cosine similarity
cosinesimildotproductnormnormalnormmal
#find cosine distance
cosdistcosinesimil
answer.appendroundcosdist,
#find variance for specific area
areafiltereddatadatadataActualarea'filtervalue
transactionamountsareafiltereddataTransactionamount'
variancenpvartransactionamounts,ddof
answer.appendroundvariance
#find median of authentication score for lower th and upper th percentile
#based on type of card
filteredcarddatadatadataTypeofcard'typeofcard
authenticationscoresfilteredcarddataAuthenticationscore'
lowpercentilenppercentileauthenticationscoresinterpolation'lower'
highpercentilenppercentileauthenticationscoresinterpolation'higher'
lowmediannpmedianauthenticationscoresauthenticationscoreslowpercentile
highmediannpmedianauthenticationscoresauthenticationscoreshighpercentile
answer.appendroundlowmedianroundhighmedian
#filter mal transactions where 'actual' and 'origin' are different
#find elementwie product between authentication score and ip validation score
#perform correlation between resultant vector and amount column
malsusspotsdatadataTransactionType''Malicious'&dataActualdataOrigin
authscoresmalsusspotsAuthenticationscore'
ipscoresmalsusspotsIPvalidityscore'
dotproductnpdotauthscoresipscores
correlationnpcorrcoefdotproduct, malsusspotsTransactionamount'
answer.appendroundcorrelation
#create Nx matrix where N is number of rows in data set
#find principal component analysis PCA to reduce dimensionality to Nx
transactiontypemapATM:'EFTPOS':'Internet':
entrymodemapMagnetic Stripe':'Manual':'Chip Card Read':NFC:
datacopyTransactionType'datacopyTransactionType'maptransactiontypemap
datacopyEntrymode'datacopyEntrymode'mapentrymodemap
featurematrixdatacopyTransactionType','Entrymode','Transactionamount','Authenticationscore',IPvalidityscore'values
pcaPCAncomponents
pcaresultpca.fittransformfeaturematrix
answer.appendlistnproundpcaresultflatten
printfCosine Distance: cosdist
printfVariance: var
printfMedian: median
printfCorrelation: corr
printfPCA: pca
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
