Get startedGet started for free

K-means clustering

A very commonly used clustering algorithm is K-means clustering. For fraud detection, K-means clustering is straightforward to implement and relatively powerful in predicting suspicious cases. It is a good algorithm to start with when working on fraud detection problems. However, fraud data is oftentimes very large, especially when you are working with transaction data. MiniBatch K-means is an efficient way to implement K-means on a large dataset, which you will use in this exercise.

The scaled data from the previous exercise, X_scaled is available. Let's give it a try.

This exercise is part of the course

Fraud Detection in Python

View Course

Exercise instructions

  • Import MiniBatchKMeans from sklearn.
  • Initialize the minibatch kmeans model with 8 clusters.
  • Fit the model to your scaled data.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import MiniBatchKmeans 
from sklearn.cluster import ____

# Define the model 
kmeans = ____(n_clusters=____, random_state=0)

# Fit the model to the scaled data
kmeans.____(____)
Edit and Run Code