<jupyter_start><jupyter_text>Credit Card Fraudulent DetectionDetect credit card fraudulent with deep neural network using a dataset from https://www.kaggle.com/dalpozz/creditcardfraud<jupyter_code>import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout<jupyter_output>Using TensorFlow backend.<jupyter_text>Read data from csv<jupyter_code>df = pd.read_csv('./data/creditcard.csv')
df.head(1)
df['Class'].unique() # 0 = no fraud, 1 = fraudulent
X = df.iloc[:, :-1].values
y = df.iloc[:, -1].values<jupyter_output><empty_output><jupyter_text>Split the dataset into train and test datasets<jupyter_code>X_train, X_test, Y_train, Y_test = train_test_split(X, y, test_size=0.1, random_state=1)
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)<jupyter_output><empty_output><jupyter_text>Model deep neural network<jupyter_code>clf = Sequential([
    Dense(units=16, kernel_initializer='uniform', input_dim=30, activation='relu'),
    Dense(units=18, kernel_initializer='uniform', activation='relu'),
    Dropout(0.25),
    Dense(20, kernel_initializer='uniform', activation='relu'),
    Dense(24, kernel_initializer='uniform', activation='relu'),
    Dense(1, kernel_initializer='uniform', activation='sigmoid')
])
clf.summary()<jupyter_output>_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 16)                496       
_________________________________________________________________
dense_2 (Dense)              (None, 18)                306       
_________________________________________________________________
dropout_1 (Dropout)          (None, 18)                0         
_________________________________________________________________
dense_3 (Dense)              (None, 20)                380       
_________________________________________________________________
dense_4 (Dense)              (None, 24)                504       
_________________________________________________________________
dense_5 (Dense)              (None, 1)                 25        
=================================================================
Total para[...]<jupyter_text>Compile and fit the model<jupyter_code>clf.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
clf.fit(X_train, Y_train, batch_size=15, epochs=2)<jupyter_output>Epoch 1/2
251998/251998 [==============================] - 29s - loss: 0.0075 - acc: 0.9989    
Epoch 2/2
251998/251998 [==============================] - 27s - loss: 0.0038 - acc: 0.9993<jupyter_text>Show the score<jupyter_code>score = clf.evaluate(X_test, Y_test, batch_size=128)
print('\nAnd the Score is ', score[1] * 100, '%')<jupyter_output>28000/28000 [==============================] - 0s     

And the Score is  99.9428571429 %<jupyter_text>Save the model into the local file<jupyter_code>clf.save('./model.hdf5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16661476175646217, 'fraction_numerical': 0.04360012457178449, 'mean_word_length': 4.766606822262118, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '566818', 'license': 'MIT', 'n_tokens_mistral': 1024, 'n_tokens_neox': 907, 'n_words': 189, 'path': 'modelling.ipynb', 'repo_name': 'aghabdurauf/qlik-sense-aai-creditcard-fraud', 'size': '3211'}