Skip to content

Flag card transactions that may be fraud ​

A card issuer pays for every fraudulent transaction it lets through, and its fraud team can only check so many transactions, or call so many cardholders, each day. This guide trains a Fione model that gives each transaction a probability of fraud, so that the team can look at the riskiest first. It goes from the download of an open dataset to a curl call of the served model, and shows how to choose the probability above which a transaction is flagged, from what a missed fraud and a false alarm cost.

Starting Fione from the published images and the general serving steps are in the practical guides overview. This page shows what is particular to this use case.

The business question ​

In the data used here, fewer than 2 in 1,000 transactions are fraud. An issuer that knows which transactions are most at risk can act on it:

  • hold the riskiest transactions, or ask the cardholder to confirm them;
  • have its fraud team review the next riskiest first;
  • let the rest go through, instead of checking everything.

The model answers one question per transaction: is it fraud? It returns a yes/no answer (1 or 0) and, more usefully, the probability of fraud, which is what a review list is sorted by and what a cut-off is set on.

Get the data ​

The data is the Credit Card Fraud Detection dataset, published on Kaggle by the Machine Learning Group of the Université Libre de Bruxelles (ULB), who collected it:

The creators ask that you cite their works; the dataset page lists ten, starting with these two:

  • Andrea Dal Pozzolo, Olivier Caelen, Reid A. Johnson and Gianluca Bontempi. Calibrating Probability with Undersampling for Unbalanced Classification. In Symposium on Computational Intelligence and Data Mining (CIDM), IEEE, 2015
  • Dal Pozzolo, Andrea; Caelen, Olivier; Le Borgne, Yann-Ael; Waterschoot, Serge; Bontempi, Gianluca. Learned lessons in credit card fraud detection from a practitioner perspective, Expert systems with applications,41,10,4915-4928,2014, Pergamon

What we changed: we set the last 50,000 rows aside to try predictions on (see Prepare the CSV); no value was changed.

Kaggle gives the file only to signed-in users, so you need a Kaggle account of your own, and you accept Kaggle's terms of use to download it. We used the Kaggle command-line tool, installed and signed in as its documentation shows; you can also download the data from the dataset page while signed in to Kaggle. With the command-line tool, in an empty directory:

sh
kaggle datasets download mlg-ulb/creditcardfraud
unzip creditcardfraud.zip

The command saves creditcardfraud.zip (69,155,672 bytes). It holds one file, creditcard.csv (150,828,752 bytes, about 150 MB).

creditcard.csv is a comma-separated text file of 284,808 lines (a header and 284,807 rows) with 31 columns and no empty cells. The column names and the values of Class are in double quotes ("0", "1"); Fione reads them without the quotes.

The data ​

According to the dataset page, the rows are transactions made by credit cards in September 2013 by European cardholders, over two days.

ColumnWhat it holds
TimeSeconds elapsed between this transaction and the first transaction in the dataset: 0 to 172792, in file order
V1 … V2828 numbers that are "the result of a PCA transformation" of the original features, which the creators do not publish "due to confidentiality issues"
AmountThe transaction amount (the page does not give the currency)
ClassThe answer: 1 for fraud, 0 otherwise

Class is 1 for 492 of the 284,807 rows (0.17%). Two ordinary transactions, and the first fraud in the file:

csv
"Time","V1","V2","V3","V4","V5","V6","V7","V8","V9","V10","V11","V12","V13","V14","V15","V16","V17","V18","V19","V20","V21","V22","V23","V24","V25","V26","V27","V28","Amount","Class"
0,-1.3598071336738,-0.0727811733098497,2.53634673796914,1.37815522427443,-0.338320769942518,0.462387777762292,0.239598554061257,0.0986979012610507,0.363786969611213,0.0907941719789316,-0.551599533260813,-0.617800855762348,-0.991389847235408,-0.311169353699879,1.46817697209427,-0.470400525259478,0.207971241929242,0.0257905801985591,0.403992960255733,0.251412098239705,-0.018306777944153,0.277837575558899,-0.110473910188767,0.0669280749146731,0.128539358273528,-0.189114843888824,0.133558376740387,-0.0210530534538215,149.62,"0"
0,1.19185711131486,0.26615071205963,0.16648011335321,0.448154078460911,0.0600176492822243,-0.0823608088155687,-0.0788029833323113,0.0851016549148104,-0.255425128109186,-0.166974414004614,1.61272666105479,1.06523531137287,0.48909501589608,-0.143772296441519,0.635558093258208,0.463917041022171,-0.114804663102346,-0.183361270123994,-0.145783041325259,-0.0690831352230203,-0.225775248033138,-0.638671952771851,0.101288021253234,-0.339846475529127,0.167170404418143,0.125894532368176,-0.00898309914322813,0.0147241691924927,2.69,"0"
406,-2.3122265423263,1.95199201064158,-1.60985073229769,3.9979055875468,-0.522187864667764,-1.42654531920595,-2.53738730624579,1.39165724829804,-2.77008927719433,-2.77227214465915,3.20203320709635,-2.89990738849473,-0.595221881324605,-4.28925378244217,0.389724120274487,-1.14074717980657,-2.83005567450437,-0.0168224681808257,0.416955705037907,0.126910559061474,0.517232370861764,-0.0350493686052974,-0.465211076182388,0.320198198514526,0.0445191674731724,0.177839798284401,0.261145002567677,-0.143275874698919,0,"1"

The third row is a fraud with an Amount of 0. Many of the frauds are small: half of them have an Amount of 9.29 or less, against 22 or less for half of all transactions.

Before training, look at four things.

First, the anonymised columns. V1 to V28 are not the original features: the creators transformed them and kept the originals confidential. The page does not say when the original features are known; we read them as features of the transaction itself, known when it comes in, and so keep all 28. So the model can learn from them, but when Fione tells you which inputs mattered most, a name such as V14 does not say anything about the business, and you cannot compute these columns for transactions of your own. To use this approach on your own cards, train on your own transaction features; this dataset shows the method.

Second, Time. Whether to keep a column depends on two things: is the value known at the moment you predict, and is it computed from the outcome you are predicting? Time passes both: it is known when the transaction happens and is not computed from whether it was fraud. But it counts seconds from the first transaction of this two-day file, so a transaction from any later day would have a value the model has never seen, and what the model learned about it, such as "rows near second 150,000", may not carry over. Fione keeps it checked; we uncheck it.

Third, the amount. The page says Amount can be used for cost-sensitive learning, where each missed fraud costs its own amount. Fione does not do that: the cost setting shown below uses one cost for every missed fraud and one for every false alarm. The page does not give the currency.

Fourth, repeated rows. 1,081 rows repeat an earlier row in every column, 19 of them among the frauds. The page does not mention them; two transactions are unlikely to match in all 30 numbers by chance, so we read them as the same transaction recorded more than once. We leave them in. When Fione checks the models on rows set aside in turn, a copy of a fraud can be among the rows a model learns from while its twin is among the rows it is checked on, so the figures in Read the results may be a little higher than on new transactions. None of the transactions set aside below has a copy among the training rows.

Prepare the CSV ​

creditcard.csv needs no conversion. Check it has 284,808 lines:

sh
wc -l creditcard.csv

Then keep some transactions apart, so that you can later predict rows the model never learned from. Frauds are so rare that a small part of the file may hold none (the last 1,000 rows of the file hold none), so keep many: the header and the last 50,000 rows in new-transactions.csv, and train on the other 234,807 rows in train.csv:

sh
head -n 234808 creditcard.csv > train.csv
{ head -n 1 creditcard.csv; tail -n 50000 creditcard.csv; } > new-transactions.csv

The rows are in Time order, so the 50,000 transactions set aside are the last ones of the second day (Time 148,125 to 172,792, about the last 7 hours), later than every transaction the model learns from. 65 of them (0.13%) are frauds; train.csv holds the other 427 (0.18%). That is close to how a model is used: trained on past transactions, used on the next ones.

Keep Time and Class in both files: you will uncheck Time in Fione, and the predictions page shows that the model does not use them.

Train the model ​

  1. On Projects, create a project (we named it fraud-detection) and open it.
  2. Press Upload training data, choose train.csv (about 124 MB) and press Upload and analyze. Data analysis shows 234,807 rows, 31 columns and 0% empty cells.
  3. Under What do you want to predict?, choose Class. Fione sees two values in it and suggests Classification. It also says: "The data has 234,807 rows and 31 columns, so the maximum run time is set to 30 minutes to leave time to try enough models. Shorten it below if you need an answer sooner."
  4. Under Which columns should the model learn from?, all 30 inputs are checked, all read as Number. Uncheck Time.
  5. Keep Classification under Prediction type.
  6. Keep 30 min under Maximum run time.
  7. Press Run.

Data analysis for train.csv, with Class to predict, Time unchecked, Classification and 30 min

When training ends, the page moves on to the Prediction summary. Fione loads the whole file into memory (see Known limitations). In our run, on a 16-core Mac, docker stats showed the Fione container at about 1.2 GiB just before the run, and its highest reading while training was about 4.1 GiB; the upload and analysis took a few seconds. For a file of this size, give Docker memory well above that.

Read the results ​

The Prediction summary of our run: 4 out of 5, 82% of the frauds found and 97% of the transactions called a fraud really were, with V14 and V4 at the top of the most useful inputs

In our run:

  • Rating: 4 out of 5. "On rows it did not learn from, the model found 82% of the “1” rows (only about 0.2% of all rows), and 97% of the rows it called “1” really were. Always guessing the most common answer would find none of them."
  • Guide: "Great job! The model predicts well. Try it on new data."
  • About this model: a blend of 6 models, 71 models tried, training time 21:45.
  • Most useful inputs: V14 23%, V4 15%, V10 12%, V12 9%, V16 6%.

With fraud this rare, the share of right answers says almost nothing: a "model" that always says 0 is right for 99.82% of the training rows and finds no fraud. So the sentence under the rating speaks of what matters here, the frauds found (82%) and how often a transaction called a fraud really was one (97%). The stars are still worked out from the share of right answers (How is the rating calculated? on the summary gives the formula and the bands): unrounded, the model's Accuracy is 0.99961, and it covers (0.99961 − 0.99818) / (1 − 0.99818) ≈ 0.78 of the distance from always guessing 0 to a perfect score, in the band of 4 stars (0.6 to 0.8).

Press Open advanced details and open the Metrics tab. It shows the figures measured on rows the models did not learn from. In our run:

  • Precision 0.961 and Recall 0.817: of the 427 frauds in train.csv, the model said 1 for 349 and missed 78; it said 1 for 363 transactions, so 14 were false alarms among more than 234,000 ordinary ones.
  • Confusion matrix: the tab draws it from a random sample of 200,000 of the training rows, as it says. There, of 366 frauds the model said 1 for 300 (82%) and missed 66; of 199,634 ordinary transactions it said 1 for 10. The rating's 82% and 97% agree with this sample (300 of the 310 transactions it called a fraud were one); over all the training rows, Precision is 0.961.
  • AUC 0.98 (0.5 is guessing, 1 is perfect): take one fraud and one ordinary transaction, and the model gives the fraud the higher probability about 98% of the time.
  • Average precision 0.88: "How well the true cases are ranked first; it suits rare cases. Higher is better." On the Overview tab, the Ranking metric is Average precision (classification): Fione picked it to compare the models it tried, as the answer is rare. The creators also recommend measuring with the area under the precision-recall curve here, not with accuracy.

These figures come from rows of the same data, set aside in turn while the models learn; because no time order is set, Fione shuffles the rows before setting them aside. The transactions you set aside in new-transactions.csv are a check of another kind: they are later than every training row. Make predictions shows how the model does on them.

Most useful inputs is captioned "The columns that moved the predictions most, as a share of all the columns' effect." Fione works this out on its own shortly after training (about 8 seconds after it in our run), by explaining the model's predictions on rows of the training data. As said in The data, V14, V4 and the others are anonymised, so this list tells you which of the 28 numbers the model leans on, not which business factor signals fraud. Until that explanation is done, the summary shows a different list instead, captioned "The columns the model relied on most, as a share of all it used." and based on the training's own measure; that list stays on the Importance tab (in our run V14 12%, V4 9%, V10 7%, V8 6%, V1 5%, Amount 5%, and smaller shares for the rest).

The 1/0 answer is the more likely of the two (the model's Choosing the predicted class setting is Most likely class), so the model says 1 only when it rates fraud more likely than not. That cut-off ignores what the two kinds of error cost. For an issuer, a missed fraud is usually far more expensive than a false alarm, which costs a review or a call to the cardholder. Fione can choose the cut-off from these costs, with Lowest cost (two classes, with the cost of a miss and of a false alarm). It is not on the training form: Choosing the predicted class on Training settings (Advanced settings: every training parameter on Data analysis) offers Most likely class, Adjust for class sizes and Fit to the ranking metric (two classes, or up to 50 with QWK). Set it from an AI tool through MCP, the Python client or the REST API, as Choosing the predicted class describes. Training settings also shows a tip for this data, "The rarest class is only 0.2% of the rows. If your score treats every class alike (such as balanced accuracy or macro F1), set "Choosing the predicted class" to Adjust for class sizes."; that is for a score that treats both classes alike, not for costs, so we did not follow it.

As an example, we said that a missed fraud costs 100 and a false alarm 5 (in one unit of your choice; only their ratio matters), and trained another model on the same train.csv, with the same inputs and run time, over MCP (see From an AI tool). Fione chose the cut-off on the rows set aside in turn, and its training job's page (Training job on the Overview tab) says so in a notice:

decision 'cost': the class '1' is predicted above a probability of 0.0328; on the validation rows a miss (a row of '1' given the other class) costs 100 and a false alarm 5, which comes to 0.02589 per row (the most probable class: 0.03482); the threshold is chosen on the same rows, so it is somewhat optimistic

So this model says 1 above a fraud probability of about 3%, not 50%, and on the rows it did not learn from its errors cost 0.0259 per transaction, against 0.0348 with the most likely class: about a quarter less, for the same model. (As the notice ends, the cut-off was chosen on the same rows, so that figure is somewhat optimistic.) It found more frauds and raised more false alarms: of the 427 frauds it found 374 (Recall 0.876), and 71% of the transactions it called 1 were frauds (Precision 0.706). The rating fell to 3 out of 5 ("Not bad! The model is useful. More data or a longer run may make it better still."), because the stars count right answers and each false alarm is one more wrong answer; by the costs you gave, the trade is worth it. The cut-off does not change the probabilities, so a review list sorted by this model's probability is the same with either cut-off.

Make predictions ​

Predict the 50,000 transactions you set aside:

  1. On the Prediction summary, press Make predictions.
  2. Choose new-transactions.csv and press Upload. Fione says that "new-transactions" (50,000 rows) has every column the model needs, and marks Time and Class as Not used by the model. Keep Class checked under Columns in the result, so that you can compare each prediction with what happened.
  3. Press Predict. Predictions shows 50,000 rows × 34 columns and Download predict_new-transactions.csv.

predict is the answer, and p_1 the probability of fraud. In our run, the model trained above said 1 for 48 of the 50,000 transactions: 46 were frauds and 2 were not. It missed 19 of the 65 frauds, so it found 71% of them on these later transactions, fewer than the 82% measured on the training rows. Sorted by p_1, the 54 transactions it rated most at risk hold 50 of the 65 frauds; the other 15 come further down, from the 110th place to the 11,238th.

We also predicted the same file with the lowest-cost model of Read the results. Six of the 50,000 rows, by their place in the file (row 1 is the first transaction after the training rows), with both models:

RowAmountp_1, model abovepredictp_1, lowest-cost modelpredictClass (what happened)
8100.760.9910.9911
262010.6610.4011
3996525691.160.6910.8810
12867247.860.3400.6611
541610.1700.3411
11950.0000.0000

Row 39965 is the largest amount in the whole file, and both models flagged it although it was not a fraud. The lowest-cost model says 1 for rows 2620 and 5416 with a p_1 well under 0.5, because its cut-off is about 0.03: every one of its 1 answers in this file has a p_1 above 0.0328, and every 0 below. Over the 50,000 transactions it said 1 for 96: 51 frauds and 45 false alarms, and it missed 14 frauds. With the example costs, that comes to 14 × 100 + 45 × 5 = 1,625. Had the same model used the most likely class, it would have said 1 for 47 (45 frauds, 2 false alarms) and missed 20, for 20 × 100 + 2 × 5 = 2,010. So on transactions later than any it learned from, the cut-off chosen by cost lowered the cost by about a fifth (the notice gave about a quarter for the training rows).

Under the table, Why these predictions shows, for the first 5 rows, the columns that moved each prediction most. These 5 transactions are not frauds, and with fraud this rare, the average prediction they start from rounds to 0.0% and every effect to 0.0, so this part says little here.

Serve it as an API ​

Under Serve it from your own system, press Download the serving bundle. Unpack it into a directory of its own and run the command shown on the card there, as in the overview. Use the name of your file; for our model:

sh
unzip fione-serving-Class-model-2026-11-28-09-25-19.zip -d fione-serving-Class-model-2026-11-28-09-25-19
cd fione-serving-Class-model-2026-11-28-09-25-19
docker run --rm -p 8081:8080 -v "$PWD/model:/model:ro" ghcr.io/codelibs/fione-serving:snapshot

In another terminal, ask which columns the model expects:

sh
curl -s localhost:8081/model
json
{"names":["V1","V2","V3", ... ,"V28","Amount","Class"],
 "domains":[null,null,null, ... ,null,null,[0,1]],
 "responseColumn":"Class","category":"Binomial","nclasses":2,"nfeatures":29, ...}

The model takes V1 to V28 and Amount; Time is not among them. A row has 29 values, too many to type, so in the directory where new-transactions.csv is, let python3 copy rows 810 and 1, a fraud and an ordinary transaction, into a request, and send it:

sh
python3 -c '
import csv, json
rows = list(csv.DictReader(open("new-transactions.csv")))
keep = [{k: float(v) for k, v in rows[i - 1].items() if k not in ("Time", "Class")} for i in (810, 1)]
json.dump({"instances": keep}, open("rows.json", "w"))
'
curl -s -X POST localhost:8081/invocations -H 'Content-Type: application/json' -d @rows.json
json
{"predictions":[{"label":1,"index":1,"class_probabilities":[0.009686663947501206,0.9903133360524988]},{"label":0,"index":0,"class_probabilities":[0.9999531928503944,4.680714960570136e-05]}]}

class_probabilities follow the classes of Class in domains, 0 then 1, so the second number is the probability of fraud: 0.99 and 0.00005, the same as p_1 for these rows under Make predictions. An issuer's system would send each transaction's values as it comes in, keep its own transaction number next to the answer, and hold or review the transactions above the probability it chooses.

In our run, sending the numbers as strings such as "0.76", or adding Time and Class to a row, gave the same probabilities; leaving out Amount gave an error for that row ("missing columns"). The bundle of the lowest-cost model applies its own cut-off: for row 14165, a fraud, it answered label 1 with a probability of 0.27.

From an AI tool ​

AI tools such as Claude and Codex can do the same through Fione's MCP endpoint: upload the CSV, train, read the results and predict. train.csv is larger than the 512 KiB that the upload_dataset tool takes, so the tool sends it with create_upload_url, which returns a curl command for the file. Ask the tool to leave Time out of the inputs, as above.

This is also the way to the lowest cost without code. Tell the tool what a missed fraud and a false alarm cost; propose_training_config takes them as decision cost, cost_miss and cost_false_alarm. For the model of Read the results we called it directly over MCP with cost_miss 100, cost_false_alarm 5 and a run time of 1,800 seconds. Its proposal did not leave Time out, so we added it to ignored_columns before passing the configuration to start_training. The proposal also warned which way round the costs are: "decision 'cost': a miss is a row of the class '1' (the one listed last) given the other class, and costs 100; a false alarm is a row of the other class given '1', and costs 5". Check that against your own costs before training.

For a few transactions, the predict tool takes rows like the two above and returns predict, p_0 and p_1 for each. Called directly over MCP for the model trained on the form, it returned the same probabilities as the API above. How to connect a client and what to ask is in Run the AutoML loop from an AI tool with MCP, the proposal in Proposals, and the predict tool in Predicting new rows.