Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielTavernini committed Jun 24, 2019
1 parent 0ed96b6 commit 6162935
Showing 1 changed file with 117 additions and 18 deletions.
135 changes: 117 additions & 18 deletions Gabriel_Hog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -24,7 +24,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -34,7 +34,16 @@
"id": "ATEmuaVw_VeX",
"outputId": "9cfce3d4-2323-4a72-a302-37d088552595"
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/Gabriel/Development/anaconda3/envs/WebValley/lib/python3.7/site-packages/skimage/transform/_warps.py:23: UserWarning: The default multichannel argument (None) is deprecated. Please specify either True or False explicitly. multichannel will default to False starting with release 0.16.\n",
" warn('The default multichannel argument (None) is deprecated. Please '\n"
]
}
],
"source": [
"filenames = [el for el in os.listdir(dirname) if el.endswith('.npy')]\n",
"dataset = np.zeros((len(filenames), 486), dtype=np.float32)\n",
Expand All @@ -57,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -67,15 +76,27 @@
"id": "4vPIILGE88Kw",
"outputId": "f43d71c9-f89f-4603-f314-cff778741fb6"
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"PCA(copy=True, iterated_power='auto', n_components=26, random_state=None,\n",
" svd_solver='auto', tol=0.0, whiten=False)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pca = PCA(n_components=26)\n",
"pca.fit(dataset)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -85,14 +106,26 @@
"id": "DzrsqRO89Cth",
"outputId": "32d09d2d-4305-47de-afa6-694d72fb5ae2"
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.16251983 0.06933736 0.04642825 0.04330009 0.03451309 0.02816769\n",
" 0.02274754 0.02145284 0.01891205 0.01802524 0.01760705 0.0161579\n",
" 0.01474922 0.0138591 0.013033 0.01244135 0.01222422 0.01158413\n",
" 0.01086377 0.0104156 0.01009683 0.00973011 0.00923867 0.00875507\n",
" 0.00869902 0.00850614]\n"
]
}
],
"source": [
"print(pca.explained_variance_ratio_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -116,21 +149,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "6CnRNEmI9gNP"
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
" n_clusters=2, n_init=10, n_jobs=None, precompute_distances='auto',\n",
" random_state=None, tol=0.0001, verbose=0)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kmeans = KMeans(n_clusters=2)\n",
"kmeans.fit(pca_dataset)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -140,14 +186,67 @@
"id": "XgUpL7Ws9u8-",
"outputId": "9b081883-baf0-4048-dc86-ebb0c8d05899"
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1,\n",
" 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1,\n",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1, 0, 1,\n",
" 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1,\n",
" 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0,\n",
" 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1,\n",
" 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1,\n",
" 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0,\n",
" 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1,\n",
" 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0,\n",
" 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1,\n",
" 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0,\n",
" 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0,\n",
" 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1,\n",
" 0, 1, 0, 0, 0, 0, 0, 0], dtype=int32)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kmeans.labels_"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -165,15 +264,16 @@
},
"colab_type": "code",
"id": "q6wluQ70-D3W",
"outputId": "4b3de1fb-e8db-4995-d4fc-19fa21a40468"
"outputId": "4b3de1fb-e8db-4995-d4fc-19fa21a40468",
"scrolled": false
},
"outputs": [],
"source": [
"for i, filename in enumerate(filenames):\n",
" if not \"rev\" in filename:\n",
" print(\"Label: \", kmeans.labels_[i])\n",
" img = np.load(dirname + \"/\" + filename)\n",
" ogfile = pd.read_file(\"Data/Raw/\" + filename[:][:-4] + \".dcm\")\n",
" ogfile = pydicom.read_file(\"Data/Raw/\" + filename[:][:-4] + \".dcm\")\n",
" plt.imshow(ogfile.pixel_array)\n",
" plt.show()\n",
" plt.imshow(img)\n",
Expand All @@ -189,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -203,11 +303,10 @@
"metadata": {},
"outputs": [],
"source": [
"import pydicom as pd\n",
"for filename in os.listdir(\"Data/1\"):\n",
" if not \"rev\" in filename:\n",
" img = np.load(\"Data/1/\" + filename)\n",
" ogfile = pd.read_file(\"Data/Raw/\" + filename[:][:-4] + \".dcm\")\n",
" ogfile = pydicom.read_file(\"Data/Raw/\" + filename[:][:-4] + \".dcm\")\n",
" plt.imshow(ogfile.pixel_array)\n",
" plt.show()"
]
Expand Down

0 comments on commit 6162935

Please sign in to comment.