my code stock.com

aravindh ram

Credit card fraud detection
by aravindh ram

Snippet options

Download: Download snippet as credit-card-fraud-detection.py.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

# -*- coding: utf-8 -*-
"""
Created on Thu Jun  7 11:33:57 2018

@author: aravindh
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df=pd.read_csv("Credit_Card_Applications.csv")
df.head()
X=df.iloc[:,0:-1].values
y=df.iloc[:,-1].values

#scaling
from sklearn.preprocessing import MinMaxScaler
sc=MinMaxScaler()
X=sc.fit_transform(X)
from minisom import MiniSom
som=MiniSom(10,10,input_len=15,sigma=1.0,learning_rate=0.5)
som.random_weights_init(data=X)
som.train_random(data=X,num_iteration=100)



from pylab import bone, pcolor, colorbar, plot, show
bone()
pcolor(som.distance_map().T)
colorbar()
markers = ['o', 's']
colors = ['r', 'g']
for i, x in enumerate(X):
    w = som.winner(x)
    plot(w[0] + 0.5,
         w[1] + 0.5,
         markers[y[i]],
         markeredgecolor = colors[y[i]],
         markerfacecolor = 'None',
         markersize = 10,
         markeredgewidth = 2)
show()
mapping=som.win_map(X)
frauds = np.concatenate((mapping[(8,1)], mapping[(6,8)]), axis = 0)
frauds = sc.inverse_transform(frauds)

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.