## Neural Network – Where it didn’t produce any output

I wanted to analyze my expenses so I found statistical analysis on my expense report will definitely going to help there.
So I buckled up and downloaded the previous 4 years statement of my bank, and the following kind of data I found –

Great so now I am ready and thought lets first draw some graphs from the above dataset.

First thing I found is month wise expenses and I got –

s           Great, I just found that I am doing transaction almost every month and as the amount increases, density of the data is getting decreases, naturally as I don’t have that much money to do the transaction.
Now you might find some lower Green colored data, well that is a trouble that shows my debit, so almost whatever the amount credits , I just debit , so you can assume my great bank balance.

So now I thought of shuffling through the same data in yearly pattern-

Almost similar result.

Now the point comes , on which data and what kind of classification output I am expecting to run Neural Network.

First I thought based on my amount input , lets classify it will be Debit(1) or Credit(0). Uhhh ,.. some illogical point but I just wanted to see what happens-

I ran the neural network and this is the result I got-
output <- neuralnet(Transaction ~ Amount,data,hidden = 10,threshold = 0.01,linear.output=FALSE, likelihood=TRUE)

Yeah Yeah .. Error is too high , well but the formula is pretty straightforward.
Then I realize, my formula doesn’t make any sense at all. As my Debit and Credit both are in sync and even manually I can’t justify the logic that a certain amount is Debit or Credit.

And the solution I found by adding new features

Add new features in Neural and Test

SOURCE CODE

`````` library("neuralnet")
# create a class
setClass("myDate")
setAs("character", "CrDr", function(from) c(Cr.=1,Dr.=0)[from])
setAs("character","myDate", function(from) as.Date(from, format="%d/%m/%Y") )
#Replace the comma from Amount
data\$Amount <- as.numeric(gsub(",", "", gsub("", "", data\$Amount)))
#Change Dr.(1) and Cr.(0)
data\$Transaction <- as.numeric(data\$Transaction=="Dr.")
data\$Transaction.Date <- as.Date(data\$Transaction.Date, format="%d/%m/%Y")
month = as.numeric(format(data\$Transaction.Date, format = "%m"))
year = as.numeric(format(data\$Transaction.Date, format = "%Y"))
plot(data\$Amount, year, main="Amount vs Year",
xlab="Amount", ylab="Year", pch=10, col="blue")
axis(2, at=x,labels=x, col.axis="red", las=2)
plot(data\$Amount, month, main="Amount vs Month & Dr.",
xlab="Amount", ylab="Month", pch=1, col="red")
points(data\$Amount, data\$Transaction==1, pch=5,col = "green", cex = 1.0)
plot(data\$Transaction, data\$Amount, main="Transaction vs Amount",
xlab="Transaction", ylab="Amount", pch=1, col="red")
#Month wise Credit & Debit
#To convert Dr. Cr. of Transaction Type to 1 for Dr. and 0 for Cr.
output <- neuralnet(Transaction ~ Amount,data,hidden = 4,threshold = 0.01,linear.output=FALSE, likelihood=TRUE)
print(output\$result)
plot(output,rep = "best")
testdata <- c(1000,2000,12000,45001,19123,36000)
#test_sample <- subset(testdata,select = c("day","month","year"))
result <- compute(output,testdata);
print(round(result\$net.result))
``````