In [2]:
%matplotlib inline
import pandas as pd
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
import mia
Loading the hologic and synthetic datasets.
In [3]:
hologic = pd.DataFrame.from_csv("/Volumes/Seagate/mmp_data/2015-04-01/hologic.csv")
phantom = pd.DataFrame.from_csv("/Volumes/Seagate/mmp_data/2015-04-16/synthetics1-blobs-upscale.csv")
Loading the meta data for the real and synthetic datasets.
In [4]:
hologic_meta = mia.analysis.create_hologic_meta_data(hologic, "/Volumes/Seagate/mmp_data/meta_data/BIRADS.csv")
phantom_meta = mia.analysis.create_synthetic_meta_data(phantom, "/Volumes/Seagate/mmp_data/meta_data/synthetic_meta_data_cleaned.csv")
phantom_meta.index.name = 'img_name'
Prepare the BI-RADS/VBD labels for both datasets.
In [5]:
hologic_labels = hologic_meta.drop_duplicates().BIRADS
phantom_labels = phantom_meta['VBD.1']
class_labels = pd.concat([hologic_labels, phantom_labels])
class_labels.index.name = "img_name"
labels = mia.analysis.remove_duplicate_index(class_labels)[0]
Create blob features from distribution of blobs
In [6]:
hologic_blob_features = mia.analysis.features_from_blobs(hologic)
phantom_blob_features = mia.analysis.features_from_blobs(phantom)
Take a random subset of the phantom mammograms. This is important so that each case is not over represented.
In [7]:
syn_feature_meta = mia.analysis.remove_duplicate_index(phantom_meta)
phantom_blob_features['phantom_name'] = syn_feature_meta.phantom_name.tolist()
phantom_blob_features_subset = mia.analysis.create_random_subset(phantom_blob_features, 'phantom_name')
Combine the features from both datasets.
In [8]:
features = pd.concat([hologic_blob_features, phantom_blob_features_subset])
assert features.shape[0] == 366
features.head()
Out[8]:
Filter some features, such as the min, to remove noise.
In [9]:
selected_features = features.drop(['min_radius'], axis=1)
In [10]:
kwargs = {
'learning_rate': 300,
'perplexity': 40,
'verbose': 1
}
In [11]:
SNE_mapping_2d = mia.analysis.tSNE(selected_features, n_components=2, **kwargs)
In [12]:
mia.plotting.plot_mapping_2d(SNE_mapping_2d, hologic_blob_features.index, phantom_blob_features.index, labels)
Out[12]:
Running t-SNE to obtain a 3 dimensional mapping
In [13]:
SNE_mapping_3d = mia.analysis.tSNE(selected_features, n_components=3, **kwargs)
In [14]:
mia.plotting.plot_mapping_3d(SNE_mapping_3d, hologic_blob_features.index, phantom_blob_features.index, labels)
Out[14]:
In [15]:
iso_kwargs = {
'n_neighbors': 8,
}
In [16]:
iso_mapping_2d = mia.analysis.isomap(selected_features, n_components=2, **iso_kwargs)
In [17]:
mia.plotting.plot_mapping_2d(iso_mapping_2d, hologic_blob_features.index, phantom_blob_features.index, labels)
Out[17]:
In [18]:
iso_mapping_3d = mia.analysis.isomap(selected_features, n_components=3, **iso_kwargs)
In [19]:
mia.plotting.plot_mapping_3d(iso_mapping_3d, hologic_blob_features.index, phantom_blob_features.index, labels)
Out[19]:
In [25]:
lle_kwargs = {
'n_neighbors': 8,
}
In [26]:
lle_mapping_2d = mia.analysis.lle(selected_features, n_components=2, **lle_kwargs)
In [27]:
mia.plotting.plot_mapping_2d(lle_mapping_2d, hologic_blob_features.index, phantom_blob_features.index, labels)
Out[27]:
In [21]:
lle_mapping_3d = mia.analysis.lle(selected_features, n_components=3, **lle_kwargs)
In [29]:
%matplotlib qt
mia.plotting.plot_mapping_3d(lle_mapping_3d, hologic_blob_features.index, phantom_blob_features.index, labels)
Out[29]: