HI,
WE have trained a dataset for credit fraud detection and we want to predict single record whether it belongs to class 1 or 0
FYI: 1 means fraud and 0 means normal
The below code is inspired from the below link
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It's Sunday morning, it's quiet and you wake up with a big smile on your face. Today is going to be a great day! Except, your phone rings, rather \"internationally\". You pick it up slowly and hear something really bizarre - \"Bonjour, je suis Michele. Oops, sorry. I am Michele, your personal bank agent.\". What could possibly be so urgent for someone from Switzerland to call you at this hour? \"Did you authorize a transaction for $3,358.65 for 100 copies of Diablo 3?\" Immediately, you start thinking of ways to explain why you did that to your loved one. \"No, I didn't !?\". Michele's answer is quick and to the point - \"Thank you, we're on it\". Whew, that was close! But how did Michele knew that this transaction was suspicious? After all, you did order 10 new smartphones from that same bank account, last week - Michele didn't call then.\n",
"\n",
"![](https://cdn.tutsplus.com/net/uploads/legacy/2061_stripe/1.png)\n",
"\n",
"Annual global fraud losses reached $21.8 billion in 2015, according to [Nilson Report](https://www.nilsonreport.com/upload/content_promo/The_Nilson_Report_10-17-2016.pdf). \n",
"\n",
"Probably you feel very lucky if you are a fraud. About every 12 cents per $100 were stolen in the US during the same year. Our friend Michele might have a serious problem to solve here.\n",
"\n",
"In this part of the series, we will train an Autoencoder Neural Network (implemented in Keras) in unsupervised (or semi-supervised) fashion for Anomaly Detection in credit card transaction data. The trained model will be evaluated on pre-labeled and anonymized dataset.\n",
"\n",
"# Setup\n",
"\n",
"We will be using TensorFlow 1.2 and Keras 2.0.4. Let's begin:"
]
This file has been truncated. show original
x=[402,-0.160626023844866,-0.0644592715749079,2.53107242920104,-1.32826789668652,-0.970429962152532,0.185030499749121,-0.380184273955408,0.078119056922537,1.77595623371714,-1.24231480332541,-0.364953829901919,0.435456870671237,0.0395015202936356,-0.760588288546284,1.70160412646751,-1.23341666950173,0.497776404087423,0.194699717703905,1.43068504978307,0.130322208087451,0.262123747446068,1.34069624745507,-0.25386003202542,0.178600525071912,-0.491121059669452,0.24497199815904,0.0748290902309209,-0.0699236364318091]
autoencoder = load_model(‘model.h5’)
b=np.reshape(x,(1,29))
predictions = autoencoder.predict(b,verbose=0)
From the output “predictions” we r not able to get the class. pls suggest
Thanks
vijay
It looks like you are using Keras or did you implement the same model in PyTorch?
If so, could you post the model architecture or the shape of your last linear layer?
I assume you’ve used a single output with nn.BCELoss/nn.BCEWithLogitsLoss
or two output units with nn.CrossEntropyLoss/nn.NLLLoss
.
In the first case, you can just apply a threshold (e.g. 0.5) or fine tune it using the ROC, which you would apply torch.argmax(output, 1)
in the latter case to get the prediction.