{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\nfrom imblearn.over_sampling import SMOTE","metadata":{"id":"a7_0xh_fYqy_"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/creditcards-fraud-detection/creditcard_train.csv',index_col=0)\ndf.describe()","metadata":{"id":"GyO2JTPuYqzK","outputId":"5163911a-ad48-4ba0-e026-bbbce16c51c3"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler=preprocessing.StandardScaler()\ndf['NormalizedAmount']=scaler.fit_transform(df['Amount'].values.reshape(-1,1))","metadata":{"id":"k10JPlagYqzM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"id":"Id-BxbmcYqzM","outputId":"84f5533b-5948-4f40-ae55-422b7173de64"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.drop('Amount',axis=1) \ny=df['Class']\nX=df.drop('Class',axis=1)","metadata":{"id":"QfeJ-IhCYqzN"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)","metadata":{"id":"lXaou18ZYqzN"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = keras.Sequential([\nlayers.Dense(input_dim=29, units=10, activation='relu'),\nlayers.Dense(units=10, activation='relu'),\nlayers.Dense(units=10, activation='relu'),\nlayers.Dense(units=10, activation='relu'),\nlayers.Dense(units=1, activation='sigmoid'),])","metadata":{"id":"xSvPgqUKYqzO"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_resample, y_resample = SMOTE().fit_resample(X, y)\n","metadata":{"id":"YVGJHKiPYqzP","outputId":"02605f12-5d0b-4ccb-8d2d-352cccc2c1f7"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X_resample, y_resample, test_size=0.3, random_state=0)","metadata":{"id":"IuMXmaNhYqzP"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/creditcards-fraud-detection/creditcard_test.csv', index_col=0)","metadata":{"id":"vt3doHPoYqzQ"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['NormalizedAmount']=scaler.fit_transform(df['Amount'].values.reshape(-1,1))\ndf=df.drop('Amount',axis=1) \ndf.describe()","metadata":{"id":"JzJe2PkZYqzR","outputId":"3a5ab6b7-5bba-4950-e5c8-1ae8da34a21e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam',loss='binary_crossentropy', metrics=['accuracy'])\nmodel.fit(X_train, y_train, batch_size=20, epochs=6)","metadata":{"id":"F0J7a3PlYqzS","outputId":"8fd1d78a-07d4-4c1e-e962-5ec55abf21b2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/creditcards-fraud-detection/creditcard_test.csv', index_col=0)","metadata":{"id":"ZHuS6KAjyIzb"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['NormalizedAmount'] = scaler.fit_transform(df['Amount']. values.reshape(-1,1))\ndf=df.drop('Amount',axis=1) \ndf.describe()","metadata":{"id":"RcRPEbmNYqzT","outputId":"9fbcd168-2599-49be-c9d6-27ca05a649a5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted = model.predict(df).T","metadata":{"id":"g90abkQvYqzT"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame({'Predicted': predicted[0]}).to_csv('result.csv',index_label='Id')","metadata":{"id":"Smf-rlkFYqzT"},"execution_count":null,"outputs":[]}]}