October 2018
Intermediate to advanced
172 pages
4h 6m
English
In order to load the dataset into our workspace and drop the target feature with the labels, we use the following code:
import pandas as pd#Reading in the datasetdf = pd.read_csv('fraud_prediction.csv')#Dropping the target feature & the indexdf = df.drop(['Unnamed: 0', 'isFraud'], axis = 1)
Next, we can implement the k-means algorithm with two cluster means. The choice of using two cluster means is arbitrary in nature, since we know that there should be two distinct clusters as a result of two labels: fraud and not fraud transactions. We can do this by using the following code:
from sklearn.cluster import KMeans#Initializing K-means with 2 clustersk_means = KMeans(n_clusters = 2)#Fitting the model on the data ...
Read now
Unlock full access