Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ VOLUME /var/lib/mysql
COPY example/datasets/popularize_churn.sql \
example/datasets/popularize_iris.sql \
example/datasets/popularize_boston.sql \
example/datasets/popularize_creditcardfraud.sql \
example/datasets/create_model_db.sql \
/docker-entrypoint-initdb.d/

Expand Down
46 changes: 46 additions & 0 deletions doc/examples/tutorial_creditcardfraud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# The Credit Card Fraud Detection Example

The sample data already loaded in MySQL comes from [Kaggle](https://www.kaggle.com/mlg-ulb/creditcardfraud). To train the model using the full dataset, you need to download the dataset and load the dataset into MySQL manually.

You can verify the sample data content in MySQL using:

```sql
%%sqlflow
SELECT * from creditcard.creditcard limit 5;
```

## Train a DNN Model Using SQLFlow

Once your dataset is prepared, you can run the below SQL statement to start training.
Note that SQLFlow will automatically split the dataset into training and validation
sets, the output of evaluation result is calculated using the validation set.

```sql
%%sqlflow
SELECT * from creditcard.creditcard
TRAIN DNNClassifier
WITH model.n_classes=2, model.hidden_units=[128,32], train.epoch=100
COLUMN 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
LABEL class
INTO creditcard.creditcard_deep_model;
```

## Run Predict

We can use the trained model to predict new data, e.g. we can choose some positive sample in the dataset
to do predict:

```sql
%%sqlflow
SELECT * from creditcard.creditcard
WHERE class=1
PREDICT creditcard.predict.class
USING creditcard.creditcard_deep_model;
```

Then we can get the predict result using:

```sql
%%sqlflow
SELECT * from creditcard.predict;
```
Loading