application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import sklearn.cluster as cluster

data = pd.read_csv('../input/database.csv', low_memory=False)

f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(13, 15))

crims_by_relationship = data[['Relationship', 'Record ID']].groupby('Relationship').count()
crimes_per_perpetrator_race = data[['Perpetrator Race', 'Record ID']].groupby('Perpetrator Race').count()
crimes_per_victime_race = data[['Victim Race', 'Record ID']].groupby('Victim Race').count()
crimes_per_type = data[['Crime Type', 'Record ID']].groupby('Crime Type').count()

crimes_per_perpetrator_race.plot(kind='bar', ax= ax1, title='crimes per perpetrator race')
crimes_per_victime_race.plot(kind='bar', ax= ax2, title='crimes per victime race')
crims_by_relationship.plot(kind='bar', ax= ax3, title='crimes by relationship')
crimes_per_type.plot(kind='bar', ax= ax4, title='crimes types')

data1 = data[['Relationship', 'Year', 'Record ID']].groupby(['Relationship', 'Year']).count().reset_index()

victims = data[['Victim Sex', 'Victim Age', 'Victim Ethnicity', 'Victim Race']]

import seaborn as sns
import sklearn.cluster as cluster
def plot_clusters(data, algorithm, args, kwds):
    labels = algorithm(*args, **kwds).fit_predict(data)
    palette = sns.color_palette('deep', np.unique(labels).max() + 1)
    colors = [palette[x] if x >= 0 else (0.0, 0.0, 0.0) for x in labels]
    plt.scatter(data.T[0], data.T[1], c=colors, **plot_kwds)
    frame = plt.gca()
    frame.axes.get_xaxis().set_visible(False)
    frame.axes.get_yaxis().set_visible(False)
    plt.title('Clusters found by {}'.format(str(algorithm.__name__)), fontsize=24)
    plt.text(-0.5, 0.7, 'Clustering took {:.2f} s'.format(end_time - start_time), fontsize=14)
plot_clusters(victims, cluster.KMeans, (), {'n_clusters': 6})