Real-time Fraud detection web application

Alireza Moosavi
3 min readSep 9, 2020

In the first part the machine learning part is going to be described. This fraud detection project notebook could be found here.

This fraud detection process has been implemented with two algorithm, with Random Forest and CNN and accuracy of 99% on test data.

Because of more simplicity of random forest model; in this project this model is employed to check if sent data is fraud or not!

Cassandra

The database for this real-time web application is Cassandra. This is the class for creating connection and key-space:

The data model for result data is like this:

WEB

This part of project has been built with Fastapi, this project has two endpoint to be called for checking data for fraud.

RESTfull api

This method is just simple posting data and getting back the results:

Post data method

The input data:

-0.54839782, -0.35184723, 0.17023924, -3.10939288, 0.909047 ,
3.53073928, -1.49890445, 1.37163425, -2.58719536, 0.75480169,
-0.59832237, -1.24748237, 0.56082062, -0.1370649 , 0.78843122,
0.1627786 , 0.08075539, 0.97238009, 0.14502653, -0.2140704 ,
0.01214456, 0.11382656, -0.18937492, 0.99338122, 0.13761257,
-0.10732711, 0.00999518, 0.03007495, 7.5

As it can be seen post method route has done its job right!

Web-socket

This feature is very awesome, it will classify the data in real-time and turn back the results with calling button. But to support web socket in Nginx we need to make serveral changes:

The config file is here.

Websocket route
UI for websocket

The input data:

-0.54839782, -0.35184723, 0.17023924, -3.10939288, 0.909047 ,
3.53073928, -1.49890445, 1.37163425, -2.58719536, 0.75480169,
-0.59832237, -1.24748237, 0.56082062, -0.1370649 , 0.78843122,
0.1627786 , 0.08075539, 0.97238009, 0.14502653, -0.2140704 ,
0.01214456, 0.11382656, -0.18937492, 0.99338122, 0.13761257,
-0.10732711, 0.00999518, 0.03007495, 7.5

localhost:8000/wspred

As it can be seen the length of data must be 29.

Checking Cassandra

By calling the root API the number of data is going to e shown that has been saved into Cassandra:

Checking if cassandra is working or not

Yeah there is 2 item that we tested!

--

--