Skip to content

Instantly share code, notes, and snippets.

@dice89
Last active December 21, 2018 17:20
Show Gist options
  • Save dice89/e455a00e2e13f346c289c4728f45205e to your computer and use it in GitHub Desktop.
Save dice89/e455a00e2e13f346c289c4728f45205e to your computer and use it in GitHub Desktop.
Load the breast cancer dataset and plots it
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import io
from sklearn.datasets import load_breast_cancer
def do_plot():
# Loading
data = load_breast_cancer()
breast_cancer_df = pd.DataFrame(data['data'])
breast_cancer_df.columns = data['feature_names']
breast_cancer_df['target'] = data['target']
breast_cancer_df['diagnosis'] = [data['target_names'][x] for x in data['target']]
feature_names= data['feature_names']
corr = breast_cancer_df[list(feature_names)].corr(method='pearson')
f, ax = plt.subplots(figsize=(11, 9))
cmap = sns.diverging_palette(220, 10, as_cmap=True)
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,
square=True, linewidths=.5, cbar_kws={"shrink": .5})
# here is the trick save your figure into a bytes object and you can afterwards expose it via flas
bytes_image = io.BytesIO()
plt.savefig(bytes_image, format='png')
bytes_image.seek(0)
return bytes_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment