├── .gitignore ├── 01_the_machine_learning_landscape.ipynb ├── 02_end_to_end_machine_learning_project.ipynb ├── 03_classification.ipynb ├── 04_training_linear_models.ipynb ├── 05_support_vector_machines.ipynb ├── 06_decision_trees.ipynb ├── 07_ensemble_learning_and_random_forests.ipynb ├── 08_dimensionality_reduction.ipynb ├── 09_up_and_running_with_tensorflow.ipynb ├── 10_introduction_to_artificial_neural_networks.ipynb ├── 11_deep_learning.ipynb ├── 11_deep_learning_exercises.ipynb ├── 12_distributed_tensorflow.ipynb ├── 13_convolutional_neural_networks.ipynb ├── 14_ex_8.h5 ├── 14_recurrent_neural_networks.ipynb ├── 14_recurrent_neural_networks_ex_8-2.ipynb ├── 14_recurrent_neural_networks_ex_8.ipynb ├── 15_autoencoders.ipynb ├── 16_reinforcement_learning.ipynb ├── LICENSE ├── README.md ├── book_equations.ipynb ├── datasets ├── housing │ ├── README.md │ ├── housing.csv │ └── housing.tgz ├── inception │ └── imagenet_class_names.txt ├── lifesat │ ├── README.md │ ├── gdp_per_capita.csv │ └── oecd_bli_2015.csv └── titanic │ ├── test.csv │ └── train.csv ├── docker ├── .env ├── Dockerfile ├── Makefile ├── README.md ├── bashrc.bash ├── bin │ ├── nbclean_checkpoints │ ├── nbdiff_checkpoint │ ├── rm_empty_subdirs │ └── tensorboard ├── docker-compose.yml ├── jupyter_notebook_config.py ├── nbdime-1-details.patch └── nbdime-2-toc.patch ├── environment.yml ├── extra_autodiff.ipynb ├── extra_capsnets.ipynb ├── extra_gradient_descent_comparison.ipynb ├── extra_tensorflow_reproducibility.ipynb ├── future_encoders.py ├── images ├── ann │ ├── README │ ├── activation_functions_plot.png │ └── perceptron_iris_plot.png ├── autoencoders │ ├── README │ ├── extracted_features_plot.png │ ├── generated_digits_plot.png │ ├── linear_autoencoder_pca_plot.png │ ├── reconstruction_plot.png │ └── sparsity_loss_plot.png ├── classification │ ├── README │ ├── cleaned_digit_example_plot.png │ ├── confusion_matrix_errors_plot.png │ ├── confusion_matrix_plot.png │ ├── error_analysis_digits_plot.png │ ├── more_digits_plot.png │ ├── noisy_digit_example_plot.png │ ├── precision_recall_vs_threshold_plot.png │ ├── precision_vs_recall_plot.png │ ├── roc_curve_comparison_plot.png │ ├── roc_curve_plot.png │ └── some_digit_plot.png ├── cnn │ ├── README │ ├── china_horizontal.png │ ├── china_max_pool.png │ ├── china_original.png │ ├── china_original_small.png │ ├── china_vertical.png │ └── test_image.png ├── decision_trees │ ├── README │ ├── decision_tree_decision_boundaries_plot.png │ ├── decision_tree_instability_plot.png │ ├── iris_tree.dot │ ├── iris_tree.png │ ├── min_samples_leaf_plot.png │ ├── regression_tree.dot │ ├── regression_tree.png │ ├── sensitivity_to_rotation_plot.png │ ├── tree_regression_plot.png │ └── tree_regression_regularization_plot.png ├── deep │ ├── README │ ├── elu_plot.png │ ├── leaky_relu_plot.png │ ├── selu_plot.png │ └── sigmoid_saturation_plot.png ├── dim_reduction │ ├── README │ ├── dataset_2d_plot.png │ ├── dataset_3d_plot.png │ ├── kernel_pca_plot.png │ ├── lle_unrolling_plot.png │ ├── manifold_decision_boundary_plot1.png │ ├── manifold_decision_boundary_plot2.png │ ├── manifold_decision_boundary_plot3.png │ ├── manifold_decision_boundary_plot4.png │ ├── mnist_compression_plot.png │ ├── other_dim_reduction_plot.png │ ├── pca_best_projection.png │ ├── preimage_plot.png │ ├── squished_swiss_roll_plot.png │ └── swiss_roll_plot.png ├── distributed │ └── README ├── end_to_end_project │ ├── README │ ├── attribute_histogram_plots.png │ ├── bad_visualization_plot.png │ ├── better_visualization_plot.png │ ├── california.png │ ├── california_housing_prices_plot.png │ ├── housing_prices_scatterplot.png │ ├── income_category_hist.png │ ├── income_vs_house_value_scatterplot.png │ └── scatter_matrix_plot.png ├── ensembles │ ├── README │ ├── boosting_plot.png │ ├── decision_tree_without_and_with_bagging_plot.png │ ├── early_stopping_gbrt_plot.png │ ├── gbrt_learning_rate_plot.png │ ├── gradient_boosting_plot.png │ ├── law_of_large_numbers_plot.png │ └── mnist_feature_importance_plot.png ├── fundamentals │ ├── README │ ├── best_fit_model_plot.png │ ├── cyprus_prediction_plot.png │ ├── money_happy_scatterplot.png │ ├── overfitting_model_plot.png │ ├── representative_training_data_scatterplot.png │ ├── ridge_model_plot.png │ └── tweaking_model_params_plot.png ├── rl │ ├── MsPacman.png │ ├── README │ ├── cart_pole_plot.png │ └── preprocessing_plot.png ├── rnn │ ├── README │ ├── creative_sequence_plot.png │ ├── time_series_plot.png │ └── time_series_pred_plot.png ├── svm │ ├── README │ ├── higher_dimensions_plot.png │ ├── hinge_plot.png │ ├── iris_3D_plot.png │ ├── kernel_method_plot.png │ ├── large_margin_classification_plot.png │ ├── moons_kernelized_polynomial_svc_plot.png │ ├── moons_polynomial_svc_plot.png │ ├── moons_rbf_svc_plot.png │ ├── regularization_plot.png │ ├── sensitivity_to_feature_scales_plot.png │ ├── sensitivity_to_outliers_plot.png │ ├── small_w_large_margin_plot.png │ ├── svm_regression_plot.png │ └── svm_with_polynomial_kernel_plot.png ├── tensorflow │ └── README └── training_linear_models │ ├── README │ ├── early_stopping_plot.png │ ├── generated_data_plot.png │ ├── gradient_descent_paths_plot.png │ ├── gradient_descent_plot.png │ ├── high_degree_polynomials_plot.png │ ├── lasso_regression_plot.png │ ├── lasso_vs_ridge_plot.png │ ├── learning_curves_plot.png │ ├── linear_model_predictions.png │ ├── logistic_function_plot.png │ ├── logistic_regression_contour_plot.png │ ├── logistic_regression_plot.png │ ├── quadratic_data_plot.png │ ├── quadratic_predictions_plot.png │ ├── ridge_regression_plot.png │ ├── sgd_plot.png │ ├── softmax_regression_contour_plot.png │ └── underfitting_learning_curves_plot.png ├── index.ipynb ├── math_linear_algebra.ipynb ├── requirements.txt ├── tensorflow_graph_in_jupyter.py ├── tools_matplotlib.ipynb ├── tools_numpy.ipynb └── tools_pandas.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.ckpt 3 | *.old 4 | *.pyc 5 | .DS_Store 6 | .ipynb_checkpoints 7 | checkpoint 8 | logs/* 9 | tf_logs/* 10 | images/**/*.dot 11 | my_* 12 | datasets/flowers 13 | datasets/lifesat/lifesat.csv 14 | datasets/spam 15 | datasets/words 16 | 17 | -------------------------------------------------------------------------------- /12_distributed_tensorflow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "CPython 3.6.8\n", 13 | "IPython 7.2.0\n", 14 | "\n", 15 | "numpy 1.15.4\n", 16 | "sklearn 0.20.2\n", 17 | "scipy 1.1.0\n", 18 | "matplotlib 3.0.2\n", 19 | "tensorflow 1.13.1\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "%load_ext watermark\n", 25 | "%watermark -v -p numpy,sklearn,scipy,matplotlib,tensorflow" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "**12장 – 분산 텐서플로**" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "_이 노트북은 11장에 있는 모든 샘플 코드와 연습문제 해답을 가지고 있습니다._" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "# 설정" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "파이썬 2와 3을 모두 지원합니다. 공통 모듈을 임포트하고 맷플롯립 그림이 노트북 안에 포함되도록 설정하고 생성한 그림을 저장하기 위한 함수를 준비합니다:" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "# 파이썬 2와 파이썬 3 지원\n", 63 | "from __future__ import division, print_function, unicode_literals\n", 64 | "\n", 65 | "# 공통\n", 66 | "import numpy as np\n", 67 | "import os\n", 68 | "\n", 69 | "# 일관된 출력을 위해 유사난수 초기화\n", 70 | "def reset_graph(seed=42):\n", 71 | " tf.reset_default_graph()\n", 72 | " tf.set_random_seed(seed)\n", 73 | " np.random.seed(seed)\n", 74 | "\n", 75 | "# 맷플롯립 설정\n", 76 | "%matplotlib inline\n", 77 | "import matplotlib\n", 78 | "import matplotlib.pyplot as plt\n", 79 | "plt.rcParams['axes.labelsize'] = 14\n", 80 | "plt.rcParams['xtick.labelsize'] = 12\n", 81 | "plt.rcParams['ytick.labelsize'] = 12\n", 82 | "\n", 83 | "# 그림을 저장할 폴더\n", 84 | "PROJECT_ROOT_DIR = \".\"\n", 85 | "CHAPTER_ID = \"distributed\"\n", 86 | "\n", 87 | "def save_fig(fig_id, tight_layout=True):\n", 88 | " path = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID, fig_id + \".png\")\n", 89 | " if tight_layout:\n", 90 | " plt.tight_layout()\n", 91 | " plt.savefig(path, format='png', dpi=300)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "# 로컬 서버" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 3, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "import tensorflow as tf" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 4, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "c = tf.constant(\"Hello distributed TensorFlow!\")\n", 117 | "server = tf.train.Server.create_local_server()" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 5, 123 | "metadata": {}, 124 | "outputs": [ 125 | { 126 | "name": "stdout", 127 | "output_type": "stream", 128 | "text": [ 129 | "b'Hello distributed TensorFlow!'\n" 130 | ] 131 | } 132 | ], 133 | "source": [ 134 | "with tf.Session(server.target) as sess:\n", 135 | " print(sess.run(c))" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "# 클러스터" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 6, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "cluster_spec = tf.train.ClusterSpec({\n", 152 | " \"ps\": [\n", 153 | " \"127.0.0.1:2221\", # /job:ps/task:0\n", 154 | " \"127.0.0.1:2222\", # /job:ps/task:1\n", 155 | " ],\n", 156 | " \"worker\": [\n", 157 | " \"127.0.0.1:2223\", # /job:worker/task:0\n", 158 | " \"127.0.0.1:2224\", # /job:worker/task:1\n", 159 | " \"127.0.0.1:2225\", # /job:worker/task:2\n", 160 | " ]})" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 7, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "task_ps0 = tf.train.Server(cluster_spec, job_name=\"ps\", task_index=0)\n", 170 | "task_ps1 = tf.train.Server(cluster_spec, job_name=\"ps\", task_index=1)\n", 171 | "task_worker0 = tf.train.Server(cluster_spec, job_name=\"worker\", task_index=0)\n", 172 | "task_worker1 = tf.train.Server(cluster_spec, job_name=\"worker\", task_index=1)\n", 173 | "task_worker2 = tf.train.Server(cluster_spec, job_name=\"worker\", task_index=2)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "# 여러 디바이스와 서버에 연산을 할당하기" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 8, 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "WARNING:tensorflow:From /home/haesun/anaconda3/envs/handson-ml/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", 193 | "Instructions for updating:\n", 194 | "Colocations handled automatically by placer.\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "reset_graph()\n", 200 | "\n", 201 | "with tf.device(\"/job:ps\"):\n", 202 | " a = tf.Variable(1.0, name=\"a\")\n", 203 | "\n", 204 | "with tf.device(\"/job:worker\"):\n", 205 | " b = a + 2\n", 206 | "\n", 207 | "with tf.device(\"/job:worker/task:1\"):\n", 208 | " c = a + b" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 9, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "4.0\n" 221 | ] 222 | } 223 | ], 224 | "source": [ 225 | "with tf.Session(\"grpc://127.0.0.1:2221\") as sess:\n", 226 | " sess.run(a.initializer)\n", 227 | " print(c.eval())" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 10, 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [ 236 | "reset_graph()\n", 237 | "\n", 238 | "with tf.device(tf.train.replica_device_setter(\n", 239 | " ps_tasks=2,\n", 240 | " ps_device=\"/job:ps\",\n", 241 | " worker_device=\"/job:worker\")):\n", 242 | " v1 = tf.Variable(1.0, name=\"v1\") # /job:ps/task:0 (defaults to /cpu:0) 에 할당\n", 243 | " v2 = tf.Variable(2.0, name=\"v2\") # /job:ps/task:1 (defaults to /cpu:0) 에 할당\n", 244 | " v3 = tf.Variable(3.0, name=\"v3\") # /job:ps/task:0 (defaults to /cpu:0) 에 할당\n", 245 | " s = v1 + v2 # /job:worker (defaults to task:0/cpu:0) 에 할당\n", 246 | " with tf.device(\"/task:1\"):\n", 247 | " p1 = 2 * s # /job:worker/task:1 (defaults to /cpu:0) 에 할당\n", 248 | " with tf.device(\"/cpu:0\"):\n", 249 | " p2 = 3 * s # /job:worker/task:1/cpu:0 에 할당\n", 250 | "\n", 251 | "config = tf.ConfigProto()\n", 252 | "config.log_device_placement = True\n", 253 | "\n", 254 | "with tf.Session(\"grpc://127.0.0.1:2221\", config=config) as sess:\n", 255 | " v1.initializer.run()" 256 | ] 257 | }, 258 | { 259 | "cell_type": "markdown", 260 | "metadata": {}, 261 | "source": [ 262 | "# 리더 (Reader) - 예전 방법" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 11, 268 | "metadata": {}, 269 | "outputs": [ 270 | { 271 | "name": "stdout", 272 | "output_type": "stream", 273 | "text": [ 274 | "[1.0, 6, 44]\n" 275 | ] 276 | } 277 | ], 278 | "source": [ 279 | "reset_graph()\n", 280 | "\n", 281 | "default1 = tf.constant([5.])\n", 282 | "default2 = tf.constant([6])\n", 283 | "default3 = tf.constant([7])\n", 284 | "dec = tf.decode_csv(tf.constant(\"1.,,44\"),\n", 285 | " record_defaults=[default1, default2, default3])\n", 286 | "with tf.Session() as sess:\n", 287 | " print(sess.run(dec))" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": 12, 293 | "metadata": {}, 294 | "outputs": [ 295 | { 296 | "name": "stdout", 297 | "output_type": "stream", 298 | "text": [ 299 | "WARNING:tensorflow:From :15: TextLineReader.__init__ (from tensorflow.python.ops.io_ops) is deprecated and will be removed in a future version.\n", 300 | "Instructions for updating:\n", 301 | "Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.TextLineDataset`.\n", 302 | "더 이상 읽을 파일이 없습니다\n", 303 | "[array([[ 4., 5.],\n", 304 | " [ 1., -1.]], dtype=float32), array([1, 0], dtype=int32)]\n", 305 | "[array([[7., 8.]], dtype=float32), array([0], dtype=int32)]\n", 306 | "더 이상 훈련 샘플이 없습니다\n" 307 | ] 308 | } 309 | ], 310 | "source": [ 311 | "reset_graph()\n", 312 | "\n", 313 | "test_csv = open(\"my_test.csv\", \"w\")\n", 314 | "test_csv.write(\"x1, x2 , target\\n\")\n", 315 | "test_csv.write(\"1.,, 0\\n\")\n", 316 | "test_csv.write(\"4., 5. , 1\\n\")\n", 317 | "test_csv.write(\"7., 8. , 0\\n\")\n", 318 | "test_csv.close()\n", 319 | "\n", 320 | "filename_queue = tf.FIFOQueue(capacity=10, dtypes=[tf.string], shapes=[()])\n", 321 | "filename = tf.placeholder(tf.string)\n", 322 | "enqueue_filename = filename_queue.enqueue([filename])\n", 323 | "close_filename_queue = filename_queue.close()\n", 324 | "\n", 325 | "reader = tf.TextLineReader(skip_header_lines=1)\n", 326 | "key, value = reader.read(filename_queue)\n", 327 | "\n", 328 | "x1, x2, target = tf.decode_csv(value, record_defaults=[[-1.], [-1.], [-1]])\n", 329 | "features = tf.stack([x1, x2])\n", 330 | "\n", 331 | "instance_queue = tf.RandomShuffleQueue(\n", 332 | " capacity=10, min_after_dequeue=2,\n", 333 | " dtypes=[tf.float32, tf.int32], shapes=[[2],[]],\n", 334 | " name=\"instance_q\", shared_name=\"shared_instance_q\")\n", 335 | "enqueue_instance = instance_queue.enqueue([features, target])\n", 336 | "close_instance_queue = instance_queue.close()\n", 337 | "\n", 338 | "minibatch_instances, minibatch_targets = instance_queue.dequeue_up_to(2)\n", 339 | "\n", 340 | "with tf.Session() as sess:\n", 341 | " sess.run(enqueue_filename, feed_dict={filename: \"my_test.csv\"})\n", 342 | " sess.run(close_filename_queue)\n", 343 | " try:\n", 344 | " while True:\n", 345 | " sess.run(enqueue_instance)\n", 346 | " except tf.errors.OutOfRangeError as ex:\n", 347 | " print(\"더 이상 읽을 파일이 없습니다\")\n", 348 | " sess.run(close_instance_queue)\n", 349 | " try:\n", 350 | " while True:\n", 351 | " print(sess.run([minibatch_instances, minibatch_targets]))\n", 352 | " except tf.errors.OutOfRangeError as ex:\n", 353 | " print(\"더 이상 훈련 샘플이 없습니다\")" 354 | ] 355 | }, 356 | { 357 | "cell_type": "code", 358 | "execution_count": 13, 359 | "metadata": {}, 360 | "outputs": [], 361 | "source": [ 362 | "#coord = tf.train.Coordinator()\n", 363 | "#threads = tf.train.start_queue_runners(coord=coord)\n", 364 | "#filename_queue = tf.train.string_input_producer([\"test.csv\"])\n", 365 | "#coord.request_stop()\n", 366 | "#coord.join(threads)" 367 | ] 368 | }, 369 | { 370 | "cell_type": "markdown", 371 | "metadata": {}, 372 | "source": [ 373 | "# QueueRunner와 Coordinator" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": 14, 379 | "metadata": {}, 380 | "outputs": [ 381 | { 382 | "name": "stdout", 383 | "output_type": "stream", 384 | "text": [ 385 | "WARNING:tensorflow:From :24: QueueRunner.__init__ (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.\n", 386 | "Instructions for updating:\n", 387 | "To construct input pipelines, use the `tf.data` module.\n", 388 | "[array([[ 4., 5.],\n", 389 | " [ 1., -1.]], dtype=float32), array([1, 0], dtype=int32)]\n", 390 | "[array([[7., 8.]], dtype=float32), array([0], dtype=int32)]\n", 391 | "더 이상 훈련 샘플이 없습니다\n" 392 | ] 393 | } 394 | ], 395 | "source": [ 396 | "reset_graph()\n", 397 | "\n", 398 | "filename_queue = tf.FIFOQueue(capacity=10, dtypes=[tf.string], shapes=[()])\n", 399 | "filename = tf.placeholder(tf.string)\n", 400 | "enqueue_filename = filename_queue.enqueue([filename])\n", 401 | "close_filename_queue = filename_queue.close()\n", 402 | "\n", 403 | "reader = tf.TextLineReader(skip_header_lines=1)\n", 404 | "key, value = reader.read(filename_queue)\n", 405 | "\n", 406 | "x1, x2, target = tf.decode_csv(value, record_defaults=[[-1.], [-1.], [-1]])\n", 407 | "features = tf.stack([x1, x2])\n", 408 | "\n", 409 | "instance_queue = tf.RandomShuffleQueue(\n", 410 | " capacity=10, min_after_dequeue=2,\n", 411 | " dtypes=[tf.float32, tf.int32], shapes=[[2],[]],\n", 412 | " name=\"instance_q\", shared_name=\"shared_instance_q\")\n", 413 | "enqueue_instance = instance_queue.enqueue([features, target])\n", 414 | "close_instance_queue = instance_queue.close()\n", 415 | "\n", 416 | "minibatch_instances, minibatch_targets = instance_queue.dequeue_up_to(2)\n", 417 | "\n", 418 | "n_threads = 5\n", 419 | "queue_runner = tf.train.QueueRunner(instance_queue, [enqueue_instance] * n_threads)\n", 420 | "coord = tf.train.Coordinator()\n", 421 | "\n", 422 | "with tf.Session() as sess:\n", 423 | " sess.run(enqueue_filename, feed_dict={filename: \"my_test.csv\"})\n", 424 | " sess.run(close_filename_queue)\n", 425 | " enqueue_threads = queue_runner.create_threads(sess, coord=coord, start=True)\n", 426 | " try:\n", 427 | " while True:\n", 428 | " print(sess.run([minibatch_instances, minibatch_targets]))\n", 429 | " except tf.errors.OutOfRangeError as ex:\n", 430 | " print(\"더 이상 훈련 샘플이 없습니다\")" 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": 15, 436 | "metadata": {}, 437 | "outputs": [ 438 | { 439 | "name": "stdout", 440 | "output_type": "stream", 441 | "text": [ 442 | "[array([[ 4., 5.],\n", 443 | " [ 1., -1.]], dtype=float32), array([1, 0], dtype=int32)]\n", 444 | "[array([[7., 8.]], dtype=float32), array([0], dtype=int32)]\n", 445 | "더 이상 훈련 샘플이 없습니다\n" 446 | ] 447 | } 448 | ], 449 | "source": [ 450 | "reset_graph()\n", 451 | "\n", 452 | "def read_and_push_instance(filename_queue, instance_queue):\n", 453 | " reader = tf.TextLineReader(skip_header_lines=1)\n", 454 | " key, value = reader.read(filename_queue)\n", 455 | " x1, x2, target = tf.decode_csv(value, record_defaults=[[-1.], [-1.], [-1]])\n", 456 | " features = tf.stack([x1, x2])\n", 457 | " enqueue_instance = instance_queue.enqueue([features, target])\n", 458 | " return enqueue_instance\n", 459 | "\n", 460 | "filename_queue = tf.FIFOQueue(capacity=10, dtypes=[tf.string], shapes=[()])\n", 461 | "filename = tf.placeholder(tf.string)\n", 462 | "enqueue_filename = filename_queue.enqueue([filename])\n", 463 | "close_filename_queue = filename_queue.close()\n", 464 | "\n", 465 | "instance_queue = tf.RandomShuffleQueue(\n", 466 | " capacity=10, min_after_dequeue=2,\n", 467 | " dtypes=[tf.float32, tf.int32], shapes=[[2],[]],\n", 468 | " name=\"instance_q\", shared_name=\"shared_instance_q\")\n", 469 | "\n", 470 | "minibatch_instances, minibatch_targets = instance_queue.dequeue_up_to(2)\n", 471 | "\n", 472 | "read_and_enqueue_ops = [read_and_push_instance(filename_queue, instance_queue) for i in range(5)]\n", 473 | "queue_runner = tf.train.QueueRunner(instance_queue, read_and_enqueue_ops)\n", 474 | "\n", 475 | "with tf.Session() as sess:\n", 476 | " sess.run(enqueue_filename, feed_dict={filename: \"my_test.csv\"})\n", 477 | " sess.run(close_filename_queue)\n", 478 | " coord = tf.train.Coordinator()\n", 479 | " enqueue_threads = queue_runner.create_threads(sess, coord=coord, start=True)\n", 480 | " try:\n", 481 | " while True:\n", 482 | " print(sess.run([minibatch_instances, minibatch_targets]))\n", 483 | " except tf.errors.OutOfRangeError as ex:\n", 484 | " print(\"더 이상 훈련 샘플이 없습니다\")" 485 | ] 486 | }, 487 | { 488 | "cell_type": "markdown", 489 | "metadata": {}, 490 | "source": [ 491 | "# 타임아웃 지정하기" 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 16, 497 | "metadata": {}, 498 | "outputs": [ 499 | { 500 | "name": "stdout", 501 | "output_type": "stream", 502 | "text": [ 503 | "2.0\n", 504 | "6.0\n", 505 | "3.0\n", 506 | "4.0\n", 507 | "dequeue 타임 아웃\n" 508 | ] 509 | } 510 | ], 511 | "source": [ 512 | "reset_graph()\n", 513 | "\n", 514 | "q = tf.FIFOQueue(capacity=10, dtypes=[tf.float32], shapes=[()])\n", 515 | "v = tf.placeholder(tf.float32)\n", 516 | "enqueue = q.enqueue([v])\n", 517 | "dequeue = q.dequeue()\n", 518 | "output = dequeue + 1\n", 519 | "\n", 520 | "config = tf.ConfigProto()\n", 521 | "config.operation_timeout_in_ms = 1000\n", 522 | "\n", 523 | "with tf.Session(config=config) as sess:\n", 524 | " sess.run(enqueue, feed_dict={v: 1.0})\n", 525 | " sess.run(enqueue, feed_dict={v: 2.0})\n", 526 | " sess.run(enqueue, feed_dict={v: 3.0})\n", 527 | " print(sess.run(output))\n", 528 | " print(sess.run(output, feed_dict={dequeue: 5}))\n", 529 | " print(sess.run(output))\n", 530 | " print(sess.run(output))\n", 531 | " try:\n", 532 | " print(sess.run(output))\n", 533 | " except tf.errors.DeadlineExceededError as ex:\n", 534 | " print(\"dequeue 타임 아웃\")" 535 | ] 536 | }, 537 | { 538 | "cell_type": "markdown", 539 | "metadata": {}, 540 | "source": [ 541 | "# Data API" 542 | ] 543 | }, 544 | { 545 | "cell_type": "markdown", 546 | "metadata": {}, 547 | "source": [ 548 | "텐서플로 1.4에서 소개된 Data API를 사용하면 손쉽게 데이터를 효율적으로 읽을 수 있습니다." 549 | ] 550 | }, 551 | { 552 | "cell_type": "code", 553 | "execution_count": 17, 554 | "metadata": {}, 555 | "outputs": [], 556 | "source": [ 557 | "tf.reset_default_graph()" 558 | ] 559 | }, 560 | { 561 | "cell_type": "markdown", 562 | "metadata": {}, 563 | "source": [ 564 | "0에서 9까지 정수를 세 번 반복한 간단한 데이터셋을 일곱 개씩 배치로 만들어 시작해 보죠:" 565 | ] 566 | }, 567 | { 568 | "cell_type": "code", 569 | "execution_count": 18, 570 | "metadata": {}, 571 | "outputs": [], 572 | "source": [ 573 | "dataset = tf.data.Dataset.from_tensor_slices(np.arange(10))\n", 574 | "dataset = dataset.repeat(3).batch(7)" 575 | ] 576 | }, 577 | { 578 | "cell_type": "markdown", 579 | "metadata": {}, 580 | "source": [ 581 | "첫 번째 줄은 0에서 9까지 정수를 담은 데이터셋을 만듭니다. 두 번째 줄은 이 데이터셋의 원소를 세 번 반복하고 일곱 개씩 담은 새로운 데이터셋을 만듭니다. 위에서 볼 수 있듯이 원본 데이터셋에서 여러 변환 메서드를 연결하여 호출하여 적용했습니다." 582 | ] 583 | }, 584 | { 585 | "cell_type": "markdown", 586 | "metadata": {}, 587 | "source": [ 588 | "그다음, 데이터셋을 한 번 순회하는 원-샷-이터레이터(one-shot-iterator)를 만들고, 다음 원소를 지칭하는 텐서를 얻기 위해 `get_next()` 메서드를 호출합니다." 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 19, 594 | "metadata": {}, 595 | "outputs": [], 596 | "source": [ 597 | "iterator = dataset.make_one_shot_iterator()\n", 598 | "next_element = iterator.get_next()" 599 | ] 600 | }, 601 | { 602 | "cell_type": "markdown", 603 | "metadata": {}, 604 | "source": [ 605 | "`next_element`를 반복적으로 평가해서 데이터셋을 순회해 보죠. 원소가 별로 없기 때문에 `OutOfRangeError`가 발생합니다:" 606 | ] 607 | }, 608 | { 609 | "cell_type": "code", 610 | "execution_count": 20, 611 | "metadata": {}, 612 | "outputs": [ 613 | { 614 | "name": "stdout", 615 | "output_type": "stream", 616 | "text": [ 617 | "[0 1 2 3 4 5 6]\n", 618 | "[7 8 9 0 1 2 3]\n", 619 | "[4 5 6 7 8 9 0]\n", 620 | "[1 2 3 4 5 6 7]\n", 621 | "[8 9]\n", 622 | "완료\n" 623 | ] 624 | } 625 | ], 626 | "source": [ 627 | "with tf.Session() as sess:\n", 628 | " try:\n", 629 | " while True:\n", 630 | " print(next_element.eval())\n", 631 | " except tf.errors.OutOfRangeError:\n", 632 | " print(\"완료\")" 633 | ] 634 | }, 635 | { 636 | "cell_type": "markdown", 637 | "metadata": {}, 638 | "source": [ 639 | "좋네요! 잘 작동합니다." 640 | ] 641 | }, 642 | { 643 | "cell_type": "markdown", 644 | "metadata": {}, 645 | "source": [ 646 | "늘 그렇듯이 텐서는 그래프를 실행(`sess.run()`)할 때마다 한 번만 평가된다는 것을 기억하세요. `next_element`에 의존하는 텐서를 여러개 평가하더라도 한 번만 평가됩니다. 또한 `next_element`를 동시에 두 번 실행해도 마찬가지입니다:" 647 | ] 648 | }, 649 | { 650 | "cell_type": "code", 651 | "execution_count": 21, 652 | "metadata": {}, 653 | "outputs": [ 654 | { 655 | "name": "stdout", 656 | "output_type": "stream", 657 | "text": [ 658 | "[array([0, 1, 2, 3, 4, 5, 6]), array([0, 1, 2, 3, 4, 5, 6])]\n", 659 | "[array([7, 8, 9, 0, 1, 2, 3]), array([7, 8, 9, 0, 1, 2, 3])]\n", 660 | "[array([4, 5, 6, 7, 8, 9, 0]), array([4, 5, 6, 7, 8, 9, 0])]\n", 661 | "[array([1, 2, 3, 4, 5, 6, 7]), array([1, 2, 3, 4, 5, 6, 7])]\n", 662 | "[array([8, 9]), array([8, 9])]\n", 663 | "완료\n" 664 | ] 665 | } 666 | ], 667 | "source": [ 668 | "with tf.Session() as sess:\n", 669 | " try:\n", 670 | " while True:\n", 671 | " print(sess.run([next_element, next_element]))\n", 672 | " except tf.errors.OutOfRangeError:\n", 673 | " print(\"완료\")" 674 | ] 675 | }, 676 | { 677 | "cell_type": "markdown", 678 | "metadata": {}, 679 | "source": [ 680 | "`interleave()` 메서드는 강력하지만 처음에는 이해하기 좀 어렵습니다. 예제를 통해 이해하는 것이 가장 좋습니다:" 681 | ] 682 | }, 683 | { 684 | "cell_type": "code", 685 | "execution_count": 22, 686 | "metadata": {}, 687 | "outputs": [], 688 | "source": [ 689 | "tf.reset_default_graph()" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": 23, 695 | "metadata": {}, 696 | "outputs": [], 697 | "source": [ 698 | "dataset = tf.data.Dataset.from_tensor_slices(np.arange(10))\n", 699 | "dataset = dataset.repeat(3).batch(7)\n", 700 | "dataset = dataset.interleave(\n", 701 | " lambda v: tf.data.Dataset.from_tensor_slices(v),\n", 702 | " cycle_length=3,\n", 703 | " block_length=2)\n", 704 | "iterator = dataset.make_one_shot_iterator()\n", 705 | "next_element = iterator.get_next()" 706 | ] 707 | }, 708 | { 709 | "cell_type": "code", 710 | "execution_count": 24, 711 | "metadata": {}, 712 | "outputs": [ 713 | { 714 | "name": "stdout", 715 | "output_type": "stream", 716 | "text": [ 717 | "0,1,7,8,4,5,2,3,9,0,6,7,4,5,1,2,8,9,6,3,0,1,2,8,9,3,4,5,6,7,완료\n" 718 | ] 719 | } 720 | ], 721 | "source": [ 722 | "with tf.Session() as sess:\n", 723 | " try:\n", 724 | " while True:\n", 725 | " print(next_element.eval(), end=\",\")\n", 726 | " except tf.errors.OutOfRangeError:\n", 727 | " print(\"완료\")" 728 | ] 729 | }, 730 | { 731 | "cell_type": "markdown", 732 | "metadata": {}, 733 | "source": [ 734 | "`cycle_length=3`이므로 새로운 데이터셋은 이전 데이터셋에서 세 개의 원소를 추출합니다. 즉 `[0,1,2,3,4,5,6]`, `[7,8,9,0,1,2,3]`, `[4,5,6,7,8,9,0]` 입니다. 그다음 원소마다 하나의 데이터셋을 만들기 위해 람다(lambda) 함수를 호출합니다. `Dataset.from_tensor_slices()`를 사용했기 때문에 각 데이터셋은 차례대로 원소를 반환합니다. 다음 이 세 개의 데이터셋에서 각각 두 개의 아이템(`block_length=2`이므로)을 추출합니다. 세 개의 데이터셋의 아이템이 모두 소진될 때까지 반복됩니다. 즉 0,1 (첫 번째에서), 7,8 (두 번째에서), 4,5 (세 번째에서), 2,3 (첫 번째에서), 9,0 (두 번째에서) 등과 같은 식으로 8,9 (세 번째에서), 6 (첫 번째에서), 3 (두 번째에서), 0 (세 번째에서)까지 진행됩니다. 그다음에 원본 데이터셋에서 다음 번 세 개의 원소를 추출하려고 합니다. 하지만 두 개만 남아 있습니다. `[1,2,3,4,5,6,7]`와 `[8,9]` 입니다. 다시 이 원소로부터 데이터셋을 만들고 이 데이텃세의 아이템이 모두 소진될 때까지 두 개의 아이템을 추출합니다. 1,2 (첫 번째에서), 8,9 (두 번째에서), 3,4 (첫 번째에서), 5,6 (첫 번째에서), 7 (첫 번째에서)가 됩니다. 배열의 길이가 다르기 때문에 마지막에는 교대로 배치되지 않았습니다." 735 | ] 736 | }, 737 | { 738 | "cell_type": "markdown", 739 | "metadata": {}, 740 | "source": [ 741 | "# 리더 (Reader) - 새로운 방법" 742 | ] 743 | }, 744 | { 745 | "cell_type": "markdown", 746 | "metadata": {}, 747 | "source": [ 748 | "`from_tensor_slices()`나 `from_tensor()`를 기반으로 한 원본 데이터셋을 사용하는 대신 리더 데이터셋을 사용할 수 있습니다. 복잡한 일들을 대부분 대신 처리해 줍니다(예를 들면, 스레드):" 749 | ] 750 | }, 751 | { 752 | "cell_type": "code", 753 | "execution_count": 25, 754 | "metadata": {}, 755 | "outputs": [], 756 | "source": [ 757 | "tf.reset_default_graph()" 758 | ] 759 | }, 760 | { 761 | "cell_type": "code", 762 | "execution_count": 26, 763 | "metadata": {}, 764 | "outputs": [], 765 | "source": [ 766 | "filenames = [\"my_test.csv\"]" 767 | ] 768 | }, 769 | { 770 | "cell_type": "code", 771 | "execution_count": 27, 772 | "metadata": {}, 773 | "outputs": [], 774 | "source": [ 775 | "dataset = tf.data.TextLineDataset(filenames)" 776 | ] 777 | }, 778 | { 779 | "cell_type": "markdown", 780 | "metadata": {}, 781 | "source": [ 782 | "각 줄을 어떻게 디코드해야 하는지는 알려 주어야 합니다:" 783 | ] 784 | }, 785 | { 786 | "cell_type": "code", 787 | "execution_count": 28, 788 | "metadata": {}, 789 | "outputs": [], 790 | "source": [ 791 | "def decode_csv_line(line):\n", 792 | " x1, x2, y = tf.decode_csv(\n", 793 | " line, record_defaults=[[-1.], [-1.], [-1.]])\n", 794 | " X = tf.stack([x1, x2])\n", 795 | " return X, y" 796 | ] 797 | }, 798 | { 799 | "cell_type": "markdown", 800 | "metadata": {}, 801 | "source": [ 802 | "그다음, 이 디코딩 함수를 `map()`을 사용하여 데이터셋에 있는 각 원소에 적용할 수 있습니다:" 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "execution_count": 29, 808 | "metadata": {}, 809 | "outputs": [], 810 | "source": [ 811 | "dataset = dataset.skip(1).map(decode_csv_line)" 812 | ] 813 | }, 814 | { 815 | "cell_type": "markdown", 816 | "metadata": {}, 817 | "source": [ 818 | "마지막으로 원-샷-이터레이터를 만들어 보죠:" 819 | ] 820 | }, 821 | { 822 | "cell_type": "code", 823 | "execution_count": 30, 824 | "metadata": {}, 825 | "outputs": [], 826 | "source": [ 827 | "it = dataset.make_one_shot_iterator()\n", 828 | "X, y = it.get_next()" 829 | ] 830 | }, 831 | { 832 | "cell_type": "code", 833 | "execution_count": 31, 834 | "metadata": {}, 835 | "outputs": [ 836 | { 837 | "name": "stdout", 838 | "output_type": "stream", 839 | "text": [ 840 | "[ 1. -1.] 0.0\n", 841 | "[4. 5.] 1.0\n", 842 | "[7. 8.] 0.0\n", 843 | "완료\n" 844 | ] 845 | } 846 | ], 847 | "source": [ 848 | "with tf.Session() as sess:\n", 849 | " try:\n", 850 | " while True:\n", 851 | " X_val, y_val = sess.run([X, y])\n", 852 | " print(X_val, y_val)\n", 853 | " except tf.errors.OutOfRangeError as ex:\n", 854 | " print(\"완료\")" 855 | ] 856 | }, 857 | { 858 | "cell_type": "markdown", 859 | "metadata": { 860 | "collapsed": true 861 | }, 862 | "source": [ 863 | "# 연습문제 해답" 864 | ] 865 | }, 866 | { 867 | "cell_type": "markdown", 868 | "metadata": {}, 869 | "source": [ 870 | "**Coming soon**" 871 | ] 872 | } 873 | ], 874 | "metadata": { 875 | "kernelspec": { 876 | "display_name": "Python 3", 877 | "language": "python", 878 | "name": "python3" 879 | }, 880 | "language_info": { 881 | "codemirror_mode": { 882 | "name": "ipython", 883 | "version": 3 884 | }, 885 | "file_extension": ".py", 886 | "mimetype": "text/x-python", 887 | "name": "python", 888 | "nbconvert_exporter": "python", 889 | "pygments_lexer": "ipython3", 890 | "version": "3.6.8" 891 | }, 892 | "nav_menu": {}, 893 | "toc": { 894 | "navigate_menu": true, 895 | "number_sections": true, 896 | "sideBar": true, 897 | "threshold": 6, 898 | "toc_cell": false, 899 | "toc_section_display": "block", 900 | "toc_window_display": false 901 | } 902 | }, 903 | "nbformat": 4, 904 | "nbformat_minor": 1 905 | } 906 | -------------------------------------------------------------------------------- /14_ex_8.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/14_ex_8.h5 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | 179 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 핸즈온 머신러닝 노트북 2 | ========================== 3 | 4 | 이 깃허브는 [핸즈온 머신러닝(사이킷런과 텐서플로를 활용한 머신러닝, 딥러닝 실무)](http://www.hanbit.co.kr/store/books/look.php?p_code=B9267655530)에 포함된 예제 코드와 연습문제 해답을 가지고 있습니다: 5 | 6 | >(옮긴이)이 깃허브는 사이킷런 0.19.1, 0.20.0, 0.21.1 텐서플로 1.7, 1.8, 1.9, 1.10, 1.11, 1.12, 1.13 그리고 OpenAI gym 0.10.5에서 테스트되었습니다. 7 | 8 | [![book](http://www.hanbit.co.kr/data/books/B9267655530_l.jpg)](http://www.hanbit.co.kr/store/books/look.php?p_code=B9267655530) 9 | 10 | [주피터](http://jupyter.org/) 노트북은 다음과 같이 사용할 수 있습니다: 11 | 12 | * [jupyter.org의 노트북 뷰어](http://nbviewer.jupyter.org/github/rickiepark/handson-ml/blob/master/index.ipynb) 13 | * 노트: [github.com의 노트북 뷰어](https://github.com/rickiepark/handson-ml/blob/master/index.ipynb)도 가능하지만 좀 느리고 수식이 제대로 표현되지 않을 수 있습니다. 14 | * 이 레파지토리를 클론하고 로컬에서 주피터를 실행합니다. 이렇게 하면 코드를 사용해 여러 실험을 할 수 있습니다. 자세한 설치 방법은 아래에 있습니다. 15 | 16 | >(옮긴이) 구글의 [Colab](https://colab.research.google.com/github/rickiepark/handson-ml/blob/master/index.ipynb)을 사용하면 로컬에서 주피터를 실행하지 않고도 코드를 실행해 볼 수 있습니다. 변경한 코드는 자신의 구글 드라이브에 저장할 수 있습니다. 만약 변경한 코드를 다시 깃허브에 저장하고 싶다면 이 레파지토리를 포크한 후에 Colab을 사용하세요. 다만 이 깃허브에 있는 노트북을 위한 파이썬 패키지가 Colab에서 모두 제공되지 않을 수 있습니다. 17 | 18 | # 설치 19 | 20 | 먼저 [git](https://git-scm.com/)이 설치되어 있지 않다면 이를 설치해야 합니다. 21 | 22 | 그다음 터미널을 열고 다음 명령으로 이 레파지토리를 클론합니다. 23 | 24 | >(옮긴이) 수정된 내용을 보관하고 싶다면 깃허브에서 포크한 레파지토리를 클론하는 것이 좋습니다 25 | 26 | $ cd $HOME # 또는 적절한 다른 디렉토리 27 | $ git clone https://github.com/rickiepark/handson-ml.git 28 | $ cd handson-ml 29 | 30 | git을 설치하고 싶지 않다면, [master.zip](https://github.com/rickiepark/handson-ml/archive/master.zip)을 다운로드한 후 압축을 풀고 디렉토리 이름을 `handson-ml`로 변경한 다음 적절한 작업 디렉토리로 옮기세요. 31 | 32 | 16장의 강화학습 예제를 위해서는 [OpenAI 짐(gym)](https://gym.openai.com/docs)과 아타리 환경을 설치해야 합니다. 33 | 34 | >(옮긴이) 아나콘다가 설치되어 있다면 다음 명령을 사용하여 OpenAI 짐에 필요한 라이브러리를 먼저 시스템에 설치해야 합니다. 리눅스에서는 다음과 같습니다. 35 | > 36 | >$ sudo apt-get install -y cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev libboost-all-dev libsdl2-dev swig 37 | > 38 | >맥OS에서 명령은 다음과 같습니다. 39 | > 40 | >$ brew install cmake boost boost-python sdl2 swig wget 41 | 42 | 파이썬을 잘 알고 파이썬 라이브러리를 설치하는 방법을 알고 있으면 바로 `requirements.txt`에 리스트된 라이브러리를 설치하고 [주피터 시작하기](#starting-jupyter) 섹션으로 가도 됩니다. 자세한 설치 방법이 필요하면 다음을 참고하세요. 43 | 44 | ## 파이썬과 필수 라이브러리 45 | 46 | 당연히 파이썬이 필요합니다. 요즘 대부분의 운영체제에는 파이썬 2가 이미 설치되어 있고 때로는 파이썬 3가 설치된 경우도 있습니다. 다음 명령으로 어떤 버전의 파이썬이 설치되어 있는지 확인할 수 있습니다: 47 | 48 | $ python --version # 파이썬 2 49 | $ python3 --version # 파이썬 3 50 | 51 | 파이썬 3라면 버전에 상관없지만 3.5버전 이상이 선호됩니다. 파이썬 3가 없다면 설치하는 걸 권장합니다(파이썬 2.6 이상도 작동하지만 곧 지원이 중단될 거라 파이썬 3이 권장됩니다). 파이썬을 설치하는 방법은 몇 가지가 있습니다. 윈도우즈나 맥OS라면 [python.org](https://www.python.org/downloads/)에서 설치 파일을 다운로드 받을 수 있습니다. 맥OS에서는 [맥포트(MacPorts)](https://www.macports.org/)나 [홈브류(Homebrew)](https://brew.sh/)를 사용할 수도 있습니다. 맥OS에서 파이썬 3.6 버전을 사용하고 있다면 다음 명령으로 `certifi` 패키지를 설치해야 합니다. 맥OS의 파이썬 3.6은 SSL 연결을 검증하기 위한 증서를 가지고 있지 않기 때문입니다([스택오버플로우의 질문](https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error)을 참고하세요)): 52 | 53 | $ /Applications/Python\ 3.6/Install\ Certificates.command 54 | 55 | 리눅스에서는 어떻게 해야할지 잘 모를 땐 운영체제의 패키징 도구를 사용합니다. 예를 들어, 데비안이나 우분투에서는 다음과 같이 타이핑합니다: 56 | 57 | $ sudo apt-get update 58 | $ sudo apt-get install python3 59 | 60 | 또 다른 방법은 [아나콘다(Anaconda)](https://www.anaconda.com/downloads) 배포판을 다운로드하고 설치하는 것입니다. 이 배포판에는 파이썬과 많은 과학 라이브러리가 포함되어 있습니다. 파이썬 3 버전을 사용하는 것이 좋습니다. 61 | 62 | >(옮긴이) 윈도우즈라면 아나콘다를 사용하는 것이 거의 필수적입니다. 맥OS나 리눅스에서도 가급적 시스템에 설치된 파이썬을 변경하지 않도록 아나콘다 같은 배포판을 따로 설치하여 실험과 개발을 하는 것이 권장됩니다. 63 | 64 | 아나콘다를 선택한다면 다음 섹션을 참고하세요. 그렇지 않다면 [pip 사용하기](#using-pip) 섹션을 참고하세요. 65 | 66 | ## 아나콘다 사용하기 67 | 68 | >(옮긴이) 콘다 환경을 편리하게 만들어주기 위해 번역서 깃허브에는 `environment.yml` 파일이 포함되어 있습니다. 쉘에서 다음과 같은 명령을 실행하면 `handson-ml` 환경을 만들고 파이썬 3.5 버전과 필요한 라이브러리를 자동으로 설치해 줍니다. 69 | > 70 | >$ conda env create -f environment.yml 71 | > 72 | >만약 컴퓨터에 GPU가 있다면 environment.yml 파일에 tensorflow를 tensorflow-gpu로 변경해 주세요. 73 | 74 | 아나콘다를 사용하면 프로젝트 전용의 독립된 파이썬 환경을 만들 수 있습니다. 프로젝트마다 다른 라이브러리와 다른 버전을 설치한 별개의 환경을 유지할 수 있기 때문에 권장되는 방법입니다(가령, 이 깃허브를 위해 독립된 환경을 만듭니다): 75 | 76 | $ conda create -n mlbook python=3.5 anaconda 77 | $ source activate mlbook 78 | 79 | 이 명령은 `mlbook`이라는 이름(이름은 마음대로 바꿀 수 있습니다)으로 깨끗한 파이썬 3.5 환경을 만들고 활성화시킵니다. 이 환경은 아나콘다에 포함된 모든 과학 라이브러리를 포함시킵니다. 여기에는 텐서플로를 제외하고 우리가 필요한 모든 라이브러리가 들어 있습니다. 텐서플로는 다음과 같이 설치합니다: 80 | 81 | $ conda install -n mlbook -c conda-forge tensorflow 82 | 83 | 이 명령은 `mlbook` 환경에 아나콘다에 등록된 최근 텐서플로 버전(일반적으로 텐서플로의 최신 버전은 아닙니다)을 설치합니다(`conda-forge` 레파지토리에서 다운로드합니다). `mlbook` 환경에 설치하지 않으려면 `-n mlbook` 옵션을 빼면 됩니다. 84 | 85 | >(옮긴이) `conda-forge`에 텐서플로의 최신 버전이 다소 늦게 등록됩니다. 따라서 `conda`를 사용하는 것 보다는 `pip`를 사용하여 최신 버전의 텐서플로를 설치하는 것이 좋습니다. `environment.yml` 파일을 사용하여 환경을 만들었다면 자동으로 텐서플로 최신 버전이 설치됩니다. 86 | 87 | 그다음 선택적으로 주피터 확장팩을 설치할 수 있습니다. 노트북에 테이블을 표시할 때 좋지만 필수적이진 않습니다. 88 | 89 | $ conda install -n mlbook -c conda-forge jupyter_contrib_nbextensions 90 | 91 | 모든 것이 준비되었습니다! 이제 [주피터 시작하기](#starting-jupyter) 섹션으로 가세요. 92 | 93 | ## pip 사용하기 94 | 95 | 아나콘다를 사용하지 않는다면 이 깃허브에 필요한 파이썬 과학 라이브러리를 직접 설치해야 합니다. 특히 넘파이(NumPy), 맷플롯립(Matplotlib), 판다스(Pandas), 주피터(Jupyter) 그리고 텐서플로(TensorFlow) 등입니다. 파이썬 기본 패키징 시스템인 pip나 시스템의 패키징 시스템(가령 우분투의 apt나 맥OS의 맥포트나 홈브류)을 사용할 수 있습니다. pip를 사용하는 장점은 라이브러리와 버전이 다른 독립된 파이썬 환경을 만들기 쉽다는 것입니다(가령 이 깃허브를 위한 전용 환경). 시스템의 패키징 도구를 사용하는 장점은 파이썬 라이브러리와 시스템의 다른 패키지와 충돌할 위험이 낮다는 것입니다. 진행하는 프로젝트가 많다고 가정하고 pip를 사용하여 독립된 환경을 만들겠습니다. 또한 아나콘다와 시스템의 도구의 패키지는 최신 버전에 대응이 조금 느리고 일반적으로 pip 패키지가 가장 빠르게 최신 버전을 제공합니다. 96 | 97 | pip를 사용해 필요한 라이브러리를 설치하려면 터미널에 직접 명령을 입력해야 합니다. 노트: 만약 파이썬 3가 아니고 파이썬 2를 사용한다면 이후의 모든 명령에서 `pip3`를 `pip`로, `python3`를 `python`으로 바꾸어 주세요. 98 | 99 | 먼저 최신 버전의 pip가 설치되었는지 확인합니다: 100 | 101 | $ pip3 install --user --upgrade pip 102 | 103 | `--user` 옵션은 최신 버전의 pip를 현재 사용자에 대해서만 설치할 것입니다. `--user` 옵션을 빼고 시스템 전역에 걸쳐 설치하려면(즉, 모든 사용자를 위해서) 관리자 권한이 필요합니다(가령, 리눅스에서 `pip3` 대신에 `sudo pip3`를 사용합니다). `--user` 옵션을 사용하는 다음 명령들도 마찬가지입니다. 104 | 105 | 그다음 독립된 환경을 만들 수도 있습니다. 프로젝트마다 다른 라이브러리와 버전으로 구성된 환경을 만들 수 있으므로 이렇게 하는 것이 좋습니다: 106 | 107 | $ pip3 install --user --upgrade virtualenv 108 | $ virtualenv -p `which python3` env 109 | 110 | 이 명령은 현재 디렉토리에 파이썬 3 버전의 새로운 독립된 환경을 담고 있는 `env`라는 새로운 디렉토리를 만듭니다. 시스템에 파이썬 3의 버전이 여러 개라면 `` `which python3` ``을 적절한 파이썬 경로로 바꾸어 주세요. 111 | 112 | 이제 이 환경을 활성화시켜야 합니다. 환경을 활성화할 때마다 다음 명령을 실행해야 합니다. 113 | 114 | $ source ./env/bin/activate 115 | 116 | 윈도우 사용사는 다음 명령을 실행하세요. 117 | 118 | $ .\env\Scripts\activate 119 | 120 | 다음에 pip를 사용하여 필요한 파이썬 패키지를 설치합니다. virtualenv를 사용하지 않는다면 `--user` 옵션을 사용하세요(또는 시스템 경로에 설치할 수도 있지만 아마도 관리자 권한이 필요할 것 입니다. 가령, 리눅스에서는 `pip3` 대신 `sudo pip3`를 사용합니다). 121 | 122 | $ pip3 install --upgrade -r requirements.txt 123 | 124 | 좋습니다! 모든 것이 설치되었으니 이제 주피터를 실행해 보죠. 125 | 126 | ## 주피터 시작하기 127 | 128 | 주피터 확장을 사용하려면(이 확장은 선택 사항으로 테이블을 미려하게 표현하기 위해 사용합니다) 먼저 관련 자바스크립트와 CSS 파일을 복사해야 합니다: 129 | 130 | $ jupyter contrib nbextension install --user 131 | 132 | 그런다음 "Table of Contents (2)" 확장을 활성화시킬 수 있습니다: 133 | 134 | $ jupyter nbextension enable toc2/main 135 | 136 | 좋습니다! 이제 주피터를 실행해 보죠: 137 | 138 | $ jupyter notebook 139 | 140 | 이 명령은 브라우저를 열고 현재 디렉토리 내용을 주피터의 트리 목록으로 보여줍니다. 브라우저가 자동으로 열리지 않는다면 주소 창에 [localhost:8888](http://localhost:8888/tree)를 입력하고 `index.ipynb` 파일을 클릭하세요. 141 | 142 | 노트: 주피터 확장을 활성화하고 변경하려면 [http://localhost:8888/nbextensions](http://localhost:8888/nbextensions)를 확인해 보세요. 143 | 144 | 축하합니다! 이제 머신러닝에 뛰어들 준비를 마쳤습니다! 145 | 146 | # 기여자 147 | 148 | 유용한 피드백을 주거나 이슈를 제기하고 풀 리퀘스트를 보내 준 모든 분들에게 감사드립니다. 특히 `docker` 디렉토리를 만든 Steven Bunkley와 Ziembla에게 감사합니다. 149 | 150 | >(옮긴이) 번역 작업을 하면서 깃허브에 포함된 `docker`를 테스트하지는 않았습니다. 윈도우즈, 리눅스, 맥OS에서 텐서플로를 쉽게 설치할 수 있기 때문에 굳이 도커를 사용할 이유는 없는 것 같습니다. 151 | -------------------------------------------------------------------------------- /datasets/housing/README.md: -------------------------------------------------------------------------------- 1 | # California Housing 2 | 3 | ## Source 4 | This dataset is a modified version of the California Housing dataset available from [Luís Torgo's page](http://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html) (University of Porto). Luís Torgo obtained it from the StatLib repository (which is closed now). The dataset may also be downloaded from StatLib mirrors. 5 | 6 | This dataset appeared in a 1997 paper titled *Sparse Spatial Autoregressions* by Pace, R. Kelley and Ronald Barry, published in the *Statistics and Probability Letters* journal. They built it using the 1990 California census data. It contains one row per census block group. A block group is the smallest geographical unit for which the U.S. Census Bureau publishes sample data (a block group typically has a population of 600 to 3,000 people). 7 | 8 | ## Tweaks 9 | The dataset in this directory is almost identical to the original, with two differences: 10 | 11 | * 207 values were randomly removed from the `total_bedrooms` column, so we can discuss what to do with missing data. 12 | * An additional categorical attribute called `ocean_proximity` was added, indicating (very roughly) whether each block group is near the ocean, near the Bay area, inland or on an island. This allows discussing what to do with categorical data. 13 | 14 | Note that the block groups are called "districts" in the Jupyter notebooks, simply because in some contexts the name "block group" was confusing. 15 | 16 | ## Data description 17 | 18 | >>> housing.info() 19 | 20 | RangeIndex: 20640 entries, 0 to 20639 21 | Data columns (total 10 columns): 22 | longitude 20640 non-null float64 23 | latitude 20640 non-null float64 24 | housing_median_age 20640 non-null float64 25 | total_rooms 20640 non-null float64 26 | total_bedrooms 20433 non-null float64 27 | population 20640 non-null float64 28 | households 20640 non-null float64 29 | median_income 20640 non-null float64 30 | median_house_value 20640 non-null float64 31 | ocean_proximity 20640 non-null object 32 | dtypes: float64(9), object(1) 33 | memory usage: 1.6+ MB 34 | 35 | >>> housing["ocean_proximity"].value_counts() 36 | <1H OCEAN 9136 37 | INLAND 6551 38 | NEAR OCEAN 2658 39 | NEAR BAY 2290 40 | ISLAND 5 41 | Name: ocean_proximity, dtype: int64 42 | 43 | >>> housing.describe() 44 | longitude latitude housing_median_age total_rooms \ 45 | count 16513.000000 16513.000000 16513.000000 16513.000000 46 | mean -119.575972 35.639693 28.652335 2622.347605 47 | std 2.002048 2.138279 12.576306 2138.559393 48 | min -124.350000 32.540000 1.000000 6.000000 49 | 25% -121.800000 33.940000 18.000000 1442.000000 50 | 50% -118.510000 34.260000 29.000000 2119.000000 51 | 75% -118.010000 37.720000 37.000000 3141.000000 52 | max -114.310000 41.950000 52.000000 39320.000000 53 | 54 | total_bedrooms population households median_income 55 | count 16355.000000 16513.000000 16513.000000 16513.000000 56 | mean 534.885112 1419.525465 496.975050 3.875651 57 | std 412.716467 1115.715084 375.737945 1.905088 58 | min 2.000000 3.000000 2.000000 0.499900 59 | 25% 295.000000 784.000000 278.000000 2.566800 60 | 50% 433.000000 1164.000000 408.000000 3.541400 61 | 75% 644.000000 1718.000000 602.000000 4.745000 62 | max 6210.000000 35682.000000 5358.000000 15.000100 63 | 64 | -------------------------------------------------------------------------------- /datasets/housing/housing.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/datasets/housing/housing.tgz -------------------------------------------------------------------------------- /datasets/inception/imagenet_class_names.txt: -------------------------------------------------------------------------------- 1 | n01440764 tench, Tinca tinca 2 | n01443537 goldfish, Carassius auratus 3 | n01484850 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias 4 | n01491361 tiger shark, Galeocerdo cuvieri 5 | n01494475 hammerhead, hammerhead shark 6 | n01496331 electric ray, crampfish, numbfish, torpedo 7 | n01498041 stingray 8 | n01514668 cock 9 | n01514859 hen 10 | n01518878 ostrich, Struthio camelus 11 | n01530575 brambling, Fringilla montifringilla 12 | n01531178 goldfinch, Carduelis carduelis 13 | n01532829 house finch, linnet, Carpodacus mexicanus 14 | n01534433 junco, snowbird 15 | n01537544 indigo bunting, indigo finch, indigo bird, Passerina cyanea 16 | n01558993 robin, American robin, Turdus migratorius 17 | n01560419 bulbul 18 | n01580077 jay 19 | n01582220 magpie 20 | n01592084 chickadee 21 | n01601694 water ouzel, dipper 22 | n01608432 kite 23 | n01614925 bald eagle, American eagle, Haliaeetus leucocephalus 24 | n01616318 vulture 25 | n01622779 great grey owl, great gray owl, Strix nebulosa 26 | n01629819 European fire salamander, Salamandra salamandra 27 | n01630670 common newt, Triturus vulgaris 28 | n01631663 eft 29 | n01632458 spotted salamander, Ambystoma maculatum 30 | n01632777 axolotl, mud puppy, Ambystoma mexicanum 31 | n01641577 bullfrog, Rana catesbeiana 32 | n01644373 tree frog, tree-frog 33 | n01644900 tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui 34 | n01664065 loggerhead, loggerhead turtle, Caretta caretta 35 | n01665541 leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea 36 | n01667114 mud turtle 37 | n01667778 terrapin 38 | n01669191 box turtle, box tortoise 39 | n01675722 banded gecko 40 | n01677366 common iguana, iguana, Iguana iguana 41 | n01682714 American chameleon, anole, Anolis carolinensis 42 | n01685808 whiptail, whiptail lizard 43 | n01687978 agama 44 | n01688243 frilled lizard, Chlamydosaurus kingi 45 | n01689811 alligator lizard 46 | n01692333 Gila monster, Heloderma suspectum 47 | n01693334 green lizard, Lacerta viridis 48 | n01694178 African chameleon, Chamaeleo chamaeleon 49 | n01695060 Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis 50 | n01697457 African crocodile, Nile crocodile, Crocodylus niloticus 51 | n01698640 American alligator, Alligator mississipiensis 52 | n01704323 triceratops 53 | n01728572 thunder snake, worm snake, Carphophis amoenus 54 | n01728920 ringneck snake, ring-necked snake, ring snake 55 | n01729322 hognose snake, puff adder, sand viper 56 | n01729977 green snake, grass snake 57 | n01734418 king snake, kingsnake 58 | n01735189 garter snake, grass snake 59 | n01737021 water snake 60 | n01739381 vine snake 61 | n01740131 night snake, Hypsiglena torquata 62 | n01742172 boa constrictor, Constrictor constrictor 63 | n01744401 rock python, rock snake, Python sebae 64 | n01748264 Indian cobra, Naja naja 65 | n01749939 green mamba 66 | n01751748 sea snake 67 | n01753488 horned viper, cerastes, sand viper, horned asp, Cerastes cornutus 68 | n01755581 diamondback, diamondback rattlesnake, Crotalus adamanteus 69 | n01756291 sidewinder, horned rattlesnake, Crotalus cerastes 70 | n01768244 trilobite 71 | n01770081 harvestman, daddy longlegs, Phalangium opilio 72 | n01770393 scorpion 73 | n01773157 black and gold garden spider, Argiope aurantia 74 | n01773549 barn spider, Araneus cavaticus 75 | n01773797 garden spider, Aranea diademata 76 | n01774384 black widow, Latrodectus mactans 77 | n01774750 tarantula 78 | n01775062 wolf spider, hunting spider 79 | n01776313 tick 80 | n01784675 centipede 81 | n01795545 black grouse 82 | n01796340 ptarmigan 83 | n01797886 ruffed grouse, partridge, Bonasa umbellus 84 | n01798484 prairie chicken, prairie grouse, prairie fowl 85 | n01806143 peacock 86 | n01806567 quail 87 | n01807496 partridge 88 | n01817953 African grey, African gray, Psittacus erithacus 89 | n01818515 macaw 90 | n01819313 sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita 91 | n01820546 lorikeet 92 | n01824575 coucal 93 | n01828970 bee eater 94 | n01829413 hornbill 95 | n01833805 hummingbird 96 | n01843065 jacamar 97 | n01843383 toucan 98 | n01847000 drake 99 | n01855032 red-breasted merganser, Mergus serrator 100 | n01855672 goose 101 | n01860187 black swan, Cygnus atratus 102 | n01871265 tusker 103 | n01872401 echidna, spiny anteater, anteater 104 | n01873310 platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus 105 | n01877812 wallaby, brush kangaroo 106 | n01882714 koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus 107 | n01883070 wombat 108 | n01910747 jellyfish 109 | n01914609 sea anemone, anemone 110 | n01917289 brain coral 111 | n01924916 flatworm, platyhelminth 112 | n01930112 nematode, nematode worm, roundworm 113 | n01943899 conch 114 | n01944390 snail 115 | n01945685 slug 116 | n01950731 sea slug, nudibranch 117 | n01955084 chiton, coat-of-mail shell, sea cradle, polyplacophore 118 | n01968897 chambered nautilus, pearly nautilus, nautilus 119 | n01978287 Dungeness crab, Cancer magister 120 | n01978455 rock crab, Cancer irroratus 121 | n01980166 fiddler crab 122 | n01981276 king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica 123 | n01983481 American lobster, Northern lobster, Maine lobster, Homarus americanus 124 | n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish 125 | n01985128 crayfish, crawfish, crawdad, crawdaddy 126 | n01986214 hermit crab 127 | n01990800 isopod 128 | n02002556 white stork, Ciconia ciconia 129 | n02002724 black stork, Ciconia nigra 130 | n02006656 spoonbill 131 | n02007558 flamingo 132 | n02009229 little blue heron, Egretta caerulea 133 | n02009912 American egret, great white heron, Egretta albus 134 | n02011460 bittern 135 | n02012849 crane 136 | n02013706 limpkin, Aramus pictus 137 | n02017213 European gallinule, Porphyrio porphyrio 138 | n02018207 American coot, marsh hen, mud hen, water hen, Fulica americana 139 | n02018795 bustard 140 | n02025239 ruddy turnstone, Arenaria interpres 141 | n02027492 red-backed sandpiper, dunlin, Erolia alpina 142 | n02028035 redshank, Tringa totanus 143 | n02033041 dowitcher 144 | n02037110 oystercatcher, oyster catcher 145 | n02051845 pelican 146 | n02056570 king penguin, Aptenodytes patagonica 147 | n02058221 albatross, mollymawk 148 | n02066245 grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus 149 | n02071294 killer whale, killer, orca, grampus, sea wolf, Orcinus orca 150 | n02074367 dugong, Dugong dugon 151 | n02077923 sea lion 152 | n02085620 Chihuahua 153 | n02085782 Japanese spaniel 154 | n02085936 Maltese dog, Maltese terrier, Maltese 155 | n02086079 Pekinese, Pekingese, Peke 156 | n02086240 Shih-Tzu 157 | n02086646 Blenheim spaniel 158 | n02086910 papillon 159 | n02087046 toy terrier 160 | n02087394 Rhodesian ridgeback 161 | n02088094 Afghan hound, Afghan 162 | n02088238 basset, basset hound 163 | n02088364 beagle 164 | n02088466 bloodhound, sleuthhound 165 | n02088632 bluetick 166 | n02089078 black-and-tan coonhound 167 | n02089867 Walker hound, Walker foxhound 168 | n02089973 English foxhound 169 | n02090379 redbone 170 | n02090622 borzoi, Russian wolfhound 171 | n02090721 Irish wolfhound 172 | n02091032 Italian greyhound 173 | n02091134 whippet 174 | n02091244 Ibizan hound, Ibizan Podenco 175 | n02091467 Norwegian elkhound, elkhound 176 | n02091635 otterhound, otter hound 177 | n02091831 Saluki, gazelle hound 178 | n02092002 Scottish deerhound, deerhound 179 | n02092339 Weimaraner 180 | n02093256 Staffordshire bullterrier, Staffordshire bull terrier 181 | n02093428 American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier 182 | n02093647 Bedlington terrier 183 | n02093754 Border terrier 184 | n02093859 Kerry blue terrier 185 | n02093991 Irish terrier 186 | n02094114 Norfolk terrier 187 | n02094258 Norwich terrier 188 | n02094433 Yorkshire terrier 189 | n02095314 wire-haired fox terrier 190 | n02095570 Lakeland terrier 191 | n02095889 Sealyham terrier, Sealyham 192 | n02096051 Airedale, Airedale terrier 193 | n02096177 cairn, cairn terrier 194 | n02096294 Australian terrier 195 | n02096437 Dandie Dinmont, Dandie Dinmont terrier 196 | n02096585 Boston bull, Boston terrier 197 | n02097047 miniature schnauzer 198 | n02097130 giant schnauzer 199 | n02097209 standard schnauzer 200 | n02097298 Scotch terrier, Scottish terrier, Scottie 201 | n02097474 Tibetan terrier, chrysanthemum dog 202 | n02097658 silky terrier, Sydney silky 203 | n02098105 soft-coated wheaten terrier 204 | n02098286 West Highland white terrier 205 | n02098413 Lhasa, Lhasa apso 206 | n02099267 flat-coated retriever 207 | n02099429 curly-coated retriever 208 | n02099601 golden retriever 209 | n02099712 Labrador retriever 210 | n02099849 Chesapeake Bay retriever 211 | n02100236 German short-haired pointer 212 | n02100583 vizsla, Hungarian pointer 213 | n02100735 English setter 214 | n02100877 Irish setter, red setter 215 | n02101006 Gordon setter 216 | n02101388 Brittany spaniel 217 | n02101556 clumber, clumber spaniel 218 | n02102040 English springer, English springer spaniel 219 | n02102177 Welsh springer spaniel 220 | n02102318 cocker spaniel, English cocker spaniel, cocker 221 | n02102480 Sussex spaniel 222 | n02102973 Irish water spaniel 223 | n02104029 kuvasz 224 | n02104365 schipperke 225 | n02105056 groenendael 226 | n02105162 malinois 227 | n02105251 briard 228 | n02105412 kelpie 229 | n02105505 komondor 230 | n02105641 Old English sheepdog, bobtail 231 | n02105855 Shetland sheepdog, Shetland sheep dog, Shetland 232 | n02106030 collie 233 | n02106166 Border collie 234 | n02106382 Bouvier des Flandres, Bouviers des Flandres 235 | n02106550 Rottweiler 236 | n02106662 German shepherd, German shepherd dog, German police dog, alsatian 237 | n02107142 Doberman, Doberman pinscher 238 | n02107312 miniature pinscher 239 | n02107574 Greater Swiss Mountain dog 240 | n02107683 Bernese mountain dog 241 | n02107908 Appenzeller 242 | n02108000 EntleBucher 243 | n02108089 boxer 244 | n02108422 bull mastiff 245 | n02108551 Tibetan mastiff 246 | n02108915 French bulldog 247 | n02109047 Great Dane 248 | n02109525 Saint Bernard, St Bernard 249 | n02109961 Eskimo dog, husky 250 | n02110063 malamute, malemute, Alaskan malamute 251 | n02110185 Siberian husky 252 | n02110341 dalmatian, coach dog, carriage dog 253 | n02110627 affenpinscher, monkey pinscher, monkey dog 254 | n02110806 basenji 255 | n02110958 pug, pug-dog 256 | n02111129 Leonberg 257 | n02111277 Newfoundland, Newfoundland dog 258 | n02111500 Great Pyrenees 259 | n02111889 Samoyed, Samoyede 260 | n02112018 Pomeranian 261 | n02112137 chow, chow chow 262 | n02112350 keeshond 263 | n02112706 Brabancon griffon 264 | n02113023 Pembroke, Pembroke Welsh corgi 265 | n02113186 Cardigan, Cardigan Welsh corgi 266 | n02113624 toy poodle 267 | n02113712 miniature poodle 268 | n02113799 standard poodle 269 | n02113978 Mexican hairless 270 | n02114367 timber wolf, grey wolf, gray wolf, Canis lupus 271 | n02114548 white wolf, Arctic wolf, Canis lupus tundrarum 272 | n02114712 red wolf, maned wolf, Canis rufus, Canis niger 273 | n02114855 coyote, prairie wolf, brush wolf, Canis latrans 274 | n02115641 dingo, warrigal, warragal, Canis dingo 275 | n02115913 dhole, Cuon alpinus 276 | n02116738 African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus 277 | n02117135 hyena, hyaena 278 | n02119022 red fox, Vulpes vulpes 279 | n02119789 kit fox, Vulpes macrotis 280 | n02120079 Arctic fox, white fox, Alopex lagopus 281 | n02120505 grey fox, gray fox, Urocyon cinereoargenteus 282 | n02123045 tabby, tabby cat 283 | n02123159 tiger cat 284 | n02123394 Persian cat 285 | n02123597 Siamese cat, Siamese 286 | n02124075 Egyptian cat 287 | n02125311 cougar, puma, catamount, mountain lion, painter, panther, Felis concolor 288 | n02127052 lynx, catamount 289 | n02128385 leopard, Panthera pardus 290 | n02128757 snow leopard, ounce, Panthera uncia 291 | n02128925 jaguar, panther, Panthera onca, Felis onca 292 | n02129165 lion, king of beasts, Panthera leo 293 | n02129604 tiger, Panthera tigris 294 | n02130308 cheetah, chetah, Acinonyx jubatus 295 | n02132136 brown bear, bruin, Ursus arctos 296 | n02133161 American black bear, black bear, Ursus americanus, Euarctos americanus 297 | n02134084 ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus 298 | n02134418 sloth bear, Melursus ursinus, Ursus ursinus 299 | n02137549 mongoose 300 | n02138441 meerkat, mierkat 301 | n02165105 tiger beetle 302 | n02165456 ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle 303 | n02167151 ground beetle, carabid beetle 304 | n02168699 long-horned beetle, longicorn, longicorn beetle 305 | n02169497 leaf beetle, chrysomelid 306 | n02172182 dung beetle 307 | n02174001 rhinoceros beetle 308 | n02177972 weevil 309 | n02190166 fly 310 | n02206856 bee 311 | n02219486 ant, emmet, pismire 312 | n02226429 grasshopper, hopper 313 | n02229544 cricket 314 | n02231487 walking stick, walkingstick, stick insect 315 | n02233338 cockroach, roach 316 | n02236044 mantis, mantid 317 | n02256656 cicada, cicala 318 | n02259212 leafhopper 319 | n02264363 lacewing, lacewing fly 320 | n02268443 dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk 321 | n02268853 damselfly 322 | n02276258 admiral 323 | n02277742 ringlet, ringlet butterfly 324 | n02279972 monarch, monarch butterfly, milkweed butterfly, Danaus plexippus 325 | n02280649 cabbage butterfly 326 | n02281406 sulphur butterfly, sulfur butterfly 327 | n02281787 lycaenid, lycaenid butterfly 328 | n02317335 starfish, sea star 329 | n02319095 sea urchin 330 | n02321529 sea cucumber, holothurian 331 | n02325366 wood rabbit, cottontail, cottontail rabbit 332 | n02326432 hare 333 | n02328150 Angora, Angora rabbit 334 | n02342885 hamster 335 | n02346627 porcupine, hedgehog 336 | n02356798 fox squirrel, eastern fox squirrel, Sciurus niger 337 | n02361337 marmot 338 | n02363005 beaver 339 | n02364673 guinea pig, Cavia cobaya 340 | n02389026 sorrel 341 | n02391049 zebra 342 | n02395406 hog, pig, grunter, squealer, Sus scrofa 343 | n02396427 wild boar, boar, Sus scrofa 344 | n02397096 warthog 345 | n02398521 hippopotamus, hippo, river horse, Hippopotamus amphibius 346 | n02403003 ox 347 | n02408429 water buffalo, water ox, Asiatic buffalo, Bubalus bubalis 348 | n02410509 bison 349 | n02412080 ram, tup 350 | n02415577 bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis 351 | n02417914 ibex, Capra ibex 352 | n02422106 hartebeest 353 | n02422699 impala, Aepyceros melampus 354 | n02423022 gazelle 355 | n02437312 Arabian camel, dromedary, Camelus dromedarius 356 | n02437616 llama 357 | n02441942 weasel 358 | n02442845 mink 359 | n02443114 polecat, fitch, foulmart, foumart, Mustela putorius 360 | n02443484 black-footed ferret, ferret, Mustela nigripes 361 | n02444819 otter 362 | n02445715 skunk, polecat, wood pussy 363 | n02447366 badger 364 | n02454379 armadillo 365 | n02457408 three-toed sloth, ai, Bradypus tridactylus 366 | n02480495 orangutan, orang, orangutang, Pongo pygmaeus 367 | n02480855 gorilla, Gorilla gorilla 368 | n02481823 chimpanzee, chimp, Pan troglodytes 369 | n02483362 gibbon, Hylobates lar 370 | n02483708 siamang, Hylobates syndactylus, Symphalangus syndactylus 371 | n02484975 guenon, guenon monkey 372 | n02486261 patas, hussar monkey, Erythrocebus patas 373 | n02486410 baboon 374 | n02487347 macaque 375 | n02488291 langur 376 | n02488702 colobus, colobus monkey 377 | n02489166 proboscis monkey, Nasalis larvatus 378 | n02490219 marmoset 379 | n02492035 capuchin, ringtail, Cebus capucinus 380 | n02492660 howler monkey, howler 381 | n02493509 titi, titi monkey 382 | n02493793 spider monkey, Ateles geoffroyi 383 | n02494079 squirrel monkey, Saimiri sciureus 384 | n02497673 Madagascar cat, ring-tailed lemur, Lemur catta 385 | n02500267 indri, indris, Indri indri, Indri brevicaudatus 386 | n02504013 Indian elephant, Elephas maximus 387 | n02504458 African elephant, Loxodonta africana 388 | n02509815 lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens 389 | n02510455 giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca 390 | n02514041 barracouta, snoek 391 | n02526121 eel 392 | n02536864 coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch 393 | n02606052 rock beauty, Holocanthus tricolor 394 | n02607072 anemone fish 395 | n02640242 sturgeon 396 | n02641379 gar, garfish, garpike, billfish, Lepisosteus osseus 397 | n02643566 lionfish 398 | n02655020 puffer, pufferfish, blowfish, globefish 399 | n02666196 abacus 400 | n02667093 abaya 401 | n02669723 academic gown, academic robe, judge's robe 402 | n02672831 accordion, piano accordion, squeeze box 403 | n02676566 acoustic guitar 404 | n02687172 aircraft carrier, carrier, flattop, attack aircraft carrier 405 | n02690373 airliner 406 | n02692877 airship, dirigible 407 | n02699494 altar 408 | n02701002 ambulance 409 | n02704792 amphibian, amphibious vehicle 410 | n02708093 analog clock 411 | n02727426 apiary, bee house 412 | n02730930 apron 413 | n02747177 ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin 414 | n02749479 assault rifle, assault gun 415 | n02769748 backpack, back pack, knapsack, packsack, rucksack, haversack 416 | n02776631 bakery, bakeshop, bakehouse 417 | n02777292 balance beam, beam 418 | n02782093 balloon 419 | n02783161 ballpoint, ballpoint pen, ballpen, Biro 420 | n02786058 Band Aid 421 | n02787622 banjo 422 | n02788148 bannister, banister, balustrade, balusters, handrail 423 | n02790996 barbell 424 | n02791124 barber chair 425 | n02791270 barbershop 426 | n02793495 barn 427 | n02794156 barometer 428 | n02795169 barrel, cask 429 | n02797295 barrow, garden cart, lawn cart, wheelbarrow 430 | n02799071 baseball 431 | n02802426 basketball 432 | n02804414 bassinet 433 | n02804610 bassoon 434 | n02807133 bathing cap, swimming cap 435 | n02808304 bath towel 436 | n02808440 bathtub, bathing tub, bath, tub 437 | n02814533 beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon 438 | n02814860 beacon, lighthouse, beacon light, pharos 439 | n02815834 beaker 440 | n02817516 bearskin, busby, shako 441 | n02823428 beer bottle 442 | n02823750 beer glass 443 | n02825657 bell cote, bell cot 444 | n02834397 bib 445 | n02835271 bicycle-built-for-two, tandem bicycle, tandem 446 | n02837789 bikini, two-piece 447 | n02840245 binder, ring-binder 448 | n02841315 binoculars, field glasses, opera glasses 449 | n02843684 birdhouse 450 | n02859443 boathouse 451 | n02860847 bobsled, bobsleigh, bob 452 | n02865351 bolo tie, bolo, bola tie, bola 453 | n02869837 bonnet, poke bonnet 454 | n02870880 bookcase 455 | n02871525 bookshop, bookstore, bookstall 456 | n02877765 bottlecap 457 | n02879718 bow 458 | n02883205 bow tie, bow-tie, bowtie 459 | n02892201 brass, memorial tablet, plaque 460 | n02892767 brassiere, bra, bandeau 461 | n02894605 breakwater, groin, groyne, mole, bulwark, seawall, jetty 462 | n02895154 breastplate, aegis, egis 463 | n02906734 broom 464 | n02909870 bucket, pail 465 | n02910353 buckle 466 | n02916936 bulletproof vest 467 | n02917067 bullet train, bullet 468 | n02927161 butcher shop, meat market 469 | n02930766 cab, hack, taxi, taxicab 470 | n02939185 caldron, cauldron 471 | n02948072 candle, taper, wax light 472 | n02950826 cannon 473 | n02951358 canoe 474 | n02951585 can opener, tin opener 475 | n02963159 cardigan 476 | n02965783 car mirror 477 | n02966193 carousel, carrousel, merry-go-round, roundabout, whirligig 478 | n02966687 carpenter's kit, tool kit 479 | n02971356 carton 480 | n02974003 car wheel 481 | n02977058 cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM 482 | n02978881 cassette 483 | n02979186 cassette player 484 | n02980441 castle 485 | n02981792 catamaran 486 | n02988304 CD player 487 | n02992211 cello, violoncello 488 | n02992529 cellular telephone, cellular phone, cellphone, cell, mobile phone 489 | n02999410 chain 490 | n03000134 chainlink fence 491 | n03000247 chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour 492 | n03000684 chain saw, chainsaw 493 | n03014705 chest 494 | n03016953 chiffonier, commode 495 | n03017168 chime, bell, gong 496 | n03018349 china cabinet, china closet 497 | n03026506 Christmas stocking 498 | n03028079 church, church building 499 | n03032252 cinema, movie theater, movie theatre, movie house, picture palace 500 | n03041632 cleaver, meat cleaver, chopper 501 | n03042490 cliff dwelling 502 | n03045698 cloak 503 | n03047690 clog, geta, patten, sabot 504 | n03062245 cocktail shaker 505 | n03063599 coffee mug 506 | n03063689 coffeepot 507 | n03065424 coil, spiral, volute, whorl, helix 508 | n03075370 combination lock 509 | n03085013 computer keyboard, keypad 510 | n03089624 confectionery, confectionary, candy store 511 | n03095699 container ship, containership, container vessel 512 | n03100240 convertible 513 | n03109150 corkscrew, bottle screw 514 | n03110669 cornet, horn, trumpet, trump 515 | n03124043 cowboy boot 516 | n03124170 cowboy hat, ten-gallon hat 517 | n03125729 cradle 518 | n03126707 crane 519 | n03127747 crash helmet 520 | n03127925 crate 521 | n03131574 crib, cot 522 | n03133878 Crock Pot 523 | n03134739 croquet ball 524 | n03141823 crutch 525 | n03146219 cuirass 526 | n03160309 dam, dike, dyke 527 | n03179701 desk 528 | n03180011 desktop computer 529 | n03187595 dial telephone, dial phone 530 | n03188531 diaper, nappy, napkin 531 | n03196217 digital clock 532 | n03197337 digital watch 533 | n03201208 dining table, board 534 | n03207743 dishrag, dishcloth 535 | n03207941 dishwasher, dish washer, dishwashing machine 536 | n03208938 disk brake, disc brake 537 | n03216828 dock, dockage, docking facility 538 | n03218198 dogsled, dog sled, dog sleigh 539 | n03220513 dome 540 | n03223299 doormat, welcome mat 541 | n03240683 drilling platform, offshore rig 542 | n03249569 drum, membranophone, tympan 543 | n03250847 drumstick 544 | n03255030 dumbbell 545 | n03259280 Dutch oven 546 | n03271574 electric fan, blower 547 | n03272010 electric guitar 548 | n03272562 electric locomotive 549 | n03290653 entertainment center 550 | n03291819 envelope 551 | n03297495 espresso maker 552 | n03314780 face powder 553 | n03325584 feather boa, boa 554 | n03337140 file, file cabinet, filing cabinet 555 | n03344393 fireboat 556 | n03345487 fire engine, fire truck 557 | n03347037 fire screen, fireguard 558 | n03355925 flagpole, flagstaff 559 | n03372029 flute, transverse flute 560 | n03376595 folding chair 561 | n03379051 football helmet 562 | n03384352 forklift 563 | n03388043 fountain 564 | n03388183 fountain pen 565 | n03388549 four-poster 566 | n03393912 freight car 567 | n03394916 French horn, horn 568 | n03400231 frying pan, frypan, skillet 569 | n03404251 fur coat 570 | n03417042 garbage truck, dustcart 571 | n03424325 gasmask, respirator, gas helmet 572 | n03425413 gas pump, gasoline pump, petrol pump, island dispenser 573 | n03443371 goblet 574 | n03444034 go-kart 575 | n03445777 golf ball 576 | n03445924 golfcart, golf cart 577 | n03447447 gondola 578 | n03447721 gong, tam-tam 579 | n03450230 gown 580 | n03452741 grand piano, grand 581 | n03457902 greenhouse, nursery, glasshouse 582 | n03459775 grille, radiator grille 583 | n03461385 grocery store, grocery, food market, market 584 | n03467068 guillotine 585 | n03476684 hair slide 586 | n03476991 hair spray 587 | n03478589 half track 588 | n03481172 hammer 589 | n03482405 hamper 590 | n03483316 hand blower, blow dryer, blow drier, hair dryer, hair drier 591 | n03485407 hand-held computer, hand-held microcomputer 592 | n03485794 handkerchief, hankie, hanky, hankey 593 | n03492542 hard disc, hard disk, fixed disk 594 | n03494278 harmonica, mouth organ, harp, mouth harp 595 | n03495258 harp 596 | n03496892 harvester, reaper 597 | n03498962 hatchet 598 | n03527444 holster 599 | n03529860 home theater, home theatre 600 | n03530642 honeycomb 601 | n03532672 hook, claw 602 | n03534580 hoopskirt, crinoline 603 | n03535780 horizontal bar, high bar 604 | n03538406 horse cart, horse-cart 605 | n03544143 hourglass 606 | n03584254 iPod 607 | n03584829 iron, smoothing iron 608 | n03590841 jack-o'-lantern 609 | n03594734 jean, blue jean, denim 610 | n03594945 jeep, landrover 611 | n03595614 jersey, T-shirt, tee shirt 612 | n03598930 jigsaw puzzle 613 | n03599486 jinrikisha, ricksha, rickshaw 614 | n03602883 joystick 615 | n03617480 kimono 616 | n03623198 knee pad 617 | n03627232 knot 618 | n03630383 lab coat, laboratory coat 619 | n03633091 ladle 620 | n03637318 lampshade, lamp shade 621 | n03642806 laptop, laptop computer 622 | n03649909 lawn mower, mower 623 | n03657121 lens cap, lens cover 624 | n03658185 letter opener, paper knife, paperknife 625 | n03661043 library 626 | n03662601 lifeboat 627 | n03666591 lighter, light, igniter, ignitor 628 | n03670208 limousine, limo 629 | n03673027 liner, ocean liner 630 | n03676483 lipstick, lip rouge 631 | n03680355 Loafer 632 | n03690938 lotion 633 | n03691459 loudspeaker, speaker, speaker unit, loudspeaker system, speaker system 634 | n03692522 loupe, jeweler's loupe 635 | n03697007 lumbermill, sawmill 636 | n03706229 magnetic compass 637 | n03709823 mailbag, postbag 638 | n03710193 mailbox, letter box 639 | n03710637 maillot 640 | n03710721 maillot, tank suit 641 | n03717622 manhole cover 642 | n03720891 maraca 643 | n03721384 marimba, xylophone 644 | n03724870 mask 645 | n03729826 matchstick 646 | n03733131 maypole 647 | n03733281 maze, labyrinth 648 | n03733805 measuring cup 649 | n03742115 medicine chest, medicine cabinet 650 | n03743016 megalith, megalithic structure 651 | n03759954 microphone, mike 652 | n03761084 microwave, microwave oven 653 | n03763968 military uniform 654 | n03764736 milk can 655 | n03769881 minibus 656 | n03770439 miniskirt, mini 657 | n03770679 minivan 658 | n03773504 missile 659 | n03775071 mitten 660 | n03775546 mixing bowl 661 | n03776460 mobile home, manufactured home 662 | n03777568 Model T 663 | n03777754 modem 664 | n03781244 monastery 665 | n03782006 monitor 666 | n03785016 moped 667 | n03786901 mortar 668 | n03787032 mortarboard 669 | n03788195 mosque 670 | n03788365 mosquito net 671 | n03791053 motor scooter, scooter 672 | n03792782 mountain bike, all-terrain bike, off-roader 673 | n03792972 mountain tent 674 | n03793489 mouse, computer mouse 675 | n03794056 mousetrap 676 | n03796401 moving van 677 | n03803284 muzzle 678 | n03804744 nail 679 | n03814639 neck brace 680 | n03814906 necklace 681 | n03825788 nipple 682 | n03832673 notebook, notebook computer 683 | n03837869 obelisk 684 | n03838899 oboe, hautboy, hautbois 685 | n03840681 ocarina, sweet potato 686 | n03841143 odometer, hodometer, mileometer, milometer 687 | n03843555 oil filter 688 | n03854065 organ, pipe organ 689 | n03857828 oscilloscope, scope, cathode-ray oscilloscope, CRO 690 | n03866082 overskirt 691 | n03868242 oxcart 692 | n03868863 oxygen mask 693 | n03871628 packet 694 | n03873416 paddle, boat paddle 695 | n03874293 paddlewheel, paddle wheel 696 | n03874599 padlock 697 | n03876231 paintbrush 698 | n03877472 pajama, pyjama, pj's, jammies 699 | n03877845 palace 700 | n03884397 panpipe, pandean pipe, syrinx 701 | n03887697 paper towel 702 | n03888257 parachute, chute 703 | n03888605 parallel bars, bars 704 | n03891251 park bench 705 | n03891332 parking meter 706 | n03895866 passenger car, coach, carriage 707 | n03899768 patio, terrace 708 | n03902125 pay-phone, pay-station 709 | n03903868 pedestal, plinth, footstall 710 | n03908618 pencil box, pencil case 711 | n03908714 pencil sharpener 712 | n03916031 perfume, essence 713 | n03920288 Petri dish 714 | n03924679 photocopier 715 | n03929660 pick, plectrum, plectron 716 | n03929855 pickelhaube 717 | n03930313 picket fence, paling 718 | n03930630 pickup, pickup truck 719 | n03933933 pier 720 | n03935335 piggy bank, penny bank 721 | n03937543 pill bottle 722 | n03938244 pillow 723 | n03942813 ping-pong ball 724 | n03944341 pinwheel 725 | n03947888 pirate, pirate ship 726 | n03950228 pitcher, ewer 727 | n03954731 plane, carpenter's plane, woodworking plane 728 | n03956157 planetarium 729 | n03958227 plastic bag 730 | n03961711 plate rack 731 | n03967562 plow, plough 732 | n03970156 plunger, plumber's helper 733 | n03976467 Polaroid camera, Polaroid Land camera 734 | n03976657 pole 735 | n03977966 police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria 736 | n03980874 poncho 737 | n03982430 pool table, billiard table, snooker table 738 | n03983396 pop bottle, soda bottle 739 | n03991062 pot, flowerpot 740 | n03992509 potter's wheel 741 | n03995372 power drill 742 | n03998194 prayer rug, prayer mat 743 | n04004767 printer 744 | n04005630 prison, prison house 745 | n04008634 projectile, missile 746 | n04009552 projector 747 | n04019541 puck, hockey puck 748 | n04023962 punching bag, punch bag, punching ball, punchball 749 | n04026417 purse 750 | n04033901 quill, quill pen 751 | n04033995 quilt, comforter, comfort, puff 752 | n04037443 racer, race car, racing car 753 | n04039381 racket, racquet 754 | n04040759 radiator 755 | n04041544 radio, wireless 756 | n04044716 radio telescope, radio reflector 757 | n04049303 rain barrel 758 | n04065272 recreational vehicle, RV, R.V. 759 | n04067472 reel 760 | n04069434 reflex camera 761 | n04070727 refrigerator, icebox 762 | n04074963 remote control, remote 763 | n04081281 restaurant, eating house, eating place, eatery 764 | n04086273 revolver, six-gun, six-shooter 765 | n04090263 rifle 766 | n04099969 rocking chair, rocker 767 | n04111531 rotisserie 768 | n04116512 rubber eraser, rubber, pencil eraser 769 | n04118538 rugby ball 770 | n04118776 rule, ruler 771 | n04120489 running shoe 772 | n04125021 safe 773 | n04127249 safety pin 774 | n04131690 saltshaker, salt shaker 775 | n04133789 sandal 776 | n04136333 sarong 777 | n04141076 sax, saxophone 778 | n04141327 scabbard 779 | n04141975 scale, weighing machine 780 | n04146614 school bus 781 | n04147183 schooner 782 | n04149813 scoreboard 783 | n04152593 screen, CRT screen 784 | n04153751 screw 785 | n04154565 screwdriver 786 | n04162706 seat belt, seatbelt 787 | n04179913 sewing machine 788 | n04192698 shield, buckler 789 | n04200800 shoe shop, shoe-shop, shoe store 790 | n04201297 shoji 791 | n04204238 shopping basket 792 | n04204347 shopping cart 793 | n04208210 shovel 794 | n04209133 shower cap 795 | n04209239 shower curtain 796 | n04228054 ski 797 | n04229816 ski mask 798 | n04235860 sleeping bag 799 | n04238763 slide rule, slipstick 800 | n04239074 sliding door 801 | n04243546 slot, one-armed bandit 802 | n04251144 snorkel 803 | n04252077 snowmobile 804 | n04252225 snowplow, snowplough 805 | n04254120 soap dispenser 806 | n04254680 soccer ball 807 | n04254777 sock 808 | n04258138 solar dish, solar collector, solar furnace 809 | n04259630 sombrero 810 | n04263257 soup bowl 811 | n04264628 space bar 812 | n04265275 space heater 813 | n04266014 space shuttle 814 | n04270147 spatula 815 | n04273569 speedboat 816 | n04275548 spider web, spider's web 817 | n04277352 spindle 818 | n04285008 sports car, sport car 819 | n04286575 spotlight, spot 820 | n04296562 stage 821 | n04310018 steam locomotive 822 | n04311004 steel arch bridge 823 | n04311174 steel drum 824 | n04317175 stethoscope 825 | n04325704 stole 826 | n04326547 stone wall 827 | n04328186 stopwatch, stop watch 828 | n04330267 stove 829 | n04332243 strainer 830 | n04335435 streetcar, tram, tramcar, trolley, trolley car 831 | n04336792 stretcher 832 | n04344873 studio couch, day bed 833 | n04346328 stupa, tope 834 | n04347754 submarine, pigboat, sub, U-boat 835 | n04350905 suit, suit of clothes 836 | n04355338 sundial 837 | n04355933 sunglass 838 | n04356056 sunglasses, dark glasses, shades 839 | n04357314 sunscreen, sunblock, sun blocker 840 | n04366367 suspension bridge 841 | n04367480 swab, swob, mop 842 | n04370456 sweatshirt 843 | n04371430 swimming trunks, bathing trunks 844 | n04371774 swing 845 | n04372370 switch, electric switch, electrical switch 846 | n04376876 syringe 847 | n04380533 table lamp 848 | n04389033 tank, army tank, armored combat vehicle, armoured combat vehicle 849 | n04392985 tape player 850 | n04398044 teapot 851 | n04399382 teddy, teddy bear 852 | n04404412 television, television system 853 | n04409515 tennis ball 854 | n04417672 thatch, thatched roof 855 | n04418357 theater curtain, theatre curtain 856 | n04423845 thimble 857 | n04428191 thresher, thrasher, threshing machine 858 | n04429376 throne 859 | n04435653 tile roof 860 | n04442312 toaster 861 | n04443257 tobacco shop, tobacconist shop, tobacconist 862 | n04447861 toilet seat 863 | n04456115 torch 864 | n04458633 totem pole 865 | n04461696 tow truck, tow car, wrecker 866 | n04462240 toyshop 867 | n04465501 tractor 868 | n04467665 trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi 869 | n04476259 tray 870 | n04479046 trench coat 871 | n04482393 tricycle, trike, velocipede 872 | n04483307 trimaran 873 | n04485082 tripod 874 | n04486054 triumphal arch 875 | n04487081 trolleybus, trolley coach, trackless trolley 876 | n04487394 trombone 877 | n04493381 tub, vat 878 | n04501370 turnstile 879 | n04505470 typewriter keyboard 880 | n04507155 umbrella 881 | n04509417 unicycle, monocycle 882 | n04515003 upright, upright piano 883 | n04517823 vacuum, vacuum cleaner 884 | n04522168 vase 885 | n04523525 vault 886 | n04525038 velvet 887 | n04525305 vending machine 888 | n04532106 vestment 889 | n04532670 viaduct 890 | n04536866 violin, fiddle 891 | n04540053 volleyball 892 | n04542943 waffle iron 893 | n04548280 wall clock 894 | n04548362 wallet, billfold, notecase, pocketbook 895 | n04550184 wardrobe, closet, press 896 | n04552348 warplane, military plane 897 | n04553703 washbasin, handbasin, washbowl, lavabo, wash-hand basin 898 | n04554684 washer, automatic washer, washing machine 899 | n04557648 water bottle 900 | n04560804 water jug 901 | n04562935 water tower 902 | n04579145 whiskey jug 903 | n04579432 whistle 904 | n04584207 wig 905 | n04589890 window screen 906 | n04590129 window shade 907 | n04591157 Windsor tie 908 | n04591713 wine bottle 909 | n04592741 wing 910 | n04596742 wok 911 | n04597913 wooden spoon 912 | n04599235 wool, woolen, woollen 913 | n04604644 worm fence, snake fence, snake-rail fence, Virginia fence 914 | n04606251 wreck 915 | n04612504 yawl 916 | n04613696 yurt 917 | n06359193 web site, website, internet site, site 918 | n06596364 comic book 919 | n06785654 crossword puzzle, crossword 920 | n06794110 street sign 921 | n06874185 traffic light, traffic signal, stoplight 922 | n07248320 book jacket, dust cover, dust jacket, dust wrapper 923 | n07565083 menu 924 | n07579787 plate 925 | n07583066 guacamole 926 | n07584110 consomme 927 | n07590611 hot pot, hotpot 928 | n07613480 trifle 929 | n07614500 ice cream, icecream 930 | n07615774 ice lolly, lolly, lollipop, popsicle 931 | n07684084 French loaf 932 | n07693725 bagel, beigel 933 | n07695742 pretzel 934 | n07697313 cheeseburger 935 | n07697537 hotdog, hot dog, red hot 936 | n07711569 mashed potato 937 | n07714571 head cabbage 938 | n07714990 broccoli 939 | n07715103 cauliflower 940 | n07716358 zucchini, courgette 941 | n07716906 spaghetti squash 942 | n07717410 acorn squash 943 | n07717556 butternut squash 944 | n07718472 cucumber, cuke 945 | n07718747 artichoke, globe artichoke 946 | n07720875 bell pepper 947 | n07730033 cardoon 948 | n07734744 mushroom 949 | n07742313 Granny Smith 950 | n07745940 strawberry 951 | n07747607 orange 952 | n07749582 lemon 953 | n07753113 fig 954 | n07753275 pineapple, ananas 955 | n07753592 banana 956 | n07754684 jackfruit, jak, jack 957 | n07760859 custard apple 958 | n07768694 pomegranate 959 | n07802026 hay 960 | n07831146 carbonara 961 | n07836838 chocolate sauce, chocolate syrup 962 | n07860988 dough 963 | n07871810 meat loaf, meatloaf 964 | n07873807 pizza, pizza pie 965 | n07875152 potpie 966 | n07880968 burrito 967 | n07892512 red wine 968 | n07920052 espresso 969 | n07930864 cup 970 | n07932039 eggnog 971 | n09193705 alp 972 | n09229709 bubble 973 | n09246464 cliff, drop, drop-off 974 | n09256479 coral reef 975 | n09288635 geyser 976 | n09332890 lakeside, lakeshore 977 | n09399592 promontory, headland, head, foreland 978 | n09421951 sandbar, sand bar 979 | n09428293 seashore, coast, seacoast, sea-coast 980 | n09468604 valley, vale 981 | n09472597 volcano 982 | n09835506 ballplayer, baseball player 983 | n10148035 groom, bridegroom 984 | n10565667 scuba diver 985 | n11879895 rapeseed 986 | n11939491 daisy 987 | n12057211 yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum 988 | n12144580 corn 989 | n12267677 acorn 990 | n12620546 hip, rose hip, rosehip 991 | n12768682 buckeye, horse chestnut, conker 992 | n12985857 coral fungus 993 | n12998815 agaric 994 | n13037406 gyromitra 995 | n13040303 stinkhorn, carrion fungus 996 | n13044778 earthstar 997 | n13052670 hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa 998 | n13054560 bolete 999 | n13133613 ear, spike, capitulum 1000 | n15075141 toilet tissue, toilet paper, bathroom tissue -------------------------------------------------------------------------------- /datasets/lifesat/README.md: -------------------------------------------------------------------------------- 1 | # Life satisfaction and GDP per capita 2 | ## Life satisfaction 3 | ### Source 4 | This dataset was obtained from the OECD's website at: http://stats.oecd.org/index.aspx?DataSetCode=BLI 5 | 6 | ### Data description 7 | 8 | Int64Index: 3292 entries, 0 to 3291 9 | Data columns (total 17 columns): 10 | "LOCATION" 3292 non-null object 11 | Country 3292 non-null object 12 | INDICATOR 3292 non-null object 13 | Indicator 3292 non-null object 14 | MEASURE 3292 non-null object 15 | Measure 3292 non-null object 16 | INEQUALITY 3292 non-null object 17 | Inequality 3292 non-null object 18 | Unit Code 3292 non-null object 19 | Unit 3292 non-null object 20 | PowerCode Code 3292 non-null int64 21 | PowerCode 3292 non-null object 22 | Reference Period Code 0 non-null float64 23 | Reference Period 0 non-null float64 24 | Value 3292 non-null float64 25 | Flag Codes 1120 non-null object 26 | Flags 1120 non-null object 27 | dtypes: float64(3), int64(1), object(13) 28 | memory usage: 462.9+ KB 29 | 30 | ### Example usage using python Pandas 31 | 32 | >>> life_sat = pd.read_csv("oecd_bli_2015.csv", thousands=',') 33 | 34 | >>> life_sat_total = life_sat[life_sat["INEQUALITY"]=="TOT"] 35 | 36 | >>> life_sat_total = life_sat_total.pivot(index="Country", columns="Indicator", values="Value") 37 | 38 | >>> life_sat_total.info() 39 | 40 | Index: 37 entries, Australia to United States 41 | Data columns (total 24 columns): 42 | Air pollution 37 non-null float64 43 | Assault rate 37 non-null float64 44 | Consultation on rule-making 37 non-null float64 45 | Dwellings without basic facilities 37 non-null float64 46 | Educational attainment 37 non-null float64 47 | Employees working very long hours 37 non-null float64 48 | Employment rate 37 non-null float64 49 | Homicide rate 37 non-null float64 50 | Household net adjusted disposable income 37 non-null float64 51 | Household net financial wealth 37 non-null float64 52 | Housing expenditure 37 non-null float64 53 | Job security 37 non-null float64 54 | Life expectancy 37 non-null float64 55 | Life satisfaction 37 non-null float64 56 | Long-term unemployment rate 37 non-null float64 57 | Personal earnings 37 non-null float64 58 | Quality of support network 37 non-null float64 59 | Rooms per person 37 non-null float64 60 | Self-reported health 37 non-null float64 61 | Student skills 37 non-null float64 62 | Time devoted to leisure and personal care 37 non-null float64 63 | Voter turnout 37 non-null float64 64 | Water quality 37 non-null float64 65 | Years in education 37 non-null float64 66 | dtypes: float64(24) 67 | memory usage: 7.2+ KB 68 | 69 | ## GDP per capita 70 | ### Source 71 | Dataset obtained from the IMF's website at: http://goo.gl/j1MSKe 72 | 73 | ### Data description 74 | 75 | Int64Index: 190 entries, 0 to 189 76 | Data columns (total 7 columns): 77 | Country 190 non-null object 78 | Subject Descriptor 189 non-null object 79 | Units 189 non-null object 80 | Scale 189 non-null object 81 | Country/Series-specific Notes 188 non-null object 82 | 2015 187 non-null float64 83 | Estimates Start After 188 non-null float64 84 | dtypes: float64(2), object(5) 85 | memory usage: 11.9+ KB 86 | 87 | ### Example usage using python Pandas 88 | 89 | >>> gdp_per_capita = pd.read_csv( 90 | ... datapath+"gdp_per_capita.csv", thousands=',', delimiter='\t', 91 | ... encoding='latin1', na_values="n/a", index_col="Country") 92 | ... 93 | >>> gdp_per_capita.rename(columns={"2015": "GDP per capita"}, inplace=True) 94 | 95 | -------------------------------------------------------------------------------- /datasets/lifesat/gdp_per_capita.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/datasets/lifesat/gdp_per_capita.csv -------------------------------------------------------------------------------- /datasets/titanic/test.csv: -------------------------------------------------------------------------------- 1 | PassengerId,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked 2 | 892,3,"Kelly, Mr. James",male,34.5,0,0,330911,7.8292,,Q 3 | 893,3,"Wilkes, Mrs. James (Ellen Needs)",female,47,1,0,363272,7,,S 4 | 894,2,"Myles, Mr. Thomas Francis",male,62,0,0,240276,9.6875,,Q 5 | 895,3,"Wirz, Mr. Albert",male,27,0,0,315154,8.6625,,S 6 | 896,3,"Hirvonen, Mrs. Alexander (Helga E Lindqvist)",female,22,1,1,3101298,12.2875,,S 7 | 897,3,"Svensson, Mr. Johan Cervin",male,14,0,0,7538,9.225,,S 8 | 898,3,"Connolly, Miss. Kate",female,30,0,0,330972,7.6292,,Q 9 | 899,2,"Caldwell, Mr. Albert Francis",male,26,1,1,248738,29,,S 10 | 900,3,"Abrahim, Mrs. Joseph (Sophie Halaut Easu)",female,18,0,0,2657,7.2292,,C 11 | 901,3,"Davies, Mr. John Samuel",male,21,2,0,A/4 48871,24.15,,S 12 | 902,3,"Ilieff, Mr. Ylio",male,,0,0,349220,7.8958,,S 13 | 903,1,"Jones, Mr. Charles Cresson",male,46,0,0,694,26,,S 14 | 904,1,"Snyder, Mrs. John Pillsbury (Nelle Stevenson)",female,23,1,0,21228,82.2667,B45,S 15 | 905,2,"Howard, Mr. Benjamin",male,63,1,0,24065,26,,S 16 | 906,1,"Chaffee, Mrs. Herbert Fuller (Carrie Constance Toogood)",female,47,1,0,W.E.P. 5734,61.175,E31,S 17 | 907,2,"del Carlo, Mrs. Sebastiano (Argenia Genovesi)",female,24,1,0,SC/PARIS 2167,27.7208,,C 18 | 908,2,"Keane, Mr. Daniel",male,35,0,0,233734,12.35,,Q 19 | 909,3,"Assaf, Mr. Gerios",male,21,0,0,2692,7.225,,C 20 | 910,3,"Ilmakangas, Miss. Ida Livija",female,27,1,0,STON/O2. 3101270,7.925,,S 21 | 911,3,"Assaf Khalil, Mrs. Mariana (Miriam"")""",female,45,0,0,2696,7.225,,C 22 | 912,1,"Rothschild, Mr. Martin",male,55,1,0,PC 17603,59.4,,C 23 | 913,3,"Olsen, Master. Artur Karl",male,9,0,1,C 17368,3.1708,,S 24 | 914,1,"Flegenheim, Mrs. Alfred (Antoinette)",female,,0,0,PC 17598,31.6833,,S 25 | 915,1,"Williams, Mr. Richard Norris II",male,21,0,1,PC 17597,61.3792,,C 26 | 916,1,"Ryerson, Mrs. Arthur Larned (Emily Maria Borie)",female,48,1,3,PC 17608,262.375,B57 B59 B63 B66,C 27 | 917,3,"Robins, Mr. Alexander A",male,50,1,0,A/5. 3337,14.5,,S 28 | 918,1,"Ostby, Miss. Helene Ragnhild",female,22,0,1,113509,61.9792,B36,C 29 | 919,3,"Daher, Mr. Shedid",male,22.5,0,0,2698,7.225,,C 30 | 920,1,"Brady, Mr. John Bertram",male,41,0,0,113054,30.5,A21,S 31 | 921,3,"Samaan, Mr. Elias",male,,2,0,2662,21.6792,,C 32 | 922,2,"Louch, Mr. Charles Alexander",male,50,1,0,SC/AH 3085,26,,S 33 | 923,2,"Jefferys, Mr. Clifford Thomas",male,24,2,0,C.A. 31029,31.5,,S 34 | 924,3,"Dean, Mrs. Bertram (Eva Georgetta Light)",female,33,1,2,C.A. 2315,20.575,,S 35 | 925,3,"Johnston, Mrs. Andrew G (Elizabeth Lily"" Watson)""",female,,1,2,W./C. 6607,23.45,,S 36 | 926,1,"Mock, Mr. Philipp Edmund",male,30,1,0,13236,57.75,C78,C 37 | 927,3,"Katavelas, Mr. Vassilios (Catavelas Vassilios"")""",male,18.5,0,0,2682,7.2292,,C 38 | 928,3,"Roth, Miss. Sarah A",female,,0,0,342712,8.05,,S 39 | 929,3,"Cacic, Miss. Manda",female,21,0,0,315087,8.6625,,S 40 | 930,3,"Sap, Mr. Julius",male,25,0,0,345768,9.5,,S 41 | 931,3,"Hee, Mr. Ling",male,,0,0,1601,56.4958,,S 42 | 932,3,"Karun, Mr. Franz",male,39,0,1,349256,13.4167,,C 43 | 933,1,"Franklin, Mr. Thomas Parham",male,,0,0,113778,26.55,D34,S 44 | 934,3,"Goldsmith, Mr. Nathan",male,41,0,0,SOTON/O.Q. 3101263,7.85,,S 45 | 935,2,"Corbett, Mrs. Walter H (Irene Colvin)",female,30,0,0,237249,13,,S 46 | 936,1,"Kimball, Mrs. Edwin Nelson Jr (Gertrude Parsons)",female,45,1,0,11753,52.5542,D19,S 47 | 937,3,"Peltomaki, Mr. Nikolai Johannes",male,25,0,0,STON/O 2. 3101291,7.925,,S 48 | 938,1,"Chevre, Mr. Paul Romaine",male,45,0,0,PC 17594,29.7,A9,C 49 | 939,3,"Shaughnessy, Mr. Patrick",male,,0,0,370374,7.75,,Q 50 | 940,1,"Bucknell, Mrs. William Robert (Emma Eliza Ward)",female,60,0,0,11813,76.2917,D15,C 51 | 941,3,"Coutts, Mrs. William (Winnie Minnie"" Treanor)""",female,36,0,2,C.A. 37671,15.9,,S 52 | 942,1,"Smith, Mr. Lucien Philip",male,24,1,0,13695,60,C31,S 53 | 943,2,"Pulbaum, Mr. Franz",male,27,0,0,SC/PARIS 2168,15.0333,,C 54 | 944,2,"Hocking, Miss. Ellen Nellie""""",female,20,2,1,29105,23,,S 55 | 945,1,"Fortune, Miss. Ethel Flora",female,28,3,2,19950,263,C23 C25 C27,S 56 | 946,2,"Mangiavacchi, Mr. Serafino Emilio",male,,0,0,SC/A.3 2861,15.5792,,C 57 | 947,3,"Rice, Master. Albert",male,10,4,1,382652,29.125,,Q 58 | 948,3,"Cor, Mr. Bartol",male,35,0,0,349230,7.8958,,S 59 | 949,3,"Abelseth, Mr. Olaus Jorgensen",male,25,0,0,348122,7.65,F G63,S 60 | 950,3,"Davison, Mr. Thomas Henry",male,,1,0,386525,16.1,,S 61 | 951,1,"Chaudanson, Miss. Victorine",female,36,0,0,PC 17608,262.375,B61,C 62 | 952,3,"Dika, Mr. Mirko",male,17,0,0,349232,7.8958,,S 63 | 953,2,"McCrae, Mr. Arthur Gordon",male,32,0,0,237216,13.5,,S 64 | 954,3,"Bjorklund, Mr. Ernst Herbert",male,18,0,0,347090,7.75,,S 65 | 955,3,"Bradley, Miss. Bridget Delia",female,22,0,0,334914,7.725,,Q 66 | 956,1,"Ryerson, Master. John Borie",male,13,2,2,PC 17608,262.375,B57 B59 B63 B66,C 67 | 957,2,"Corey, Mrs. Percy C (Mary Phyllis Elizabeth Miller)",female,,0,0,F.C.C. 13534,21,,S 68 | 958,3,"Burns, Miss. Mary Delia",female,18,0,0,330963,7.8792,,Q 69 | 959,1,"Moore, Mr. Clarence Bloomfield",male,47,0,0,113796,42.4,,S 70 | 960,1,"Tucker, Mr. Gilbert Milligan Jr",male,31,0,0,2543,28.5375,C53,C 71 | 961,1,"Fortune, Mrs. Mark (Mary McDougald)",female,60,1,4,19950,263,C23 C25 C27,S 72 | 962,3,"Mulvihill, Miss. Bertha E",female,24,0,0,382653,7.75,,Q 73 | 963,3,"Minkoff, Mr. Lazar",male,21,0,0,349211,7.8958,,S 74 | 964,3,"Nieminen, Miss. Manta Josefina",female,29,0,0,3101297,7.925,,S 75 | 965,1,"Ovies y Rodriguez, Mr. Servando",male,28.5,0,0,PC 17562,27.7208,D43,C 76 | 966,1,"Geiger, Miss. Amalie",female,35,0,0,113503,211.5,C130,C 77 | 967,1,"Keeping, Mr. Edwin",male,32.5,0,0,113503,211.5,C132,C 78 | 968,3,"Miles, Mr. Frank",male,,0,0,359306,8.05,,S 79 | 969,1,"Cornell, Mrs. Robert Clifford (Malvina Helen Lamson)",female,55,2,0,11770,25.7,C101,S 80 | 970,2,"Aldworth, Mr. Charles Augustus",male,30,0,0,248744,13,,S 81 | 971,3,"Doyle, Miss. Elizabeth",female,24,0,0,368702,7.75,,Q 82 | 972,3,"Boulos, Master. Akar",male,6,1,1,2678,15.2458,,C 83 | 973,1,"Straus, Mr. Isidor",male,67,1,0,PC 17483,221.7792,C55 C57,S 84 | 974,1,"Case, Mr. Howard Brown",male,49,0,0,19924,26,,S 85 | 975,3,"Demetri, Mr. Marinko",male,,0,0,349238,7.8958,,S 86 | 976,2,"Lamb, Mr. John Joseph",male,,0,0,240261,10.7083,,Q 87 | 977,3,"Khalil, Mr. Betros",male,,1,0,2660,14.4542,,C 88 | 978,3,"Barry, Miss. Julia",female,27,0,0,330844,7.8792,,Q 89 | 979,3,"Badman, Miss. Emily Louisa",female,18,0,0,A/4 31416,8.05,,S 90 | 980,3,"O'Donoghue, Ms. Bridget",female,,0,0,364856,7.75,,Q 91 | 981,2,"Wells, Master. Ralph Lester",male,2,1,1,29103,23,,S 92 | 982,3,"Dyker, Mrs. Adolf Fredrik (Anna Elisabeth Judith Andersson)",female,22,1,0,347072,13.9,,S 93 | 983,3,"Pedersen, Mr. Olaf",male,,0,0,345498,7.775,,S 94 | 984,1,"Davidson, Mrs. Thornton (Orian Hays)",female,27,1,2,F.C. 12750,52,B71,S 95 | 985,3,"Guest, Mr. Robert",male,,0,0,376563,8.05,,S 96 | 986,1,"Birnbaum, Mr. Jakob",male,25,0,0,13905,26,,C 97 | 987,3,"Tenglin, Mr. Gunnar Isidor",male,25,0,0,350033,7.7958,,S 98 | 988,1,"Cavendish, Mrs. Tyrell William (Julia Florence Siegel)",female,76,1,0,19877,78.85,C46,S 99 | 989,3,"Makinen, Mr. Kalle Edvard",male,29,0,0,STON/O 2. 3101268,7.925,,S 100 | 990,3,"Braf, Miss. Elin Ester Maria",female,20,0,0,347471,7.8542,,S 101 | 991,3,"Nancarrow, Mr. William Henry",male,33,0,0,A./5. 3338,8.05,,S 102 | 992,1,"Stengel, Mrs. Charles Emil Henry (Annie May Morris)",female,43,1,0,11778,55.4417,C116,C 103 | 993,2,"Weisz, Mr. Leopold",male,27,1,0,228414,26,,S 104 | 994,3,"Foley, Mr. William",male,,0,0,365235,7.75,,Q 105 | 995,3,"Johansson Palmquist, Mr. Oskar Leander",male,26,0,0,347070,7.775,,S 106 | 996,3,"Thomas, Mrs. Alexander (Thamine Thelma"")""",female,16,1,1,2625,8.5167,,C 107 | 997,3,"Holthen, Mr. Johan Martin",male,28,0,0,C 4001,22.525,,S 108 | 998,3,"Buckley, Mr. Daniel",male,21,0,0,330920,7.8208,,Q 109 | 999,3,"Ryan, Mr. Edward",male,,0,0,383162,7.75,,Q 110 | 1000,3,"Willer, Mr. Aaron (Abi Weller"")""",male,,0,0,3410,8.7125,,S 111 | 1001,2,"Swane, Mr. George",male,18.5,0,0,248734,13,F,S 112 | 1002,2,"Stanton, Mr. Samuel Ward",male,41,0,0,237734,15.0458,,C 113 | 1003,3,"Shine, Miss. Ellen Natalia",female,,0,0,330968,7.7792,,Q 114 | 1004,1,"Evans, Miss. Edith Corse",female,36,0,0,PC 17531,31.6792,A29,C 115 | 1005,3,"Buckley, Miss. Katherine",female,18.5,0,0,329944,7.2833,,Q 116 | 1006,1,"Straus, Mrs. Isidor (Rosalie Ida Blun)",female,63,1,0,PC 17483,221.7792,C55 C57,S 117 | 1007,3,"Chronopoulos, Mr. Demetrios",male,18,1,0,2680,14.4542,,C 118 | 1008,3,"Thomas, Mr. John",male,,0,0,2681,6.4375,,C 119 | 1009,3,"Sandstrom, Miss. Beatrice Irene",female,1,1,1,PP 9549,16.7,G6,S 120 | 1010,1,"Beattie, Mr. Thomson",male,36,0,0,13050,75.2417,C6,C 121 | 1011,2,"Chapman, Mrs. John Henry (Sara Elizabeth Lawry)",female,29,1,0,SC/AH 29037,26,,S 122 | 1012,2,"Watt, Miss. Bertha J",female,12,0,0,C.A. 33595,15.75,,S 123 | 1013,3,"Kiernan, Mr. John",male,,1,0,367227,7.75,,Q 124 | 1014,1,"Schabert, Mrs. Paul (Emma Mock)",female,35,1,0,13236,57.75,C28,C 125 | 1015,3,"Carver, Mr. Alfred John",male,28,0,0,392095,7.25,,S 126 | 1016,3,"Kennedy, Mr. John",male,,0,0,368783,7.75,,Q 127 | 1017,3,"Cribb, Miss. Laura Alice",female,17,0,1,371362,16.1,,S 128 | 1018,3,"Brobeck, Mr. Karl Rudolf",male,22,0,0,350045,7.7958,,S 129 | 1019,3,"McCoy, Miss. Alicia",female,,2,0,367226,23.25,,Q 130 | 1020,2,"Bowenur, Mr. Solomon",male,42,0,0,211535,13,,S 131 | 1021,3,"Petersen, Mr. Marius",male,24,0,0,342441,8.05,,S 132 | 1022,3,"Spinner, Mr. Henry John",male,32,0,0,STON/OQ. 369943,8.05,,S 133 | 1023,1,"Gracie, Col. Archibald IV",male,53,0,0,113780,28.5,C51,C 134 | 1024,3,"Lefebre, Mrs. Frank (Frances)",female,,0,4,4133,25.4667,,S 135 | 1025,3,"Thomas, Mr. Charles P",male,,1,0,2621,6.4375,,C 136 | 1026,3,"Dintcheff, Mr. Valtcho",male,43,0,0,349226,7.8958,,S 137 | 1027,3,"Carlsson, Mr. Carl Robert",male,24,0,0,350409,7.8542,,S 138 | 1028,3,"Zakarian, Mr. Mapriededer",male,26.5,0,0,2656,7.225,,C 139 | 1029,2,"Schmidt, Mr. August",male,26,0,0,248659,13,,S 140 | 1030,3,"Drapkin, Miss. Jennie",female,23,0,0,SOTON/OQ 392083,8.05,,S 141 | 1031,3,"Goodwin, Mr. Charles Frederick",male,40,1,6,CA 2144,46.9,,S 142 | 1032,3,"Goodwin, Miss. Jessie Allis",female,10,5,2,CA 2144,46.9,,S 143 | 1033,1,"Daniels, Miss. Sarah",female,33,0,0,113781,151.55,,S 144 | 1034,1,"Ryerson, Mr. Arthur Larned",male,61,1,3,PC 17608,262.375,B57 B59 B63 B66,C 145 | 1035,2,"Beauchamp, Mr. Henry James",male,28,0,0,244358,26,,S 146 | 1036,1,"Lindeberg-Lind, Mr. Erik Gustaf (Mr Edward Lingrey"")""",male,42,0,0,17475,26.55,,S 147 | 1037,3,"Vander Planke, Mr. Julius",male,31,3,0,345763,18,,S 148 | 1038,1,"Hilliard, Mr. Herbert Henry",male,,0,0,17463,51.8625,E46,S 149 | 1039,3,"Davies, Mr. Evan",male,22,0,0,SC/A4 23568,8.05,,S 150 | 1040,1,"Crafton, Mr. John Bertram",male,,0,0,113791,26.55,,S 151 | 1041,2,"Lahtinen, Rev. William",male,30,1,1,250651,26,,S 152 | 1042,1,"Earnshaw, Mrs. Boulton (Olive Potter)",female,23,0,1,11767,83.1583,C54,C 153 | 1043,3,"Matinoff, Mr. Nicola",male,,0,0,349255,7.8958,,C 154 | 1044,3,"Storey, Mr. Thomas",male,60.5,0,0,3701,,,S 155 | 1045,3,"Klasen, Mrs. (Hulda Kristina Eugenia Lofqvist)",female,36,0,2,350405,12.1833,,S 156 | 1046,3,"Asplund, Master. Filip Oscar",male,13,4,2,347077,31.3875,,S 157 | 1047,3,"Duquemin, Mr. Joseph",male,24,0,0,S.O./P.P. 752,7.55,,S 158 | 1048,1,"Bird, Miss. Ellen",female,29,0,0,PC 17483,221.7792,C97,S 159 | 1049,3,"Lundin, Miss. Olga Elida",female,23,0,0,347469,7.8542,,S 160 | 1050,1,"Borebank, Mr. John James",male,42,0,0,110489,26.55,D22,S 161 | 1051,3,"Peacock, Mrs. Benjamin (Edith Nile)",female,26,0,2,SOTON/O.Q. 3101315,13.775,,S 162 | 1052,3,"Smyth, Miss. Julia",female,,0,0,335432,7.7333,,Q 163 | 1053,3,"Touma, Master. Georges Youssef",male,7,1,1,2650,15.2458,,C 164 | 1054,2,"Wright, Miss. Marion",female,26,0,0,220844,13.5,,S 165 | 1055,3,"Pearce, Mr. Ernest",male,,0,0,343271,7,,S 166 | 1056,2,"Peruschitz, Rev. Joseph Maria",male,41,0,0,237393,13,,S 167 | 1057,3,"Kink-Heilmann, Mrs. Anton (Luise Heilmann)",female,26,1,1,315153,22.025,,S 168 | 1058,1,"Brandeis, Mr. Emil",male,48,0,0,PC 17591,50.4958,B10,C 169 | 1059,3,"Ford, Mr. Edward Watson",male,18,2,2,W./C. 6608,34.375,,S 170 | 1060,1,"Cassebeer, Mrs. Henry Arthur Jr (Eleanor Genevieve Fosdick)",female,,0,0,17770,27.7208,,C 171 | 1061,3,"Hellstrom, Miss. Hilda Maria",female,22,0,0,7548,8.9625,,S 172 | 1062,3,"Lithman, Mr. Simon",male,,0,0,S.O./P.P. 251,7.55,,S 173 | 1063,3,"Zakarian, Mr. Ortin",male,27,0,0,2670,7.225,,C 174 | 1064,3,"Dyker, Mr. Adolf Fredrik",male,23,1,0,347072,13.9,,S 175 | 1065,3,"Torfa, Mr. Assad",male,,0,0,2673,7.2292,,C 176 | 1066,3,"Asplund, Mr. Carl Oscar Vilhelm Gustafsson",male,40,1,5,347077,31.3875,,S 177 | 1067,2,"Brown, Miss. Edith Eileen",female,15,0,2,29750,39,,S 178 | 1068,2,"Sincock, Miss. Maude",female,20,0,0,C.A. 33112,36.75,,S 179 | 1069,1,"Stengel, Mr. Charles Emil Henry",male,54,1,0,11778,55.4417,C116,C 180 | 1070,2,"Becker, Mrs. Allen Oliver (Nellie E Baumgardner)",female,36,0,3,230136,39,F4,S 181 | 1071,1,"Compton, Mrs. Alexander Taylor (Mary Eliza Ingersoll)",female,64,0,2,PC 17756,83.1583,E45,C 182 | 1072,2,"McCrie, Mr. James Matthew",male,30,0,0,233478,13,,S 183 | 1073,1,"Compton, Mr. Alexander Taylor Jr",male,37,1,1,PC 17756,83.1583,E52,C 184 | 1074,1,"Marvin, Mrs. Daniel Warner (Mary Graham Carmichael Farquarson)",female,18,1,0,113773,53.1,D30,S 185 | 1075,3,"Lane, Mr. Patrick",male,,0,0,7935,7.75,,Q 186 | 1076,1,"Douglas, Mrs. Frederick Charles (Mary Helene Baxter)",female,27,1,1,PC 17558,247.5208,B58 B60,C 187 | 1077,2,"Maybery, Mr. Frank Hubert",male,40,0,0,239059,16,,S 188 | 1078,2,"Phillips, Miss. Alice Frances Louisa",female,21,0,1,S.O./P.P. 2,21,,S 189 | 1079,3,"Davies, Mr. Joseph",male,17,2,0,A/4 48873,8.05,,S 190 | 1080,3,"Sage, Miss. Ada",female,,8,2,CA. 2343,69.55,,S 191 | 1081,2,"Veal, Mr. James",male,40,0,0,28221,13,,S 192 | 1082,2,"Angle, Mr. William A",male,34,1,0,226875,26,,S 193 | 1083,1,"Salomon, Mr. Abraham L",male,,0,0,111163,26,,S 194 | 1084,3,"van Billiard, Master. Walter John",male,11.5,1,1,A/5. 851,14.5,,S 195 | 1085,2,"Lingane, Mr. John",male,61,0,0,235509,12.35,,Q 196 | 1086,2,"Drew, Master. Marshall Brines",male,8,0,2,28220,32.5,,S 197 | 1087,3,"Karlsson, Mr. Julius Konrad Eugen",male,33,0,0,347465,7.8542,,S 198 | 1088,1,"Spedden, Master. Robert Douglas",male,6,0,2,16966,134.5,E34,C 199 | 1089,3,"Nilsson, Miss. Berta Olivia",female,18,0,0,347066,7.775,,S 200 | 1090,2,"Baimbrigge, Mr. Charles Robert",male,23,0,0,C.A. 31030,10.5,,S 201 | 1091,3,"Rasmussen, Mrs. (Lena Jacobsen Solvang)",female,,0,0,65305,8.1125,,S 202 | 1092,3,"Murphy, Miss. Nora",female,,0,0,36568,15.5,,Q 203 | 1093,3,"Danbom, Master. Gilbert Sigvard Emanuel",male,0.33,0,2,347080,14.4,,S 204 | 1094,1,"Astor, Col. John Jacob",male,47,1,0,PC 17757,227.525,C62 C64,C 205 | 1095,2,"Quick, Miss. Winifred Vera",female,8,1,1,26360,26,,S 206 | 1096,2,"Andrew, Mr. Frank Thomas",male,25,0,0,C.A. 34050,10.5,,S 207 | 1097,1,"Omont, Mr. Alfred Fernand",male,,0,0,F.C. 12998,25.7417,,C 208 | 1098,3,"McGowan, Miss. Katherine",female,35,0,0,9232,7.75,,Q 209 | 1099,2,"Collett, Mr. Sidney C Stuart",male,24,0,0,28034,10.5,,S 210 | 1100,1,"Rosenbaum, Miss. Edith Louise",female,33,0,0,PC 17613,27.7208,A11,C 211 | 1101,3,"Delalic, Mr. Redjo",male,25,0,0,349250,7.8958,,S 212 | 1102,3,"Andersen, Mr. Albert Karvin",male,32,0,0,C 4001,22.525,,S 213 | 1103,3,"Finoli, Mr. Luigi",male,,0,0,SOTON/O.Q. 3101308,7.05,,S 214 | 1104,2,"Deacon, Mr. Percy William",male,17,0,0,S.O.C. 14879,73.5,,S 215 | 1105,2,"Howard, Mrs. Benjamin (Ellen Truelove Arman)",female,60,1,0,24065,26,,S 216 | 1106,3,"Andersson, Miss. Ida Augusta Margareta",female,38,4,2,347091,7.775,,S 217 | 1107,1,"Head, Mr. Christopher",male,42,0,0,113038,42.5,B11,S 218 | 1108,3,"Mahon, Miss. Bridget Delia",female,,0,0,330924,7.8792,,Q 219 | 1109,1,"Wick, Mr. George Dennick",male,57,1,1,36928,164.8667,,S 220 | 1110,1,"Widener, Mrs. George Dunton (Eleanor Elkins)",female,50,1,1,113503,211.5,C80,C 221 | 1111,3,"Thomson, Mr. Alexander Morrison",male,,0,0,32302,8.05,,S 222 | 1112,2,"Duran y More, Miss. Florentina",female,30,1,0,SC/PARIS 2148,13.8583,,C 223 | 1113,3,"Reynolds, Mr. Harold J",male,21,0,0,342684,8.05,,S 224 | 1114,2,"Cook, Mrs. (Selena Rogers)",female,22,0,0,W./C. 14266,10.5,F33,S 225 | 1115,3,"Karlsson, Mr. Einar Gervasius",male,21,0,0,350053,7.7958,,S 226 | 1116,1,"Candee, Mrs. Edward (Helen Churchill Hungerford)",female,53,0,0,PC 17606,27.4458,,C 227 | 1117,3,"Moubarek, Mrs. George (Omine Amenia"" Alexander)""",female,,0,2,2661,15.2458,,C 228 | 1118,3,"Asplund, Mr. Johan Charles",male,23,0,0,350054,7.7958,,S 229 | 1119,3,"McNeill, Miss. Bridget",female,,0,0,370368,7.75,,Q 230 | 1120,3,"Everett, Mr. Thomas James",male,40.5,0,0,C.A. 6212,15.1,,S 231 | 1121,2,"Hocking, Mr. Samuel James Metcalfe",male,36,0,0,242963,13,,S 232 | 1122,2,"Sweet, Mr. George Frederick",male,14,0,0,220845,65,,S 233 | 1123,1,"Willard, Miss. Constance",female,21,0,0,113795,26.55,,S 234 | 1124,3,"Wiklund, Mr. Karl Johan",male,21,1,0,3101266,6.4958,,S 235 | 1125,3,"Linehan, Mr. Michael",male,,0,0,330971,7.8792,,Q 236 | 1126,1,"Cumings, Mr. John Bradley",male,39,1,0,PC 17599,71.2833,C85,C 237 | 1127,3,"Vendel, Mr. Olof Edvin",male,20,0,0,350416,7.8542,,S 238 | 1128,1,"Warren, Mr. Frank Manley",male,64,1,0,110813,75.25,D37,C 239 | 1129,3,"Baccos, Mr. Raffull",male,20,0,0,2679,7.225,,C 240 | 1130,2,"Hiltunen, Miss. Marta",female,18,1,1,250650,13,,S 241 | 1131,1,"Douglas, Mrs. Walter Donald (Mahala Dutton)",female,48,1,0,PC 17761,106.425,C86,C 242 | 1132,1,"Lindstrom, Mrs. Carl Johan (Sigrid Posse)",female,55,0,0,112377,27.7208,,C 243 | 1133,2,"Christy, Mrs. (Alice Frances)",female,45,0,2,237789,30,,S 244 | 1134,1,"Spedden, Mr. Frederic Oakley",male,45,1,1,16966,134.5,E34,C 245 | 1135,3,"Hyman, Mr. Abraham",male,,0,0,3470,7.8875,,S 246 | 1136,3,"Johnston, Master. William Arthur Willie""""",male,,1,2,W./C. 6607,23.45,,S 247 | 1137,1,"Kenyon, Mr. Frederick R",male,41,1,0,17464,51.8625,D21,S 248 | 1138,2,"Karnes, Mrs. J Frank (Claire Bennett)",female,22,0,0,F.C.C. 13534,21,,S 249 | 1139,2,"Drew, Mr. James Vivian",male,42,1,1,28220,32.5,,S 250 | 1140,2,"Hold, Mrs. Stephen (Annie Margaret Hill)",female,29,1,0,26707,26,,S 251 | 1141,3,"Khalil, Mrs. Betros (Zahie Maria"" Elias)""",female,,1,0,2660,14.4542,,C 252 | 1142,2,"West, Miss. Barbara J",female,0.92,1,2,C.A. 34651,27.75,,S 253 | 1143,3,"Abrahamsson, Mr. Abraham August Johannes",male,20,0,0,SOTON/O2 3101284,7.925,,S 254 | 1144,1,"Clark, Mr. Walter Miller",male,27,1,0,13508,136.7792,C89,C 255 | 1145,3,"Salander, Mr. Karl Johan",male,24,0,0,7266,9.325,,S 256 | 1146,3,"Wenzel, Mr. Linhart",male,32.5,0,0,345775,9.5,,S 257 | 1147,3,"MacKay, Mr. George William",male,,0,0,C.A. 42795,7.55,,S 258 | 1148,3,"Mahon, Mr. John",male,,0,0,AQ/4 3130,7.75,,Q 259 | 1149,3,"Niklasson, Mr. Samuel",male,28,0,0,363611,8.05,,S 260 | 1150,2,"Bentham, Miss. Lilian W",female,19,0,0,28404,13,,S 261 | 1151,3,"Midtsjo, Mr. Karl Albert",male,21,0,0,345501,7.775,,S 262 | 1152,3,"de Messemaeker, Mr. Guillaume Joseph",male,36.5,1,0,345572,17.4,,S 263 | 1153,3,"Nilsson, Mr. August Ferdinand",male,21,0,0,350410,7.8542,,S 264 | 1154,2,"Wells, Mrs. Arthur Henry (Addie"" Dart Trevaskis)""",female,29,0,2,29103,23,,S 265 | 1155,3,"Klasen, Miss. Gertrud Emilia",female,1,1,1,350405,12.1833,,S 266 | 1156,2,"Portaluppi, Mr. Emilio Ilario Giuseppe",male,30,0,0,C.A. 34644,12.7375,,C 267 | 1157,3,"Lyntakoff, Mr. Stanko",male,,0,0,349235,7.8958,,S 268 | 1158,1,"Chisholm, Mr. Roderick Robert Crispin",male,,0,0,112051,0,,S 269 | 1159,3,"Warren, Mr. Charles William",male,,0,0,C.A. 49867,7.55,,S 270 | 1160,3,"Howard, Miss. May Elizabeth",female,,0,0,A. 2. 39186,8.05,,S 271 | 1161,3,"Pokrnic, Mr. Mate",male,17,0,0,315095,8.6625,,S 272 | 1162,1,"McCaffry, Mr. Thomas Francis",male,46,0,0,13050,75.2417,C6,C 273 | 1163,3,"Fox, Mr. Patrick",male,,0,0,368573,7.75,,Q 274 | 1164,1,"Clark, Mrs. Walter Miller (Virginia McDowell)",female,26,1,0,13508,136.7792,C89,C 275 | 1165,3,"Lennon, Miss. Mary",female,,1,0,370371,15.5,,Q 276 | 1166,3,"Saade, Mr. Jean Nassr",male,,0,0,2676,7.225,,C 277 | 1167,2,"Bryhl, Miss. Dagmar Jenny Ingeborg ",female,20,1,0,236853,26,,S 278 | 1168,2,"Parker, Mr. Clifford Richard",male,28,0,0,SC 14888,10.5,,S 279 | 1169,2,"Faunthorpe, Mr. Harry",male,40,1,0,2926,26,,S 280 | 1170,2,"Ware, Mr. John James",male,30,1,0,CA 31352,21,,S 281 | 1171,2,"Oxenham, Mr. Percy Thomas",male,22,0,0,W./C. 14260,10.5,,S 282 | 1172,3,"Oreskovic, Miss. Jelka",female,23,0,0,315085,8.6625,,S 283 | 1173,3,"Peacock, Master. Alfred Edward",male,0.75,1,1,SOTON/O.Q. 3101315,13.775,,S 284 | 1174,3,"Fleming, Miss. Honora",female,,0,0,364859,7.75,,Q 285 | 1175,3,"Touma, Miss. Maria Youssef",female,9,1,1,2650,15.2458,,C 286 | 1176,3,"Rosblom, Miss. Salli Helena",female,2,1,1,370129,20.2125,,S 287 | 1177,3,"Dennis, Mr. William",male,36,0,0,A/5 21175,7.25,,S 288 | 1178,3,"Franklin, Mr. Charles (Charles Fardon)",male,,0,0,SOTON/O.Q. 3101314,7.25,,S 289 | 1179,1,"Snyder, Mr. John Pillsbury",male,24,1,0,21228,82.2667,B45,S 290 | 1180,3,"Mardirosian, Mr. Sarkis",male,,0,0,2655,7.2292,F E46,C 291 | 1181,3,"Ford, Mr. Arthur",male,,0,0,A/5 1478,8.05,,S 292 | 1182,1,"Rheims, Mr. George Alexander Lucien",male,,0,0,PC 17607,39.6,,S 293 | 1183,3,"Daly, Miss. Margaret Marcella Maggie""""",female,30,0,0,382650,6.95,,Q 294 | 1184,3,"Nasr, Mr. Mustafa",male,,0,0,2652,7.2292,,C 295 | 1185,1,"Dodge, Dr. Washington",male,53,1,1,33638,81.8583,A34,S 296 | 1186,3,"Wittevrongel, Mr. Camille",male,36,0,0,345771,9.5,,S 297 | 1187,3,"Angheloff, Mr. Minko",male,26,0,0,349202,7.8958,,S 298 | 1188,2,"Laroche, Miss. Louise",female,1,1,2,SC/Paris 2123,41.5792,,C 299 | 1189,3,"Samaan, Mr. Hanna",male,,2,0,2662,21.6792,,C 300 | 1190,1,"Loring, Mr. Joseph Holland",male,30,0,0,113801,45.5,,S 301 | 1191,3,"Johansson, Mr. Nils",male,29,0,0,347467,7.8542,,S 302 | 1192,3,"Olsson, Mr. Oscar Wilhelm",male,32,0,0,347079,7.775,,S 303 | 1193,2,"Malachard, Mr. Noel",male,,0,0,237735,15.0458,D,C 304 | 1194,2,"Phillips, Mr. Escott Robert",male,43,0,1,S.O./P.P. 2,21,,S 305 | 1195,3,"Pokrnic, Mr. Tome",male,24,0,0,315092,8.6625,,S 306 | 1196,3,"McCarthy, Miss. Catherine Katie""""",female,,0,0,383123,7.75,,Q 307 | 1197,1,"Crosby, Mrs. Edward Gifford (Catherine Elizabeth Halstead)",female,64,1,1,112901,26.55,B26,S 308 | 1198,1,"Allison, Mr. Hudson Joshua Creighton",male,30,1,2,113781,151.55,C22 C26,S 309 | 1199,3,"Aks, Master. Philip Frank",male,0.83,0,1,392091,9.35,,S 310 | 1200,1,"Hays, Mr. Charles Melville",male,55,1,1,12749,93.5,B69,S 311 | 1201,3,"Hansen, Mrs. Claus Peter (Jennie L Howard)",female,45,1,0,350026,14.1083,,S 312 | 1202,3,"Cacic, Mr. Jego Grga",male,18,0,0,315091,8.6625,,S 313 | 1203,3,"Vartanian, Mr. David",male,22,0,0,2658,7.225,,C 314 | 1204,3,"Sadowitz, Mr. Harry",male,,0,0,LP 1588,7.575,,S 315 | 1205,3,"Carr, Miss. Jeannie",female,37,0,0,368364,7.75,,Q 316 | 1206,1,"White, Mrs. John Stuart (Ella Holmes)",female,55,0,0,PC 17760,135.6333,C32,C 317 | 1207,3,"Hagardon, Miss. Kate",female,17,0,0,AQ/3. 30631,7.7333,,Q 318 | 1208,1,"Spencer, Mr. William Augustus",male,57,1,0,PC 17569,146.5208,B78,C 319 | 1209,2,"Rogers, Mr. Reginald Harry",male,19,0,0,28004,10.5,,S 320 | 1210,3,"Jonsson, Mr. Nils Hilding",male,27,0,0,350408,7.8542,,S 321 | 1211,2,"Jefferys, Mr. Ernest Wilfred",male,22,2,0,C.A. 31029,31.5,,S 322 | 1212,3,"Andersson, Mr. Johan Samuel",male,26,0,0,347075,7.775,,S 323 | 1213,3,"Krekorian, Mr. Neshan",male,25,0,0,2654,7.2292,F E57,C 324 | 1214,2,"Nesson, Mr. Israel",male,26,0,0,244368,13,F2,S 325 | 1215,1,"Rowe, Mr. Alfred G",male,33,0,0,113790,26.55,,S 326 | 1216,1,"Kreuchen, Miss. Emilie",female,39,0,0,24160,211.3375,,S 327 | 1217,3,"Assam, Mr. Ali",male,23,0,0,SOTON/O.Q. 3101309,7.05,,S 328 | 1218,2,"Becker, Miss. Ruth Elizabeth",female,12,2,1,230136,39,F4,S 329 | 1219,1,"Rosenshine, Mr. George (Mr George Thorne"")""",male,46,0,0,PC 17585,79.2,,C 330 | 1220,2,"Clarke, Mr. Charles Valentine",male,29,1,0,2003,26,,S 331 | 1221,2,"Enander, Mr. Ingvar",male,21,0,0,236854,13,,S 332 | 1222,2,"Davies, Mrs. John Morgan (Elizabeth Agnes Mary White) ",female,48,0,2,C.A. 33112,36.75,,S 333 | 1223,1,"Dulles, Mr. William Crothers",male,39,0,0,PC 17580,29.7,A18,C 334 | 1224,3,"Thomas, Mr. Tannous",male,,0,0,2684,7.225,,C 335 | 1225,3,"Nakid, Mrs. Said (Waika Mary"" Mowad)""",female,19,1,1,2653,15.7417,,C 336 | 1226,3,"Cor, Mr. Ivan",male,27,0,0,349229,7.8958,,S 337 | 1227,1,"Maguire, Mr. John Edward",male,30,0,0,110469,26,C106,S 338 | 1228,2,"de Brito, Mr. Jose Joaquim",male,32,0,0,244360,13,,S 339 | 1229,3,"Elias, Mr. Joseph",male,39,0,2,2675,7.2292,,C 340 | 1230,2,"Denbury, Mr. Herbert",male,25,0,0,C.A. 31029,31.5,,S 341 | 1231,3,"Betros, Master. Seman",male,,0,0,2622,7.2292,,C 342 | 1232,2,"Fillbrook, Mr. Joseph Charles",male,18,0,0,C.A. 15185,10.5,,S 343 | 1233,3,"Lundstrom, Mr. Thure Edvin",male,32,0,0,350403,7.5792,,S 344 | 1234,3,"Sage, Mr. John George",male,,1,9,CA. 2343,69.55,,S 345 | 1235,1,"Cardeza, Mrs. James Warburton Martinez (Charlotte Wardle Drake)",female,58,0,1,PC 17755,512.3292,B51 B53 B55,C 346 | 1236,3,"van Billiard, Master. James William",male,,1,1,A/5. 851,14.5,,S 347 | 1237,3,"Abelseth, Miss. Karen Marie",female,16,0,0,348125,7.65,,S 348 | 1238,2,"Botsford, Mr. William Hull",male,26,0,0,237670,13,,S 349 | 1239,3,"Whabee, Mrs. George Joseph (Shawneene Abi-Saab)",female,38,0,0,2688,7.2292,,C 350 | 1240,2,"Giles, Mr. Ralph",male,24,0,0,248726,13.5,,S 351 | 1241,2,"Walcroft, Miss. Nellie",female,31,0,0,F.C.C. 13528,21,,S 352 | 1242,1,"Greenfield, Mrs. Leo David (Blanche Strouse)",female,45,0,1,PC 17759,63.3583,D10 D12,C 353 | 1243,2,"Stokes, Mr. Philip Joseph",male,25,0,0,F.C.C. 13540,10.5,,S 354 | 1244,2,"Dibden, Mr. William",male,18,0,0,S.O.C. 14879,73.5,,S 355 | 1245,2,"Herman, Mr. Samuel",male,49,1,2,220845,65,,S 356 | 1246,3,"Dean, Miss. Elizabeth Gladys Millvina""""",female,0.17,1,2,C.A. 2315,20.575,,S 357 | 1247,1,"Julian, Mr. Henry Forbes",male,50,0,0,113044,26,E60,S 358 | 1248,1,"Brown, Mrs. John Murray (Caroline Lane Lamson)",female,59,2,0,11769,51.4792,C101,S 359 | 1249,3,"Lockyer, Mr. Edward",male,,0,0,1222,7.8792,,S 360 | 1250,3,"O'Keefe, Mr. Patrick",male,,0,0,368402,7.75,,Q 361 | 1251,3,"Lindell, Mrs. Edvard Bengtsson (Elin Gerda Persson)",female,30,1,0,349910,15.55,,S 362 | 1252,3,"Sage, Master. William Henry",male,14.5,8,2,CA. 2343,69.55,,S 363 | 1253,2,"Mallet, Mrs. Albert (Antoinette Magnin)",female,24,1,1,S.C./PARIS 2079,37.0042,,C 364 | 1254,2,"Ware, Mrs. John James (Florence Louise Long)",female,31,0,0,CA 31352,21,,S 365 | 1255,3,"Strilic, Mr. Ivan",male,27,0,0,315083,8.6625,,S 366 | 1256,1,"Harder, Mrs. George Achilles (Dorothy Annan)",female,25,1,0,11765,55.4417,E50,C 367 | 1257,3,"Sage, Mrs. John (Annie Bullen)",female,,1,9,CA. 2343,69.55,,S 368 | 1258,3,"Caram, Mr. Joseph",male,,1,0,2689,14.4583,,C 369 | 1259,3,"Riihivouri, Miss. Susanna Juhantytar Sanni""""",female,22,0,0,3101295,39.6875,,S 370 | 1260,1,"Gibson, Mrs. Leonard (Pauline C Boeson)",female,45,0,1,112378,59.4,,C 371 | 1261,2,"Pallas y Castello, Mr. Emilio",male,29,0,0,SC/PARIS 2147,13.8583,,C 372 | 1262,2,"Giles, Mr. Edgar",male,21,1,0,28133,11.5,,S 373 | 1263,1,"Wilson, Miss. Helen Alice",female,31,0,0,16966,134.5,E39 E41,C 374 | 1264,1,"Ismay, Mr. Joseph Bruce",male,49,0,0,112058,0,B52 B54 B56,S 375 | 1265,2,"Harbeck, Mr. William H",male,44,0,0,248746,13,,S 376 | 1266,1,"Dodge, Mrs. Washington (Ruth Vidaver)",female,54,1,1,33638,81.8583,A34,S 377 | 1267,1,"Bowen, Miss. Grace Scott",female,45,0,0,PC 17608,262.375,,C 378 | 1268,3,"Kink, Miss. Maria",female,22,2,0,315152,8.6625,,S 379 | 1269,2,"Cotterill, Mr. Henry Harry""""",male,21,0,0,29107,11.5,,S 380 | 1270,1,"Hipkins, Mr. William Edward",male,55,0,0,680,50,C39,S 381 | 1271,3,"Asplund, Master. Carl Edgar",male,5,4,2,347077,31.3875,,S 382 | 1272,3,"O'Connor, Mr. Patrick",male,,0,0,366713,7.75,,Q 383 | 1273,3,"Foley, Mr. Joseph",male,26,0,0,330910,7.8792,,Q 384 | 1274,3,"Risien, Mrs. Samuel (Emma)",female,,0,0,364498,14.5,,S 385 | 1275,3,"McNamee, Mrs. Neal (Eileen O'Leary)",female,19,1,0,376566,16.1,,S 386 | 1276,2,"Wheeler, Mr. Edwin Frederick""""",male,,0,0,SC/PARIS 2159,12.875,,S 387 | 1277,2,"Herman, Miss. Kate",female,24,1,2,220845,65,,S 388 | 1278,3,"Aronsson, Mr. Ernst Axel Algot",male,24,0,0,349911,7.775,,S 389 | 1279,2,"Ashby, Mr. John",male,57,0,0,244346,13,,S 390 | 1280,3,"Canavan, Mr. Patrick",male,21,0,0,364858,7.75,,Q 391 | 1281,3,"Palsson, Master. Paul Folke",male,6,3,1,349909,21.075,,S 392 | 1282,1,"Payne, Mr. Vivian Ponsonby",male,23,0,0,12749,93.5,B24,S 393 | 1283,1,"Lines, Mrs. Ernest H (Elizabeth Lindsey James)",female,51,0,1,PC 17592,39.4,D28,S 394 | 1284,3,"Abbott, Master. Eugene Joseph",male,13,0,2,C.A. 2673,20.25,,S 395 | 1285,2,"Gilbert, Mr. William",male,47,0,0,C.A. 30769,10.5,,S 396 | 1286,3,"Kink-Heilmann, Mr. Anton",male,29,3,1,315153,22.025,,S 397 | 1287,1,"Smith, Mrs. Lucien Philip (Mary Eloise Hughes)",female,18,1,0,13695,60,C31,S 398 | 1288,3,"Colbert, Mr. Patrick",male,24,0,0,371109,7.25,,Q 399 | 1289,1,"Frolicher-Stehli, Mrs. Maxmillian (Margaretha Emerentia Stehli)",female,48,1,1,13567,79.2,B41,C 400 | 1290,3,"Larsson-Rondberg, Mr. Edvard A",male,22,0,0,347065,7.775,,S 401 | 1291,3,"Conlon, Mr. Thomas Henry",male,31,0,0,21332,7.7333,,Q 402 | 1292,1,"Bonnell, Miss. Caroline",female,30,0,0,36928,164.8667,C7,S 403 | 1293,2,"Gale, Mr. Harry",male,38,1,0,28664,21,,S 404 | 1294,1,"Gibson, Miss. Dorothy Winifred",female,22,0,1,112378,59.4,,C 405 | 1295,1,"Carrau, Mr. Jose Pedro",male,17,0,0,113059,47.1,,S 406 | 1296,1,"Frauenthal, Mr. Isaac Gerald",male,43,1,0,17765,27.7208,D40,C 407 | 1297,2,"Nourney, Mr. Alfred (Baron von Drachstedt"")""",male,20,0,0,SC/PARIS 2166,13.8625,D38,C 408 | 1298,2,"Ware, Mr. William Jeffery",male,23,1,0,28666,10.5,,S 409 | 1299,1,"Widener, Mr. George Dunton",male,50,1,1,113503,211.5,C80,C 410 | 1300,3,"Riordan, Miss. Johanna Hannah""""",female,,0,0,334915,7.7208,,Q 411 | 1301,3,"Peacock, Miss. Treasteall",female,3,1,1,SOTON/O.Q. 3101315,13.775,,S 412 | 1302,3,"Naughton, Miss. Hannah",female,,0,0,365237,7.75,,Q 413 | 1303,1,"Minahan, Mrs. William Edward (Lillian E Thorpe)",female,37,1,0,19928,90,C78,Q 414 | 1304,3,"Henriksson, Miss. Jenny Lovisa",female,28,0,0,347086,7.775,,S 415 | 1305,3,"Spector, Mr. Woolf",male,,0,0,A.5. 3236,8.05,,S 416 | 1306,1,"Oliva y Ocana, Dona. Fermina",female,39,0,0,PC 17758,108.9,C105,C 417 | 1307,3,"Saether, Mr. Simon Sivertsen",male,38.5,0,0,SOTON/O.Q. 3101262,7.25,,S 418 | 1308,3,"Ware, Mr. Frederick",male,,0,0,359309,8.05,,S 419 | 1309,3,"Peter, Master. Michael J",male,,1,1,2668,22.3583,,C 420 | -------------------------------------------------------------------------------- /docker/.env: -------------------------------------------------------------------------------- 1 | COMPOSE_PROJECT_NAME=handson-ml 2 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM continuumio/anaconda3 2 | 3 | RUN apt-get update && apt-get upgrade -y \ 4 | && apt-get install -y \ 5 | libpq-dev \ 6 | build-essential \ 7 | git \ 8 | sudo \ 9 | cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev libboost-all-dev libsdl2-dev swig \ 10 | && rm -rf /var/lib/apt/lists/* 11 | 12 | RUN conda update -n base conda 13 | RUN conda install -y -c conda-forge \ 14 | tensorflow \ 15 | jupyter_contrib_nbextensions \ 16 | pyopengl 17 | RUN pip install "gym[atari,box2d,classic_control]" 18 | 19 | ARG username 20 | ARG userid 21 | 22 | ARG home=/home/${username} 23 | ARG workdir=${home}/handson-ml 24 | 25 | RUN adduser ${username} --uid ${userid} --gecos '' --disabled-password \ 26 | && echo "${username} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${username} \ 27 | && chmod 0440 /etc/sudoers.d/${username} 28 | 29 | WORKDIR ${workdir} 30 | RUN chown ${username}:${username} ${workdir} 31 | 32 | USER ${username} 33 | 34 | RUN jupyter contrib nbextension install --user 35 | RUN jupyter nbextension enable toc2/main 36 | 37 | 38 | # INFO: Jupyter and nbdime extension are not totally integrated (anaconda image is py36, 39 | # nbdime checks for py35 at the moment, still the config below enables diffing 40 | # notebooks with nbdiff (and nbdiff support in git diff command) after connecting 41 | # to the container by "make exec" (or "docker-compose exec handson-ml bash") 42 | # You may also try running: 43 | # nbd NOTEBOOK_NAME.ipynb 44 | # to get nbdiff between checkpointed version and current version of the given notebook 45 | USER root 46 | WORKDIR / 47 | RUN conda install -y -c conda-forge nbdime 48 | USER ${username} 49 | WORKDIR ${workdir} 50 | 51 | RUN git-nbdiffdriver config --enable --global 52 | 53 | # INFO: Optionally uncomment any (one) of the following RUN commands below to ignore either 54 | # metadata or details in nbdiff within git diff 55 | #RUN git config --global diff.jupyternotebook.command 'git-nbdiffdriver diff --ignore-metadata' 56 | RUN git config --global diff.jupyternotebook.command 'git-nbdiffdriver diff --ignore-details' 57 | 58 | 59 | # INFO: Dirty nbdime patching (ignored if not matching) 60 | COPY docker/nbdime-*.patch /tmp/ 61 | USER root 62 | WORKDIR / 63 | RUN patch -d /opt/conda/lib/python3.6/site-packages -p1 --forward --reject-file=- < \ 64 | /tmp/nbdime-1-details.patch || true \ 65 | && patch -d /opt/conda/lib/python3.6/site-packages -p1 --forward --reject-file=- < \ 66 | /tmp/nbdime-2-toc.patch || true 67 | RUN rm /tmp/nbdime-*.patch 68 | USER ${username} 69 | WORKDIR ${workdir} 70 | 71 | 72 | COPY docker/bashrc.bash /tmp/ 73 | RUN cat /tmp/bashrc.bash >> ${home}/.bashrc 74 | RUN echo "export PATH=\"${workdir}/docker/bin:$PATH\"" >> ${home}/.bashrc 75 | RUN sudo rm /tmp/bashrc.bash 76 | 77 | 78 | # INFO: Uncomment lines below to enable automatic save of python-only and html-only 79 | # exports alongside the notebook 80 | #COPY docker/jupyter_notebook_config.py /tmp/ 81 | #RUN cat /tmp/jupyter_notebook_config.py >> ${home}/.jupyter/jupyter_notebook_config.py 82 | #RUN sudo rm /tmp/jupyter_notebook_config.py 83 | 84 | # INFO: Uncomment the RUN command below to disable git diff paging 85 | #RUN git config --global core.pager '' 86 | 87 | # INFO: Uncomment the RUN command below for easy and constant notebook URL (just localhost:8888) 88 | # That will switch jupyter to using empty password instead of a token. 89 | # To avoid making a security hole you SHOULD in fact not only uncomment but 90 | # regenerate the hash for your own non-empty password and replace the hash below. 91 | # You can compute a password hash in any notebook, just run the code: 92 | # from notebook.auth import passwd 93 | # passwd() 94 | # and take the hash from the output 95 | #RUN mkdir -p ${home}/.jupyter && \ 96 | # echo 'c.NotebookApp.password = u"sha1:c6bbcba2d04b:f969e403db876dcfbe26f47affe41909bd53392e"' \ 97 | # >> ${home}/.jupyter/jupyter_notebook_config.py 98 | -------------------------------------------------------------------------------- /docker/Makefile: -------------------------------------------------------------------------------- 1 | 2 | help: 3 | cat Makefile 4 | run: 5 | docker-compose up 6 | exec: 7 | docker-compose exec handson-ml bash 8 | build: stop .FORCE 9 | docker-compose build 10 | rebuild: stop .FORCE 11 | docker-compose build --force-rm 12 | stop: 13 | docker stop handson-ml || true; docker rm handson-ml || true; 14 | .FORCE: 15 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Hands-on Machine Learning in Docker 3 | 4 | This is the Docker configuration which allows you to run and tweak the book's notebooks without installing any dependencies on your machine!
5 | OK, any except `docker`. With `docker-compose`. Well, you may also want `make` (but it is only used as thin layer to call a few simple `docker-compose` commands). 6 | 7 | ## Prerequisites 8 | 9 | As stated, the two things you need is `docker` and `docker-compose`. 10 | 11 | Follow the instructions on [Install Docker](https://docs.docker.com/engine/installation/) and [Install Docker Compose](https://docs.docker.com/compose/install/) for your environment if you haven't got `docker` already. 12 | 13 | Some general knowledge about `docker` infrastructure might be useful (that's an interesting topic on its own) but is not strictly *required* to just run the notebooks. 14 | 15 | ## Usage 16 | 17 | ### Prepare the image (once) 18 | 19 | Switch to `docker` directory here and run `make build` (or `docker-compose build`) to build your docker image. That may take some time but is only required once. Or perhaps a few times after you tweak something in a `Dockerfile`. 20 | 21 | After the process is finished you have a `handson-ml` image, that will be the base for your experiments. You can confirm that looking on results of `docker images` command. 22 | 23 | ### Run the notebooks 24 | 25 | Run `make run` (or just `docker-compose up`) to start the jupyter server inside the container (also named `handson-ml`, same as image). Just point your browser to the URL printed on the screen (or just if you enabled password authentication) and you're ready to play with the book's code! 26 | 27 | The server runs in the directory containing the notebooks, and the changes you make from the browser will be persisted there. 28 | 29 | You can close the server just by pressing `Ctrl-C` in terminal window. 30 | 31 | ### Run additional commands in container 32 | 33 | Run `make exec` (or `docker-compose exec handson-ml bash`) while the server is running to run an additional `bash` shell inside the `handson-ml` container. Now you're inside the environment prepared within the image. 34 | 35 | One of the usefull things that can be done there would be starting TensorBoard (for example with simple `tb` command, see bashrc file). 36 | 37 | Another one may be comparing versions of the notebooks using the `nbdiff` command if you haven't got `nbdime` installed locally (it is **way** better than plain `diff` for notebooks). See [Tools for diffing and merging of Jupyter notebooks](https://github.com/jupyter/nbdime) for more details. 38 | 39 | You can see changes you made relative to the version in git using `git diff` which is integrated with `nbdiff`. 40 | 41 | You may also try `nbd NOTEBOOK_NAME.ipynb` command (custom, see bashrc file) to compare one of your notebooks with its `checkpointed` version.
42 | To be precise, the output will tell you *what modifications should be re-played on the **manually saved** version of the notebook (located in `.ipynb_checkpoints` subdirectory) to update it to the **current** i.e. **auto-saved** version (given as command's argument - located in working directory)*. 43 | -------------------------------------------------------------------------------- /docker/bashrc.bash: -------------------------------------------------------------------------------- 1 | alias ll="ls -alF" 2 | alias nbd="nbdiff_checkpoint" 3 | alias tb="tensorboard --logdir=tf_logs" 4 | -------------------------------------------------------------------------------- /docker/bin/nbclean_checkpoints: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import collections 4 | import glob 5 | import hashlib 6 | import os 7 | import subprocess 8 | 9 | 10 | class NotebookAnalyser: 11 | 12 | def __init__(self, dry_run=False, verbose=False, colorful=False): 13 | self._dry_run = dry_run 14 | self._verbose = verbose 15 | self._colors = collections.defaultdict(lambda: "") 16 | if colorful: 17 | for color in [ 18 | NotebookAnalyser.COLOR_WHITE, 19 | NotebookAnalyser.COLOR_RED, 20 | NotebookAnalyser.COLOR_GREEN, 21 | NotebookAnalyser.COLOR_YELLOW, 22 | ]: 23 | self._colors[color] = "\033[{}m".format(color) 24 | 25 | NOTEBOOK_SUFFIX = ".ipynb" 26 | CHECKPOINT_DIR = NOTEBOOK_SUFFIX + "_checkpoints" 27 | CHECKPOINT_MASK = "*-checkpoint" + NOTEBOOK_SUFFIX 28 | CHECKPOINT_MASK_LEN = len(CHECKPOINT_MASK) - 1 29 | 30 | @staticmethod 31 | def get_hash(file_path): 32 | with open(file_path, "rb") as input: 33 | hash = hashlib.md5() 34 | for chunk in iter(lambda: input.read(4096), b""): 35 | hash.update(chunk) 36 | return hash.hexdigest() 37 | 38 | MESSAGE_ORPHANED = "missing " 39 | MESSAGE_MODIFIED = "modified" 40 | MESSAGE_DELETED = "DELETING" 41 | 42 | COLOR_WHITE = "0" 43 | COLOR_RED = "31" 44 | COLOR_GREEN = "32" 45 | COLOR_YELLOW = "33" 46 | 47 | def log(self, message, file, color=COLOR_WHITE): 48 | color_on = self._colors[color] 49 | color_off = self._colors[NotebookAnalyser.COLOR_WHITE] 50 | print("{}{}{}: {}".format(color_on, message, color_off, file)) 51 | 52 | def clean_checkpoints(self, directory): 53 | for checkpoint_path in sorted(glob.glob(os.path.join(directory, NotebookAnalyser.CHECKPOINT_MASK))): 54 | 55 | workfile_dir = os.path.dirname(os.path.dirname(checkpoint_path)) 56 | workfile_name = os.path.basename(checkpoint_path)[:-NotebookAnalyser.CHECKPOINT_MASK_LEN] + NotebookAnalyser.NOTEBOOK_SUFFIX 57 | workfile_path = os.path.join(workfile_dir, workfile_name) 58 | 59 | status = "" 60 | if not os.path.isfile(workfile_path): 61 | if self._verbose: 62 | self.log(NotebookAnalyser.MESSAGE_ORPHANED, workfile_path, NotebookAnalyser.COLOR_RED) 63 | else: 64 | checkpoint_stat = os.stat(checkpoint_path) 65 | workfile_stat = os.stat(workfile_path) 66 | 67 | modified = workfile_stat.st_size != checkpoint_stat.st_size 68 | 69 | if not modified: 70 | checkpoint_hash = NotebookAnalyser.get_hash(checkpoint_path) 71 | workfile_hash = NotebookAnalyser.get_hash(workfile_path) 72 | modified = checkpoint_hash != workfile_hash 73 | 74 | if modified: 75 | if self._verbose: 76 | self.log(NotebookAnalyser.MESSAGE_MODIFIED, workfile_path, NotebookAnalyser.COLOR_YELLOW) 77 | else: 78 | self.log(NotebookAnalyser.MESSAGE_DELETED, checkpoint_path, NotebookAnalyser.COLOR_GREEN) 79 | if not self._dry_run: 80 | os.remove(checkpoint_path) 81 | 82 | if not self._dry_run and not os.listdir(directory): 83 | self.log(NotebookAnalyser.MESSAGE_DELETED, directory, NotebookAnalyser.COLOR_GREEN) 84 | os.rmdir(directory) 85 | 86 | def clean_checkpoints_recursively(self, directory): 87 | for (root, subdirs, files) in os.walk(directory): 88 | subdirs.sort() # INFO: traverse alphabetically 89 | if NotebookAnalyser.CHECKPOINT_DIR in subdirs: 90 | subdirs.remove(NotebookAnalyser.CHECKPOINT_DIR) # INFO: don't recurse there 91 | self.clean_checkpoints(os.path.join(root, NotebookAnalyser.CHECKPOINT_DIR)) 92 | 93 | 94 | def main(): 95 | import argparse 96 | parser = argparse.ArgumentParser(description="Remove checkpointed versions of those jupyter notebooks that are identical to their working copies.", 97 | epilog="""Notebooks will be reported as either 98 | "DELETED" if the working copy and checkpointed version are identical 99 | (checkpoint will be deleted), 100 | "missing" if there is a checkpoint but no corresponding working file can be found 101 | or "modified" if notebook and the checkpoint are not byte-to-byte identical. 102 | If removal of checkpoints results in empty ".ipynb_checkpoints" directory 103 | that directory is also deleted. 104 | """) #, formatter_class=argparse.RawDescriptionHelpFormatter) 105 | parser.add_argument("dirs", metavar="DIR", type=str, nargs="*", default=".", help="directories to search") 106 | parser.add_argument("-d", "--dry-run", action="store_true", help="only print messages, don't perform any removals") 107 | parser.add_argument("-v", "--verbose", action="store_true", help="verbose mode") 108 | parser.add_argument("-c", "--color", action="store_true", help="colorful mode") 109 | args = parser.parse_args() 110 | 111 | analyser = NotebookAnalyser(args.dry_run, args.verbose, args.color) 112 | for directory in args.dirs: 113 | analyser.clean_checkpoints_recursively(directory) 114 | 115 | if __name__ == "__main__": 116 | main() 117 | -------------------------------------------------------------------------------- /docker/bin/nbdiff_checkpoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ "$#" -lt 1 || "$1" =~ ^((-h)|(--help))$ ]] ; then 3 | echo "usage: nbdiff_checkpoint NOTEBOOK.ipynb" 4 | echo 5 | echo "Show differences between given jupyter notebook and its checkpointed version (in .ipynb_checkpoints subdirectory)" 6 | exit 7 | fi 8 | 9 | DIRNAME=$(dirname "$1") 10 | BASENAME=$(basename "$1" .ipynb) 11 | shift 12 | 13 | WORKING_COPY=$DIRNAME/$BASENAME.ipynb 14 | CHECKPOINT_COPY=$DIRNAME/.ipynb_checkpoints/$BASENAME-checkpoint.ipynb 15 | 16 | echo "----- Analysing how to change $CHECKPOINT_COPY into $WORKING_COPY -----" 17 | nbdiff "$CHECKPOINT_COPY" "$WORKING_COPY" --ignore-details "$@" 18 | -------------------------------------------------------------------------------- /docker/bin/rm_empty_subdirs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | 5 | def remove_empty_directories(initial_dir, 6 | allow_initial_delete=False, ignore_nonexistant_initial=False, 7 | dry_run=False, quiet=False): 8 | 9 | FORBIDDEN_SUBDIRS = set([".git"]) 10 | 11 | if not os.path.isdir(initial_dir) and not ignore_nonexistant_initial: 12 | raise RuntimeError("Initial directory '{}' not found!".format(initial_dir)) 13 | 14 | message = "removed" 15 | if dry_run: 16 | message = "to be " + message 17 | 18 | deleted = set() 19 | 20 | for (directory, subdirs, files) in os.walk(initial_dir, topdown=False): 21 | forbidden = False 22 | parent = directory 23 | while parent: 24 | parent, dirname = os.path.split(parent) 25 | if dirname in FORBIDDEN_SUBDIRS: 26 | forbidden = True 27 | break 28 | if forbidden: 29 | continue 30 | 31 | is_empty = len(files) < 1 and len(set([os.path.join(directory, s) for s in subdirs]) - deleted) < 1 32 | 33 | if is_empty and (initial_dir != directory or allow_initial_delete): 34 | if not quiet: 35 | print("{}: {}".format(message, directory)) 36 | deleted.add(directory) 37 | if not dry_run: 38 | os.rmdir(directory) 39 | 40 | def main(): 41 | import argparse 42 | parser = argparse.ArgumentParser(description="Remove empty directories recursively in subtree.") 43 | parser.add_argument("dir", metavar="DIR", type=str, nargs="+", help="directory to be searched") 44 | parser.add_argument("-r", "--allow-dir-removal", action="store_true", help="allow deletion of DIR itself") 45 | parser.add_argument("-i", "--ignore-nonexistent-dir", action="store_true", help="don't throw an error if DIR doesn't exist") 46 | parser.add_argument("-d", "--dry-run", action="store_true", help="only print messages, don't perform any removals") 47 | parser.add_argument("-q", "--quiet", action="store_true", help="don't print names of directories being removed") 48 | args = parser.parse_args() 49 | for directory in args.dir: 50 | remove_empty_directories(directory, args.allow_dir_removal, args.ignore_nonexistent_dir, 51 | args.dry_run, args.quiet) 52 | 53 | if __name__ == "__main__": 54 | main() 55 | -------------------------------------------------------------------------------- /docker/bin/tensorboard: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python -m tensorboard.main "$@" 3 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | handson-ml: 4 | build: 5 | context: ../ 6 | dockerfile: ./docker/Dockerfile 7 | args: 8 | - username=devel 9 | - userid=1000 10 | container_name: handson-ml 11 | image: handson-ml 12 | logging: 13 | driver: json-file 14 | options: 15 | max-size: 50m 16 | ports: 17 | - "8888:8888" 18 | - "6006:6006" 19 | volumes: 20 | - ../:/home/devel/handson-ml 21 | command: /opt/conda/bin/jupyter notebook --ip='*' --port=8888 --no-browser 22 | -------------------------------------------------------------------------------- /docker/jupyter_notebook_config.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | def export_script_and_view(model, os_path, contents_manager): 5 | if model["type"] != "notebook": 6 | return 7 | dir_name, file_name = os.path.split(os_path) 8 | file_base, file_ext = os.path.splitext(file_name) 9 | if file_base.startswith("Untitled"): 10 | return 11 | export_name = file_base if file_ext == ".ipynb" else file_name 12 | subprocess.check_call(["jupyter", "nbconvert", "--to", "script", file_name, "--output", export_name + "_script"], cwd=dir_name) 13 | subprocess.check_call(["jupyter", "nbconvert", "--to", "html", file_name, "--output", export_name + "_view"], cwd=dir_name) 14 | 15 | c.FileContentsManager.post_save_hook = export_script_and_view 16 | -------------------------------------------------------------------------------- /docker/nbdime-1-details.patch: -------------------------------------------------------------------------------- 1 | --- a/nbdime/diffing/notebooks.py 2 | +++ b/nbdime/diffing/notebooks.py 3 | @@ -548,8 +548,12 @@ def set_notebook_diff_targets(sources=True, outputs=True, attachments=True, meta 4 | metadata_keys = ("/cells/*/metadata", "/metadata", "/cells/*/outputs/*/metadata") 5 | if metadata: 6 | for key in metadata_keys: 7 | - if key in notebook_differs: 8 | - del notebook_differs[key] 9 | + if details: 10 | + if key in notebook_differs: 11 | + del notebook_differs[key] 12 | + else: 13 | + notebook_differs[key] = diff_ignore_keys( 14 | + inner_differ=diff, ignore_keys=['collapsed', 'autoscroll', 'deletable', 'editable']) 15 | else: 16 | for key in metadata_keys: 17 | notebook_differs[key] = diff_ignore 18 | -------------------------------------------------------------------------------- /docker/nbdime-2-toc.patch: -------------------------------------------------------------------------------- 1 | --- a/nbdime/diffing/notebooks.py 2 | +++ b/nbdime/diffing/notebooks.py 3 | @@ -553,7 +553,7 @@ 4 | del notebook_differs[key] 5 | else: 6 | notebook_differs[key] = diff_ignore_keys( 7 | - inner_differ=diff, ignore_keys=['collapsed', 'autoscroll', 'deletable', 'editable']) 8 | + inner_differ=diff, ignore_keys=['toc', 'collapsed', 'autoscroll', 'deletable', 'editable']) 9 | else: 10 | for key in metadata_keys: 11 | notebook_differs[key] = diff_ignore 12 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: handson-ml 2 | dependencies: 3 | - python=3.6 4 | - scikit-learn 5 | - matplotlib 6 | - jupyter 7 | - pandas 8 | - pillow 9 | - nltk 10 | - pip: 11 | - tensorflow 12 | - gym 13 | - graphviz 14 | - watermark 15 | - urlextract 16 | - xgboost 17 | -------------------------------------------------------------------------------- /extra_autodiff.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "**부록 D – 자동 미분**" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "_이 노트북은 간단한 예제를 통해 여러 가지 자동 미분 기법의 작동 원리를 설명합니다._" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# 설정" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "먼저 이 노트북이 파이썬 2와 3에서 문제없이 작동되도록 합니다:" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 1, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "# 파이썬 2와 파이썬 3을 모두 지원하기 위해\n", 38 | "from __future__ import absolute_import, division, print_function, unicode_literals" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "# 소개" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "파라미터 x와 y에 대한 함수 $f(x,y)=x^2y + y + 2$의 그래디언트를 계산한다고 가정합시다:" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 2, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "def f(x,y):\n", 62 | " return x*x*y + y + 2" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "해석적으로 푸는 방법이 하나 있습니다:\n", 70 | "\n", 71 | "$\\dfrac{\\partial f}{\\partial x} = 2xy$\n", 72 | "\n", 73 | "$\\dfrac{\\partial f}{\\partial y} = x^2 + 1$" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 3, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "def df(x,y):\n", 83 | " return 2*x*y, x*x + 1" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "예를 들어 $\\dfrac{\\partial f}{\\partial x}(3,4) = 24$ 이고, $\\dfrac{\\partial f}{\\partial y}(3,4) = 10$ 입니다." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "data": { 100 | "text/plain": [ 101 | "(24, 10)" 102 | ] 103 | }, 104 | "execution_count": 4, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "df(3, 4)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "완벽합니다! 2차 도함수(헤시안이라고도 부릅니다)를 위한 식도 구할 수 있습니다:\n", 118 | "\n", 119 | "$\\dfrac{\\partial^2 f}{\\partial x \\partial x} = \\dfrac{\\partial (2xy)}{\\partial x} = 2y$\n", 120 | "\n", 121 | "$\\dfrac{\\partial^2 f}{\\partial x \\partial y} = \\dfrac{\\partial (2xy)}{\\partial y} = 2x$\n", 122 | "\n", 123 | "$\\dfrac{\\partial^2 f}{\\partial y \\partial x} = \\dfrac{\\partial (x^2 + 1)}{\\partial x} = 2x$\n", 124 | "\n", 125 | "$\\dfrac{\\partial^2 f}{\\partial y \\partial y} = \\dfrac{\\partial (x^2 + 1)}{\\partial y} = 0$" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "x=3이고 y=4일 때, 헤시안은 각각 8, 6, 6, 0입니다. 위 식을 사용해 이를 계산해 보죠:" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 5, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "def d2f(x, y):\n", 142 | " return [2*y, 2*x], [2*x, 0]" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 6, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "data": { 152 | "text/plain": [ 153 | "([8, 6], [6, 0])" 154 | ] 155 | }, 156 | "execution_count": 6, 157 | "metadata": {}, 158 | "output_type": "execute_result" 159 | } 160 | ], 161 | "source": [ 162 | "d2f(3, 4)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "좋습니다. 하지만 이렇게 하려면 수학 지식이 필요합니다. 이 경우에는 아주 어렵지 않지만 심층 신경망일 때 이런 식으로 도함수를 계산하는 것은 현실적으로 불가능합니다. 자동화해서 계산할 수 있는 여러 방법을 살펴 보겠습니다!" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "# 수치 미분" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "metadata": {}, 182 | "source": [ 183 | "여기서는 다음 식을 사용하여 그래디언트 근사값을 계산합니다. $\\dfrac{\\partial f}{\\partial x} = \\displaystyle{\\lim_{\\epsilon \\to 0}}\\dfrac{f(x+\\epsilon, y) - f(x, y)}{\\epsilon}$ (그리고 $\\dfrac{\\partial f}{\\partial y}$에 대해서도 비슷합니다)." 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 7, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "def gradients(func, vars_list, eps=0.0001):\n", 193 | " partial_derivatives = []\n", 194 | " base_func_eval = func(*vars_list)\n", 195 | " for idx in range(len(vars_list)):\n", 196 | " tweaked_vars = vars_list[:]\n", 197 | " tweaked_vars[idx] += eps\n", 198 | " tweaked_func_eval = func(*tweaked_vars)\n", 199 | " derivative = (tweaked_func_eval - base_func_eval) / eps\n", 200 | " partial_derivatives.append(derivative)\n", 201 | " return partial_derivatives" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 8, 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [ 210 | "def df(x, y):\n", 211 | " return gradients(f, [x, y])" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 9, 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "data": { 221 | "text/plain": [ 222 | "[24.000400000048216, 10.000000000047748]" 223 | ] 224 | }, 225 | "execution_count": 9, 226 | "metadata": {}, 227 | "output_type": "execute_result" 228 | } 229 | ], 230 | "source": [ 231 | "df(3, 4)" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "metadata": {}, 237 | "source": [ 238 | "잘 작동하네요!" 239 | ] 240 | }, 241 | { 242 | "cell_type": "markdown", 243 | "metadata": {}, 244 | "source": [ 245 | "이 방식의 장점은 헤시안 계산이 쉽다는 것입니다. 먼저 1차 도함수(자코비안이라고도 부릅니다)를 계산하는 함수를 만듭니다:" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 10, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "(24.000400000048216, 10.000000000047748)" 257 | ] 258 | }, 259 | "execution_count": 10, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "def dfdx(x, y):\n", 266 | " return gradients(f, [x,y])[0]\n", 267 | "\n", 268 | "def dfdy(x, y):\n", 269 | " return gradients(f, [x,y])[1]\n", 270 | "\n", 271 | "dfdx(3., 4.), dfdy(3., 4.)" 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": {}, 277 | "source": [ 278 | "이제 간단하게 이 함수에 `grandients()` 함수를 적용하면 됩니다:" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 11, 284 | "metadata": {}, 285 | "outputs": [], 286 | "source": [ 287 | "def d2f(x, y):\n", 288 | " return [gradients(dfdx, [3., 4.]), gradients(dfdy, [3., 4.])]" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 12, 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "[[7.999999951380232, 6.000099261882497],\n", 300 | " [6.000099261882497, -1.4210854715202004e-06]]" 301 | ] 302 | }, 303 | "execution_count": 12, 304 | "metadata": {}, 305 | "output_type": "execute_result" 306 | } 307 | ], 308 | "source": [ 309 | "d2f(3, 4)" 310 | ] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "metadata": {}, 315 | "source": [ 316 | "모두 잘 계산되었지만 이 결과는 근사값입니다. $n$개의 변수에 대한 함수의 그래디언트를 계산하러면 이 함수를 $n$번 호출해야 합니다. 심층 신경망에서는 경사 하강법을 사용해 수정할 파라미터가 수천 개가 있기 때문에 이런 방법은 매우 느릴 수 있습니다(경사 하강법은 각 파라미터에 대한 손실 함수의 그래디언트를 계산해야 합니다)." 317 | ] 318 | }, 319 | { 320 | "cell_type": "markdown", 321 | "metadata": {}, 322 | "source": [ 323 | "## 간단한 계산 그래프 구현하기" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "metadata": {}, 329 | "source": [ 330 | "수치적인 방법 대신에 기호 미분 기법을 구현해 보죠. 이를 위해 상수, 변수, 연산을 표현할 클래스를 정의하겠습니다." 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 13, 336 | "metadata": {}, 337 | "outputs": [], 338 | "source": [ 339 | "class Const(object):\n", 340 | " def __init__(self, value):\n", 341 | " self.value = value\n", 342 | " def evaluate(self):\n", 343 | " return self.value\n", 344 | " def __str__(self):\n", 345 | " return str(self.value)\n", 346 | "\n", 347 | "class Var(object):\n", 348 | " def __init__(self, name, init_value=0):\n", 349 | " self.value = init_value\n", 350 | " self.name = name\n", 351 | " def evaluate(self):\n", 352 | " return self.value\n", 353 | " def __str__(self):\n", 354 | " return self.name\n", 355 | "\n", 356 | "class BinaryOperator(object):\n", 357 | " def __init__(self, a, b):\n", 358 | " self.a = a\n", 359 | " self.b = b\n", 360 | "\n", 361 | "class Add(BinaryOperator):\n", 362 | " def evaluate(self):\n", 363 | " return self.a.evaluate() + self.b.evaluate()\n", 364 | " def __str__(self):\n", 365 | " return \"{} + {}\".format(self.a, self.b)\n", 366 | "\n", 367 | "class Mul(BinaryOperator):\n", 368 | " def evaluate(self):\n", 369 | " return self.a.evaluate() * self.b.evaluate()\n", 370 | " def __str__(self):\n", 371 | " return \"({}) * ({})\".format(self.a, self.b)" 372 | ] 373 | }, 374 | { 375 | "cell_type": "markdown", 376 | "metadata": {}, 377 | "source": [ 378 | "좋습니다. 이제 함수 $f$를 나타내는 계산 그래프를 만들 수 있습니다:" 379 | ] 380 | }, 381 | { 382 | "cell_type": "code", 383 | "execution_count": 14, 384 | "metadata": {}, 385 | "outputs": [], 386 | "source": [ 387 | "x = Var(\"x\")\n", 388 | "y = Var(\"y\")\n", 389 | "f = Add(Mul(Mul(x, x), y), Add(y, Const(2))) # f(x,y) = x²y + y + 2" 390 | ] 391 | }, 392 | { 393 | "cell_type": "markdown", 394 | "metadata": {}, 395 | "source": [ 396 | "이 그래프를 실행하여 어떤 포인트에서도 $f$를 계산할 수 있습니다. 예를 들면 $f(3, 4)$는 다음과 같습니다." 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 15, 402 | "metadata": {}, 403 | "outputs": [ 404 | { 405 | "data": { 406 | "text/plain": [ 407 | "42" 408 | ] 409 | }, 410 | "execution_count": 15, 411 | "metadata": {}, 412 | "output_type": "execute_result" 413 | } 414 | ], 415 | "source": [ 416 | "x.value = 3\n", 417 | "y.value = 4\n", 418 | "f.evaluate()" 419 | ] 420 | }, 421 | { 422 | "cell_type": "markdown", 423 | "metadata": {}, 424 | "source": [ 425 | "완벽한 정답을 찾았네요." 426 | ] 427 | }, 428 | { 429 | "cell_type": "markdown", 430 | "metadata": {}, 431 | "source": [ 432 | "## 그래디언트 계산하기" 433 | ] 434 | }, 435 | { 436 | "cell_type": "markdown", 437 | "metadata": {}, 438 | "source": [ 439 | "여기서 제시할 자동 미분 방법은 모두 *연쇄 법칙(chain rule)*을 기반으로 합니다." 440 | ] 441 | }, 442 | { 443 | "cell_type": "markdown", 444 | "metadata": {}, 445 | "source": [ 446 | "두 개의 함수 $u$와 $v$가 있고 어떤 입력 $x$에 연속적으로 적용하여 결과 $v$를 얻었다고 가정합시다. 즉, $z = v(u(x))$이고, $z = v(s)$와 $s = u(x)$로 나누어 쓸 수 있습니다. 연쇄 법칙을 적용하면 입력 $x$에 대한 출력 $z$의 편도 함수를 계산할 수 있습니다:\n", 447 | "\n", 448 | "$ \\dfrac{\\partial z}{\\partial x} = \\dfrac{\\partial s}{\\partial x} \\cdot \\dfrac{\\partial z}{\\partial s}$" 449 | ] 450 | }, 451 | { 452 | "cell_type": "markdown", 453 | "metadata": {}, 454 | "source": [ 455 | "$z$가 중간 출력이 $s_1, s_2, ..., s_n$인 연속 함수의 출력이라면, 연쇄 법칙이 다음과 같이 적용됩니다:\n", 456 | "\n", 457 | "$ \\dfrac{\\partial z}{\\partial x} = \\dfrac{\\partial s_1}{\\partial x} \\cdot \\dfrac{\\partial s_2}{\\partial s_1} \\cdot \\dfrac{\\partial s_3}{\\partial s_2} \\cdot \\dots \\cdot \\dfrac{\\partial s_{n-1}}{\\partial s_{n-2}} \\cdot \\dfrac{\\partial s_n}{\\partial s_{n-1}} \\cdot \\dfrac{\\partial z}{\\partial s_n}$" 458 | ] 459 | }, 460 | { 461 | "cell_type": "markdown", 462 | "metadata": {}, 463 | "source": [ 464 | "전진 모드 자동 미분에서는 알고리즘이 이 항들을 \"진행 순서대로\"(즉, 출력 $z$을 계산하기 위해 필요한 계산 순서와 동일하게), 즉 왼쪽에서 오른쪽으로 계산합니다. 먼저 $\\dfrac{\\partial s_1}{\\partial x}$를 계산하고, 그다음 $\\dfrac{\\partial s_2}{\\partial s_1}$을 계산하는 식입니다. 후진 모드 자동 미분에서는 알고리즘이 이 항들을 \"진행 반대 순서로\", 즉 오른쪽에서 왼쪽으로 계산합니다. 먼저 $\\dfrac{\\partial z}{\\partial s_n}$을 계산하고, 그다음 $\\dfrac{\\partial s_n}{\\partial s_{n-1}}$을 계산하는 식입니다.\n", 465 | "\n", 466 | "예를 들어, x=3에서 함수 $z(x)=\\sin(x^2)$의 도함수를 전진 모드 자동 미분을 사용하여 계산한다고 가정합시다. 알고리즘은 먼저 편도함수 $\\dfrac{\\partial s_1}{\\partial x}=\\dfrac{\\partial x^2}{\\partial x}=2x=6$을 계산합니다. 다음, $\\dfrac{\\partial z}{\\partial x}=\\dfrac{\\partial s_1}{\\partial x}\\cdot\\dfrac{\\partial z}{\\partial s_1}= 6 \\cdot \\dfrac{\\partial \\sin(s_1)}{\\partial s_1}=6 \\cdot \\cos(s_1)=6 \\cdot \\cos(3^2)\\approx-5.46$을 계산합니다." 467 | ] 468 | }, 469 | { 470 | "cell_type": "markdown", 471 | "metadata": {}, 472 | "source": [ 473 | "앞서 정의한 `gradients()` 함수를 사용해 결과를 검증해 보겠습니다:" 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 16, 479 | "metadata": {}, 480 | "outputs": [ 481 | { 482 | "data": { 483 | "text/plain": [ 484 | "[-5.46761419430053]" 485 | ] 486 | }, 487 | "execution_count": 16, 488 | "metadata": {}, 489 | "output_type": "execute_result" 490 | } 491 | ], 492 | "source": [ 493 | "from math import sin\n", 494 | "\n", 495 | "def z(x):\n", 496 | " return sin(x**2)\n", 497 | "\n", 498 | "gradients(z, [3])" 499 | ] 500 | }, 501 | { 502 | "cell_type": "markdown", 503 | "metadata": {}, 504 | "source": [ 505 | "훌륭하네요. 이제 후진 모드 자동 미분을 사용해 동일한 계산을 해보겠습니다. 이번에는 알고리즘이 오른쪽부터 시작하므로 $\\dfrac{\\partial z}{\\partial s_1} = \\dfrac{\\partial \\sin(s_1)}{\\partial s_1}=\\cos(s_1)=\\cos(3^2)\\approx -0.91$을 계산합니다. 다음 $\\dfrac{\\partial z}{\\partial x}=\\dfrac{\\partial s_1}{\\partial x}\\cdot\\dfrac{\\partial z}{\\partial s_1} \\approx \\dfrac{\\partial s_1}{\\partial x} \\cdot -0.91 = \\dfrac{\\partial x^2}{\\partial x} \\cdot -0.91=2x \\cdot -0.91 = 6\\cdot-0.91=-5.46$을 계산합니다." 506 | ] 507 | }, 508 | { 509 | "cell_type": "markdown", 510 | "metadata": {}, 511 | "source": [ 512 | "당연히 두 방법 모두 같은 결과를 냅니다(반올림 오차는 제외하고). 하나의 입력과 하나의 출력이 있는 경우에는 둘 다 동일한 횟수의 계산이 필요합니다. 하지만 입력과 출력의 개수가 여러 개이면 두 방법의 성능이 매우 달라집니다. 입력이 많다면 가장 오른쪽에 있는 항은 각 입력마다 편도 함수를 계산하기 위해 필요할 것입니다. 그러므로 가장 오른쪽에 있는 항을 먼저 계산하는 것이 좋습니다. 이것은 후진 모드 자동 미분을 의미합니다. 가장 오른쪽의 항을 한번 계산해서 모든 편도 함수를 계산하는데 사용할 수 있습니다. 반대로 출력이 많을 경우에는 가장 왼쪽의 항을 한번 계산해서 여러 출력의 편도 함수를 계산할 수 있는 전진 모드가 더 좋습니다. 딥러닝에서는 전형적으로 수천 개의 모델 파라미터가 있고 입력은 많지만 출력은 적습니다. 사실 훈련하는 동안 일반적으로 출력은 손실 단 하나입니다. 그래서 텐서플로와 주요 딥러닝 라이브러리들은 후진 모드 자동 미분을 사용합니다." 513 | ] 514 | }, 515 | { 516 | "cell_type": "markdown", 517 | "metadata": {}, 518 | "source": [ 519 | "후진 모드 자동 미분에는 복잡도가 한가지 추가됩니다. $s_i$의 값은 일반적으로 $\\dfrac{\\partial s_{i+1}}{\\partial s_i}$를 계산할 때 필요하고, $s_i$는 먼저 $s_{i-1}$를 계산해야 합니다. 이는 또 $s_{i-2}$를 계산해야 하는 식입니다. 그래서 $s_1$, $s_2$, $s_3$, $\\dots$, $s_{n-1}$ 그리고 $s_n$를 계산하기 위해 기본적으로 전진 방향으로 한번 네트워크를 실행해야 합니다. 그다음에 알고리즘이 오른쪽에서 왼쪽으로 편도 함수를 계산할 수 있습니다. RAM에 모든 $s_i$의 중간값을 저장하는 것은 가끔 문제가 됩니다. 특히 이미지를 다룰 때와 RAM이 부족한 GPU를 사용할 때 입니다. 이 문제를 완화하기 위해 신경망의 층 개수를 줄이거나, 텐서플로가 GPU RAM에서 CPU RAM으로 중간값들을 스왑(swap)하도록 설정할 수 있습니다. 다른 방법은 홀수 번째 중간값인 $s_1$, $s_3$, $s_5$, $\\dots$, $s_{n-4}$, $s_{n-2}$ 그리고 $s_n$만 캐싱하는 것입니다. 알고리즘이 편도 함수를 계산할 때 중간값 $s_i$가 없으면, 이전 중간값 $s_{i-1}$를 사용하여 다시 계산해야 합니다. 이는 CPU와 RAM 사이의 트레이드오프입니다(관심이 있다면 [이 논문](https://pdfs.semanticscholar.org/f61e/9fd5a4878e1493f7a6b03774a61c17b7e9a4.pdf)을 확인해 보세요)." 520 | ] 521 | }, 522 | { 523 | "cell_type": "markdown", 524 | "metadata": {}, 525 | "source": [ 526 | "### 전진 모드 자동 미분" 527 | ] 528 | }, 529 | { 530 | "cell_type": "code", 531 | "execution_count": 17, 532 | "metadata": {}, 533 | "outputs": [], 534 | "source": [ 535 | "Const.gradient = lambda self, var: Const(0)\n", 536 | "Var.gradient = lambda self, var: Const(1) if self is var else Const(0)\n", 537 | "Add.gradient = lambda self, var: Add(self.a.gradient(var), self.b.gradient(var))\n", 538 | "Mul.gradient = lambda self, var: Add(Mul(self.a, self.b.gradient(var)), Mul(self.a.gradient(var), self.b))\n", 539 | "\n", 540 | "x = Var(name=\"x\", init_value=3.)\n", 541 | "y = Var(name=\"y\", init_value=4.)\n", 542 | "f = Add(Mul(Mul(x, x), y), Add(y, Const(2))) # f(x,y) = x²y + y + 2\n", 543 | "\n", 544 | "dfdx = f.gradient(x) # 2xy\n", 545 | "dfdy = f.gradient(y) # x² + 1" 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": 18, 551 | "metadata": {}, 552 | "outputs": [ 553 | { 554 | "data": { 555 | "text/plain": [ 556 | "(24.0, 10.0)" 557 | ] 558 | }, 559 | "execution_count": 18, 560 | "metadata": {}, 561 | "output_type": "execute_result" 562 | } 563 | ], 564 | "source": [ 565 | "dfdx.evaluate(), dfdy.evaluate()" 566 | ] 567 | }, 568 | { 569 | "cell_type": "markdown", 570 | "metadata": {}, 571 | "source": [ 572 | "`gradient()` 메서드의 출력은 완전한 기호 미분이므로 1차 도함수에 국한되지 않고 2차 도함수도 계산할 수 있습니다:" 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": 19, 578 | "metadata": {}, 579 | "outputs": [], 580 | "source": [ 581 | "d2fdxdx = dfdx.gradient(x) # 2y\n", 582 | "d2fdxdy = dfdx.gradient(y) # 2x\n", 583 | "d2fdydx = dfdy.gradient(x) # 2x\n", 584 | "d2fdydy = dfdy.gradient(y) # 0" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": 20, 590 | "metadata": {}, 591 | "outputs": [ 592 | { 593 | "data": { 594 | "text/plain": [ 595 | "[[8.0, 6.0], [6.0, 0.0]]" 596 | ] 597 | }, 598 | "execution_count": 20, 599 | "metadata": {}, 600 | "output_type": "execute_result" 601 | } 602 | ], 603 | "source": [ 604 | "[[d2fdxdx.evaluate(), d2fdxdy.evaluate()],\n", 605 | " [d2fdydx.evaluate(), d2fdydy.evaluate()]]" 606 | ] 607 | }, 608 | { 609 | "cell_type": "markdown", 610 | "metadata": {}, 611 | "source": [ 612 | "결과는 근사값이 아니고 완벽하게 맞습니다(물론 컴퓨터의 부동 소수 정밀도 한계까지만)." 613 | ] 614 | }, 615 | { 616 | "cell_type": "markdown", 617 | "metadata": {}, 618 | "source": [ 619 | "### 이원수(dual number)를 사용한 전진 모드 자동 미분" 620 | ] 621 | }, 622 | { 623 | "cell_type": "markdown", 624 | "metadata": {}, 625 | "source": [ 626 | "전진 모드 자동 미분을 적용하는 좋은 한가지 방법은 [이원수](https://ko.wikipedia.org/wiki/%EC%9D%B4%EC%9B%90%EC%88%98_(%EC%88%98%ED%95%99))를 사용하는 것입니다. 간단하게 말하면 이원수 $z$는 $z = a + b\\epsilon$의 형태를 가집니다. 여기에서 $a$와 $b$는 실수입니다. $\\epsilon$은 아주 작은 양수 이지만 모든 실수보다 작기 때문에 $\\epsilon^2=0$입니다. $f(x + \\epsilon) = f(x) + \\dfrac{\\partial f}{\\partial x}\\epsilon$로 쓸 수 있으므로, $f(x + \\epsilon)$를 계산하여 $f(x)$와 $x$에 대한 $f$의 편도 함수를 구할 수 있습니다." 627 | ] 628 | }, 629 | { 630 | "cell_type": "markdown", 631 | "metadata": {}, 632 | "source": [ 633 | "이원수는 자체적인 산술 규칙을 가집니다. 일반적으로 매우 직관적입니다. 예를 들면:\n", 634 | "\n", 635 | "**덧셈**\n", 636 | "\n", 637 | "$(a_1 + b_1\\epsilon) + (a_2 + b_2\\epsilon) = (a_1 + a_2) + (b_1 + b_2)\\epsilon$\n", 638 | "\n", 639 | "**뺄셈**\n", 640 | "\n", 641 | "$(a_1 + b_1\\epsilon) - (a_2 + b_2\\epsilon) = (a_1 - a_2) + (b_1 - b_2)\\epsilon$\n", 642 | "\n", 643 | "**곱셈**\n", 644 | "\n", 645 | "$(a_1 + b_1\\epsilon) \\times (a_2 + b_2\\epsilon) = (a_1 a_2) + (a_1 b_2 + a_2 b_1)\\epsilon + b_1 b_2\\epsilon^2 = (a_1 a_2) + (a_1b_2 + a_2b_1)\\epsilon$\n", 646 | "\n", 647 | "**나눗셈**\n", 648 | "\n", 649 | "$\\dfrac{a_1 + b_1\\epsilon}{a_2 + b_2\\epsilon} = \\dfrac{a_1 + b_1\\epsilon}{a_2 + b_2\\epsilon} \\cdot \\dfrac{a_2 - b_2\\epsilon}{a_2 - b_2\\epsilon} = \\dfrac{a_1 a_2 + (b_1 a_2 - a_1 b_2)\\epsilon - b_1 b_2\\epsilon^2}{{a_2}^2 + (a_2 b_2 - a_2 b_2)\\epsilon - {b_2}^2\\epsilon} = \\dfrac{a_1}{a_2} + \\dfrac{a_1 b_2 - b_1 a_2}{{a_2}^2}\\epsilon$\n", 650 | "\n", 651 | "**거듭제곱**\n", 652 | "\n", 653 | "$(a + b\\epsilon)^n = a^n + (n a^{n-1}b)\\epsilon$\n", 654 | "\n", 655 | "등." 656 | ] 657 | }, 658 | { 659 | "cell_type": "markdown", 660 | "metadata": {}, 661 | "source": [ 662 | "이원수를 표현할 클래스를 만들고 몇 개의 연산(덧셈과 곱셈)을 구현해 보죠. 필요하면 다른 연산을 더 추가해도 됩니다." 663 | ] 664 | }, 665 | { 666 | "cell_type": "code", 667 | "execution_count": 21, 668 | "metadata": {}, 669 | "outputs": [], 670 | "source": [ 671 | "class DualNumber(object):\n", 672 | " def __init__(self, value=0.0, eps=0.0):\n", 673 | " self.value = value\n", 674 | " self.eps = eps\n", 675 | " def __add__(self, b):\n", 676 | " return DualNumber(self.value + self.to_dual(b).value,\n", 677 | " self.eps + self.to_dual(b).eps)\n", 678 | " def __radd__(self, a):\n", 679 | " return self.to_dual(a).__add__(self)\n", 680 | " def __mul__(self, b):\n", 681 | " return DualNumber(self.value * self.to_dual(b).value,\n", 682 | " self.eps * self.to_dual(b).value + self.value * self.to_dual(b).eps)\n", 683 | " def __rmul__(self, a):\n", 684 | " return self.to_dual(a).__mul__(self)\n", 685 | " def __str__(self):\n", 686 | " if self.eps:\n", 687 | " return \"{:.1f} + {:.1f}ε\".format(self.value, self.eps)\n", 688 | " else:\n", 689 | " return \"{:.1f}\".format(self.value)\n", 690 | " def __repr__(self):\n", 691 | " return str(self)\n", 692 | " @classmethod\n", 693 | " def to_dual(cls, n):\n", 694 | " if hasattr(n, \"value\"):\n", 695 | " return n\n", 696 | " else:\n", 697 | " return cls(n)" 698 | ] 699 | }, 700 | { 701 | "cell_type": "markdown", 702 | "metadata": {}, 703 | "source": [ 704 | "$3 + (3 + 4 \\epsilon) = 6 + 4\\epsilon$" 705 | ] 706 | }, 707 | { 708 | "cell_type": "code", 709 | "execution_count": 22, 710 | "metadata": {}, 711 | "outputs": [ 712 | { 713 | "data": { 714 | "text/plain": [ 715 | "6.0 + 4.0ε" 716 | ] 717 | }, 718 | "execution_count": 22, 719 | "metadata": {}, 720 | "output_type": "execute_result" 721 | } 722 | ], 723 | "source": [ 724 | "3 + DualNumber(3, 4)" 725 | ] 726 | }, 727 | { 728 | "cell_type": "markdown", 729 | "metadata": {}, 730 | "source": [ 731 | "$(3 + 4ε)\\times(5 + 7ε)$ = $3 \\times 5 + 3 \\times 7ε + 4ε \\times 5 + 4ε \\times 7ε$ = $15 + 21ε + 20ε + 28ε^2$ = $15 + 41ε + 28 \\times 0$ = $15 + 41ε$" 732 | ] 733 | }, 734 | { 735 | "cell_type": "code", 736 | "execution_count": 23, 737 | "metadata": {}, 738 | "outputs": [ 739 | { 740 | "data": { 741 | "text/plain": [ 742 | "15.0 + 41.0ε" 743 | ] 744 | }, 745 | "execution_count": 23, 746 | "metadata": {}, 747 | "output_type": "execute_result" 748 | } 749 | ], 750 | "source": [ 751 | "DualNumber(3, 4) * DualNumber(5, 7)" 752 | ] 753 | }, 754 | { 755 | "cell_type": "markdown", 756 | "metadata": {}, 757 | "source": [ 758 | "이제 이원수가 우리가 만든 계산 프레임워크와 함께 쓸 수 있는지 확인해 보죠:" 759 | ] 760 | }, 761 | { 762 | "cell_type": "code", 763 | "execution_count": 24, 764 | "metadata": {}, 765 | "outputs": [ 766 | { 767 | "data": { 768 | "text/plain": [ 769 | "42.0" 770 | ] 771 | }, 772 | "execution_count": 24, 773 | "metadata": {}, 774 | "output_type": "execute_result" 775 | } 776 | ], 777 | "source": [ 778 | "x.value = DualNumber(3.0)\n", 779 | "y.value = DualNumber(4.0)\n", 780 | "\n", 781 | "f.evaluate()" 782 | ] 783 | }, 784 | { 785 | "cell_type": "markdown", 786 | "metadata": {}, 787 | "source": [ 788 | "오, 잘 되네요. 이를 사용해 x=3이고 y=4에서 $x$와 $y$에 대한 $f$의 편도 함수를 계산해 보겠습니다:" 789 | ] 790 | }, 791 | { 792 | "cell_type": "code", 793 | "execution_count": 25, 794 | "metadata": {}, 795 | "outputs": [], 796 | "source": [ 797 | "x.value = DualNumber(3.0, 1.0) # 3 + ε\n", 798 | "y.value = DualNumber(4.0) # 4\n", 799 | "\n", 800 | "dfdx = f.evaluate().eps\n", 801 | "\n", 802 | "x.value = DualNumber(3.0) # 3\n", 803 | "y.value = DualNumber(4.0, 1.0) # 4 + ε\n", 804 | "\n", 805 | "dfdy = f.evaluate().eps" 806 | ] 807 | }, 808 | { 809 | "cell_type": "code", 810 | "execution_count": 26, 811 | "metadata": {}, 812 | "outputs": [ 813 | { 814 | "data": { 815 | "text/plain": [ 816 | "24.0" 817 | ] 818 | }, 819 | "execution_count": 26, 820 | "metadata": {}, 821 | "output_type": "execute_result" 822 | } 823 | ], 824 | "source": [ 825 | "dfdx" 826 | ] 827 | }, 828 | { 829 | "cell_type": "code", 830 | "execution_count": 27, 831 | "metadata": {}, 832 | "outputs": [ 833 | { 834 | "data": { 835 | "text/plain": [ 836 | "10.0" 837 | ] 838 | }, 839 | "execution_count": 27, 840 | "metadata": {}, 841 | "output_type": "execute_result" 842 | } 843 | ], 844 | "source": [ 845 | "dfdy" 846 | ] 847 | }, 848 | { 849 | "cell_type": "markdown", 850 | "metadata": {}, 851 | "source": [ 852 | "훌륭합니다! 하지만 이 구현에서는 1차 도함수만 가능합니다. 이제 후진 모드를 살펴 보죠." 853 | ] 854 | }, 855 | { 856 | "cell_type": "markdown", 857 | "metadata": {}, 858 | "source": [ 859 | "### 후진 모드 자동 미분" 860 | ] 861 | }, 862 | { 863 | "cell_type": "markdown", 864 | "metadata": {}, 865 | "source": [ 866 | "우리가 만든 간단한 프레임워크를 수정해서 후진 모드 자동 미분을 추가하겠습니다:" 867 | ] 868 | }, 869 | { 870 | "cell_type": "code", 871 | "execution_count": 28, 872 | "metadata": {}, 873 | "outputs": [], 874 | "source": [ 875 | "class Const(object):\n", 876 | " def __init__(self, value):\n", 877 | " self.value = value\n", 878 | " def evaluate(self):\n", 879 | " return self.value\n", 880 | " def backpropagate(self, gradient):\n", 881 | " pass\n", 882 | " def __str__(self):\n", 883 | " return str(self.value)\n", 884 | "\n", 885 | "class Var(object):\n", 886 | " def __init__(self, name, init_value=0):\n", 887 | " self.value = init_value\n", 888 | " self.name = name\n", 889 | " self.gradient = 0\n", 890 | " def evaluate(self):\n", 891 | " return self.value\n", 892 | " def backpropagate(self, gradient):\n", 893 | " self.gradient += gradient\n", 894 | " def __str__(self):\n", 895 | " return self.name\n", 896 | "\n", 897 | "class BinaryOperator(object):\n", 898 | " def __init__(self, a, b):\n", 899 | " self.a = a\n", 900 | " self.b = b\n", 901 | "\n", 902 | "class Add(BinaryOperator):\n", 903 | " def evaluate(self):\n", 904 | " self.value = self.a.evaluate() + self.b.evaluate()\n", 905 | " return self.value\n", 906 | " def backpropagate(self, gradient):\n", 907 | " self.a.backpropagate(gradient)\n", 908 | " self.b.backpropagate(gradient)\n", 909 | " def __str__(self):\n", 910 | " return \"{} + {}\".format(self.a, self.b)\n", 911 | "\n", 912 | "class Mul(BinaryOperator):\n", 913 | " def evaluate(self):\n", 914 | " self.value = self.a.evaluate() * self.b.evaluate()\n", 915 | " return self.value\n", 916 | " def backpropagate(self, gradient):\n", 917 | " self.a.backpropagate(gradient * self.b.value)\n", 918 | " self.b.backpropagate(gradient * self.a.value)\n", 919 | " def __str__(self):\n", 920 | " return \"({}) * ({})\".format(self.a, self.b)" 921 | ] 922 | }, 923 | { 924 | "cell_type": "code", 925 | "execution_count": 29, 926 | "metadata": {}, 927 | "outputs": [], 928 | "source": [ 929 | "x = Var(\"x\", init_value=3)\n", 930 | "y = Var(\"y\", init_value=4)\n", 931 | "f = Add(Mul(Mul(x, x), y), Add(y, Const(2))) # f(x,y) = x²y + y + 2\n", 932 | "\n", 933 | "result = f.evaluate()\n", 934 | "f.backpropagate(1.0)" 935 | ] 936 | }, 937 | { 938 | "cell_type": "code", 939 | "execution_count": 30, 940 | "metadata": {}, 941 | "outputs": [ 942 | { 943 | "name": "stdout", 944 | "output_type": "stream", 945 | "text": [ 946 | "((x) * (x)) * (y) + y + 2\n" 947 | ] 948 | } 949 | ], 950 | "source": [ 951 | "print(f)" 952 | ] 953 | }, 954 | { 955 | "cell_type": "code", 956 | "execution_count": 31, 957 | "metadata": {}, 958 | "outputs": [ 959 | { 960 | "data": { 961 | "text/plain": [ 962 | "42" 963 | ] 964 | }, 965 | "execution_count": 31, 966 | "metadata": {}, 967 | "output_type": "execute_result" 968 | } 969 | ], 970 | "source": [ 971 | "result" 972 | ] 973 | }, 974 | { 975 | "cell_type": "code", 976 | "execution_count": 32, 977 | "metadata": {}, 978 | "outputs": [ 979 | { 980 | "data": { 981 | "text/plain": [ 982 | "24.0" 983 | ] 984 | }, 985 | "execution_count": 32, 986 | "metadata": {}, 987 | "output_type": "execute_result" 988 | } 989 | ], 990 | "source": [ 991 | "x.gradient" 992 | ] 993 | }, 994 | { 995 | "cell_type": "code", 996 | "execution_count": 33, 997 | "metadata": {}, 998 | "outputs": [ 999 | { 1000 | "data": { 1001 | "text/plain": [ 1002 | "10.0" 1003 | ] 1004 | }, 1005 | "execution_count": 33, 1006 | "metadata": {}, 1007 | "output_type": "execute_result" 1008 | } 1009 | ], 1010 | "source": [ 1011 | "y.gradient" 1012 | ] 1013 | }, 1014 | { 1015 | "cell_type": "markdown", 1016 | "metadata": {}, 1017 | "source": [ 1018 | "여기에서도 이 구현의 출력이 숫자이고 기호 표현(symbolic expressions)이 아니므로 1차 도함수로 제한이 됩니다. 그러나 값 대신 기호 표현을 반환하는 `backpropagate()` 메서드를 만들 수 있습니다. 이렇게 하면 2차 도함수(또 그 이상)를 계산할 수 있습니다. 이것이 텐서플로와 자동 미분을 구현한 모든 주요 딥러닝 라이브러리들의 방식입니다." 1019 | ] 1020 | }, 1021 | { 1022 | "cell_type": "markdown", 1023 | "metadata": {}, 1024 | "source": [ 1025 | "### 텐서플로를 사용한 후진 모드 자동 미분" 1026 | ] 1027 | }, 1028 | { 1029 | "cell_type": "code", 1030 | "execution_count": 34, 1031 | "metadata": {}, 1032 | "outputs": [], 1033 | "source": [ 1034 | "import tensorflow as tf" 1035 | ] 1036 | }, 1037 | { 1038 | "cell_type": "code", 1039 | "execution_count": 35, 1040 | "metadata": {}, 1041 | "outputs": [ 1042 | { 1043 | "data": { 1044 | "text/plain": [ 1045 | "(42.0, [24.0, 10.0])" 1046 | ] 1047 | }, 1048 | "execution_count": 35, 1049 | "metadata": {}, 1050 | "output_type": "execute_result" 1051 | } 1052 | ], 1053 | "source": [ 1054 | "tf.reset_default_graph()\n", 1055 | "\n", 1056 | "x = tf.Variable(3., name=\"x\")\n", 1057 | "y = tf.Variable(4., name=\"y\")\n", 1058 | "f = x*x*y + y + 2\n", 1059 | "\n", 1060 | "jacobians = tf.gradients(f, [x, y])\n", 1061 | "\n", 1062 | "init = tf.global_variables_initializer()\n", 1063 | "\n", 1064 | "with tf.Session() as sess:\n", 1065 | " init.run()\n", 1066 | " f_val, jacobians_val = sess.run([f, jacobians])\n", 1067 | "\n", 1068 | "f_val, jacobians_val" 1069 | ] 1070 | }, 1071 | { 1072 | "cell_type": "markdown", 1073 | "metadata": {}, 1074 | "source": [ 1075 | "전부 기호이기 때문에 2차 도함수와 그 이상도 계산할 수 있습니다. 그러나 의존하지 않는 변수에 대한 텐서의 도함수를 계산할 때, `grandients()` 함수가 0.0 대신 None을 반환하기 때문에 `sess.run()`으로 평가할 수 없습니다. 그러므로 `None`을 주의하세요. 여기서는 간단하게 0 텐서로 바꿉니다." 1076 | ] 1077 | }, 1078 | { 1079 | "cell_type": "code", 1080 | "execution_count": 36, 1081 | "metadata": {}, 1082 | "outputs": [ 1083 | { 1084 | "data": { 1085 | "text/plain": [ 1086 | "([8.0, 6.0], [6.0, 0.0])" 1087 | ] 1088 | }, 1089 | "execution_count": 36, 1090 | "metadata": {}, 1091 | "output_type": "execute_result" 1092 | } 1093 | ], 1094 | "source": [ 1095 | "hessians_x = tf.gradients(jacobians[0], [x, y])\n", 1096 | "hessians_y = tf.gradients(jacobians[1], [x, y])\n", 1097 | "\n", 1098 | "def replace_none_with_zero(tensors):\n", 1099 | " return [tensor if tensor is not None else tf.constant(0.)\n", 1100 | " for tensor in tensors]\n", 1101 | "\n", 1102 | "hessians_x = replace_none_with_zero(hessians_x)\n", 1103 | "hessians_y = replace_none_with_zero(hessians_y)\n", 1104 | "\n", 1105 | "init = tf.global_variables_initializer()\n", 1106 | "\n", 1107 | "with tf.Session() as sess:\n", 1108 | " init.run()\n", 1109 | " hessians_x_val, hessians_y_val = sess.run([hessians_x, hessians_y])\n", 1110 | "\n", 1111 | "hessians_x_val, hessians_y_val" 1112 | ] 1113 | }, 1114 | { 1115 | "cell_type": "markdown", 1116 | "metadata": {}, 1117 | "source": [ 1118 | "여기까지 해서 마치도록 하겠습니다! 이 노트북이 맘에 드시길 바랄께요." 1119 | ] 1120 | } 1121 | ], 1122 | "metadata": { 1123 | "kernelspec": { 1124 | "display_name": "Python 3", 1125 | "language": "python", 1126 | "name": "python3" 1127 | }, 1128 | "language_info": { 1129 | "codemirror_mode": { 1130 | "name": "ipython", 1131 | "version": 3 1132 | }, 1133 | "file_extension": ".py", 1134 | "mimetype": "text/x-python", 1135 | "name": "python", 1136 | "nbconvert_exporter": "python", 1137 | "pygments_lexer": "ipython3", 1138 | "version": "3.6.5" 1139 | }, 1140 | "nav_menu": { 1141 | "height": "603px", 1142 | "width": "616px" 1143 | }, 1144 | "toc": { 1145 | "navigate_menu": true, 1146 | "number_sections": true, 1147 | "sideBar": true, 1148 | "threshold": 6, 1149 | "toc_cell": false, 1150 | "toc_section_display": "block", 1151 | "toc_window_display": true 1152 | } 1153 | }, 1154 | "nbformat": 4, 1155 | "nbformat_minor": 1 1156 | } 1157 | -------------------------------------------------------------------------------- /images/ann/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/ann/activation_functions_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ann/activation_functions_plot.png -------------------------------------------------------------------------------- /images/ann/perceptron_iris_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ann/perceptron_iris_plot.png -------------------------------------------------------------------------------- /images/autoencoders/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/autoencoders/extracted_features_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/autoencoders/extracted_features_plot.png -------------------------------------------------------------------------------- /images/autoencoders/generated_digits_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/autoencoders/generated_digits_plot.png -------------------------------------------------------------------------------- /images/autoencoders/linear_autoencoder_pca_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/autoencoders/linear_autoencoder_pca_plot.png -------------------------------------------------------------------------------- /images/autoencoders/reconstruction_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/autoencoders/reconstruction_plot.png -------------------------------------------------------------------------------- /images/autoencoders/sparsity_loss_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/autoencoders/sparsity_loss_plot.png -------------------------------------------------------------------------------- /images/classification/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/classification/cleaned_digit_example_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/cleaned_digit_example_plot.png -------------------------------------------------------------------------------- /images/classification/confusion_matrix_errors_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/confusion_matrix_errors_plot.png -------------------------------------------------------------------------------- /images/classification/confusion_matrix_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/confusion_matrix_plot.png -------------------------------------------------------------------------------- /images/classification/error_analysis_digits_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/error_analysis_digits_plot.png -------------------------------------------------------------------------------- /images/classification/more_digits_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/more_digits_plot.png -------------------------------------------------------------------------------- /images/classification/noisy_digit_example_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/noisy_digit_example_plot.png -------------------------------------------------------------------------------- /images/classification/precision_recall_vs_threshold_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/precision_recall_vs_threshold_plot.png -------------------------------------------------------------------------------- /images/classification/precision_vs_recall_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/precision_vs_recall_plot.png -------------------------------------------------------------------------------- /images/classification/roc_curve_comparison_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/roc_curve_comparison_plot.png -------------------------------------------------------------------------------- /images/classification/roc_curve_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/roc_curve_plot.png -------------------------------------------------------------------------------- /images/classification/some_digit_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/classification/some_digit_plot.png -------------------------------------------------------------------------------- /images/cnn/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/cnn/china_horizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/cnn/china_horizontal.png -------------------------------------------------------------------------------- /images/cnn/china_max_pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/cnn/china_max_pool.png -------------------------------------------------------------------------------- /images/cnn/china_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/cnn/china_original.png -------------------------------------------------------------------------------- /images/cnn/china_original_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/cnn/china_original_small.png -------------------------------------------------------------------------------- /images/cnn/china_vertical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/cnn/china_vertical.png -------------------------------------------------------------------------------- /images/cnn/test_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/cnn/test_image.png -------------------------------------------------------------------------------- /images/decision_trees/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/decision_trees/decision_tree_decision_boundaries_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/decision_tree_decision_boundaries_plot.png -------------------------------------------------------------------------------- /images/decision_trees/decision_tree_instability_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/decision_tree_instability_plot.png -------------------------------------------------------------------------------- /images/decision_trees/iris_tree.dot: -------------------------------------------------------------------------------- 1 | digraph Tree { 2 | node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ; 3 | edge [fontname=helvetica] ; 4 | 0 [label="꽃잎 길이 (cm) <= 2.45\ngini = 0.667\nsamples = 150\nvalue = [50, 50, 50]\nclass = setosa", fillcolor="#ffffff"] ; 5 | 1 [label="gini = 0.0\nsamples = 50\nvalue = [50, 0, 0]\nclass = setosa", fillcolor="#e58139"] ; 6 | 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ; 7 | 2 [label="꽃잎 너비 (cm) <= 1.75\ngini = 0.5\nsamples = 100\nvalue = [0, 50, 50]\nclass = versicolor", fillcolor="#ffffff"] ; 8 | 0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ; 9 | 3 [label="gini = 0.168\nsamples = 54\nvalue = [0, 49, 5]\nclass = versicolor", fillcolor="#4de88e"] ; 10 | 2 -> 3 ; 11 | 4 [label="gini = 0.043\nsamples = 46\nvalue = [0, 1, 45]\nclass = virginica", fillcolor="#843de6"] ; 12 | 2 -> 4 ; 13 | } -------------------------------------------------------------------------------- /images/decision_trees/iris_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/iris_tree.png -------------------------------------------------------------------------------- /images/decision_trees/min_samples_leaf_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/min_samples_leaf_plot.png -------------------------------------------------------------------------------- /images/decision_trees/regression_tree.dot: -------------------------------------------------------------------------------- 1 | digraph Tree { 2 | node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ; 3 | edge [fontname=helvetica] ; 4 | 0 [label="x1 <= 0.197\nmse = 0.098\nsamples = 200\nvalue = 0.354", fillcolor="#f6d6be"] ; 5 | 1 [label="x1 <= 0.092\nmse = 0.038\nsamples = 44\nvalue = 0.689", fillcolor="#eb9d65"] ; 6 | 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ; 7 | 2 [label="mse = 0.018\nsamples = 20\nvalue = 0.854", fillcolor="#e58139"] ; 8 | 1 -> 2 ; 9 | 3 [label="mse = 0.013\nsamples = 24\nvalue = 0.552", fillcolor="#f0b489"] ; 10 | 1 -> 3 ; 11 | 4 [label="x1 <= 0.772\nmse = 0.074\nsamples = 156\nvalue = 0.259", fillcolor="#fae6d7"] ; 12 | 0 -> 4 [labeldistance=2.5, labelangle=-45, headlabel="False"] ; 13 | 5 [label="mse = 0.015\nsamples = 110\nvalue = 0.111", fillcolor="#ffffff"] ; 14 | 4 -> 5 ; 15 | 6 [label="mse = 0.036\nsamples = 46\nvalue = 0.615", fillcolor="#edaa79"] ; 16 | 4 -> 6 ; 17 | } -------------------------------------------------------------------------------- /images/decision_trees/regression_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/regression_tree.png -------------------------------------------------------------------------------- /images/decision_trees/sensitivity_to_rotation_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/sensitivity_to_rotation_plot.png -------------------------------------------------------------------------------- /images/decision_trees/tree_regression_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/tree_regression_plot.png -------------------------------------------------------------------------------- /images/decision_trees/tree_regression_regularization_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/decision_trees/tree_regression_regularization_plot.png -------------------------------------------------------------------------------- /images/deep/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/deep/elu_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/deep/elu_plot.png -------------------------------------------------------------------------------- /images/deep/leaky_relu_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/deep/leaky_relu_plot.png -------------------------------------------------------------------------------- /images/deep/selu_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/deep/selu_plot.png -------------------------------------------------------------------------------- /images/deep/sigmoid_saturation_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/deep/sigmoid_saturation_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/dim_reduction/dataset_2d_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/dataset_2d_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/dataset_3d_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/dataset_3d_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/kernel_pca_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/kernel_pca_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/lle_unrolling_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/lle_unrolling_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/manifold_decision_boundary_plot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/manifold_decision_boundary_plot1.png -------------------------------------------------------------------------------- /images/dim_reduction/manifold_decision_boundary_plot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/manifold_decision_boundary_plot2.png -------------------------------------------------------------------------------- /images/dim_reduction/manifold_decision_boundary_plot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/manifold_decision_boundary_plot3.png -------------------------------------------------------------------------------- /images/dim_reduction/manifold_decision_boundary_plot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/manifold_decision_boundary_plot4.png -------------------------------------------------------------------------------- /images/dim_reduction/mnist_compression_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/mnist_compression_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/other_dim_reduction_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/other_dim_reduction_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/pca_best_projection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/pca_best_projection.png -------------------------------------------------------------------------------- /images/dim_reduction/preimage_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/preimage_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/squished_swiss_roll_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/squished_swiss_roll_plot.png -------------------------------------------------------------------------------- /images/dim_reduction/swiss_roll_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/dim_reduction/swiss_roll_plot.png -------------------------------------------------------------------------------- /images/distributed/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/end_to_end_project/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/end_to_end_project/attribute_histogram_plots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/attribute_histogram_plots.png -------------------------------------------------------------------------------- /images/end_to_end_project/bad_visualization_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/bad_visualization_plot.png -------------------------------------------------------------------------------- /images/end_to_end_project/better_visualization_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/better_visualization_plot.png -------------------------------------------------------------------------------- /images/end_to_end_project/california.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/california.png -------------------------------------------------------------------------------- /images/end_to_end_project/california_housing_prices_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/california_housing_prices_plot.png -------------------------------------------------------------------------------- /images/end_to_end_project/housing_prices_scatterplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/housing_prices_scatterplot.png -------------------------------------------------------------------------------- /images/end_to_end_project/income_category_hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/income_category_hist.png -------------------------------------------------------------------------------- /images/end_to_end_project/income_vs_house_value_scatterplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/income_vs_house_value_scatterplot.png -------------------------------------------------------------------------------- /images/end_to_end_project/scatter_matrix_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/end_to_end_project/scatter_matrix_plot.png -------------------------------------------------------------------------------- /images/ensembles/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/ensembles/boosting_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/boosting_plot.png -------------------------------------------------------------------------------- /images/ensembles/decision_tree_without_and_with_bagging_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/decision_tree_without_and_with_bagging_plot.png -------------------------------------------------------------------------------- /images/ensembles/early_stopping_gbrt_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/early_stopping_gbrt_plot.png -------------------------------------------------------------------------------- /images/ensembles/gbrt_learning_rate_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/gbrt_learning_rate_plot.png -------------------------------------------------------------------------------- /images/ensembles/gradient_boosting_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/gradient_boosting_plot.png -------------------------------------------------------------------------------- /images/ensembles/law_of_large_numbers_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/law_of_large_numbers_plot.png -------------------------------------------------------------------------------- /images/ensembles/mnist_feature_importance_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/ensembles/mnist_feature_importance_plot.png -------------------------------------------------------------------------------- /images/fundamentals/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/fundamentals/best_fit_model_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/best_fit_model_plot.png -------------------------------------------------------------------------------- /images/fundamentals/cyprus_prediction_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/cyprus_prediction_plot.png -------------------------------------------------------------------------------- /images/fundamentals/money_happy_scatterplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/money_happy_scatterplot.png -------------------------------------------------------------------------------- /images/fundamentals/overfitting_model_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/overfitting_model_plot.png -------------------------------------------------------------------------------- /images/fundamentals/representative_training_data_scatterplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/representative_training_data_scatterplot.png -------------------------------------------------------------------------------- /images/fundamentals/ridge_model_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/ridge_model_plot.png -------------------------------------------------------------------------------- /images/fundamentals/tweaking_model_params_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/fundamentals/tweaking_model_params_plot.png -------------------------------------------------------------------------------- /images/rl/MsPacman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/rl/MsPacman.png -------------------------------------------------------------------------------- /images/rl/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/rl/cart_pole_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/rl/cart_pole_plot.png -------------------------------------------------------------------------------- /images/rl/preprocessing_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/rl/preprocessing_plot.png -------------------------------------------------------------------------------- /images/rnn/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/rnn/creative_sequence_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/rnn/creative_sequence_plot.png -------------------------------------------------------------------------------- /images/rnn/time_series_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/rnn/time_series_plot.png -------------------------------------------------------------------------------- /images/rnn/time_series_pred_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/rnn/time_series_pred_plot.png -------------------------------------------------------------------------------- /images/svm/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/svm/higher_dimensions_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/higher_dimensions_plot.png -------------------------------------------------------------------------------- /images/svm/hinge_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/hinge_plot.png -------------------------------------------------------------------------------- /images/svm/iris_3D_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/iris_3D_plot.png -------------------------------------------------------------------------------- /images/svm/kernel_method_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/kernel_method_plot.png -------------------------------------------------------------------------------- /images/svm/large_margin_classification_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/large_margin_classification_plot.png -------------------------------------------------------------------------------- /images/svm/moons_kernelized_polynomial_svc_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/moons_kernelized_polynomial_svc_plot.png -------------------------------------------------------------------------------- /images/svm/moons_polynomial_svc_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/moons_polynomial_svc_plot.png -------------------------------------------------------------------------------- /images/svm/moons_rbf_svc_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/moons_rbf_svc_plot.png -------------------------------------------------------------------------------- /images/svm/regularization_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/regularization_plot.png -------------------------------------------------------------------------------- /images/svm/sensitivity_to_feature_scales_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/sensitivity_to_feature_scales_plot.png -------------------------------------------------------------------------------- /images/svm/sensitivity_to_outliers_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/sensitivity_to_outliers_plot.png -------------------------------------------------------------------------------- /images/svm/small_w_large_margin_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/small_w_large_margin_plot.png -------------------------------------------------------------------------------- /images/svm/svm_regression_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/svm_regression_plot.png -------------------------------------------------------------------------------- /images/svm/svm_with_polynomial_kernel_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/svm/svm_with_polynomial_kernel_plot.png -------------------------------------------------------------------------------- /images/tensorflow/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/training_linear_models/README: -------------------------------------------------------------------------------- 1 | Images generated by the notebooks 2 | -------------------------------------------------------------------------------- /images/training_linear_models/early_stopping_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/early_stopping_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/generated_data_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/generated_data_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/gradient_descent_paths_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/gradient_descent_paths_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/gradient_descent_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/gradient_descent_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/high_degree_polynomials_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/high_degree_polynomials_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/lasso_regression_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/lasso_regression_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/lasso_vs_ridge_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/lasso_vs_ridge_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/learning_curves_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/learning_curves_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/linear_model_predictions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/linear_model_predictions.png -------------------------------------------------------------------------------- /images/training_linear_models/logistic_function_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/logistic_function_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/logistic_regression_contour_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/logistic_regression_contour_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/logistic_regression_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/logistic_regression_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/quadratic_data_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/quadratic_data_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/quadratic_predictions_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/quadratic_predictions_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/ridge_regression_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/ridge_regression_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/sgd_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/sgd_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/softmax_regression_contour_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/softmax_regression_contour_plot.png -------------------------------------------------------------------------------- /images/training_linear_models/underfitting_learning_curves_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickiepark/handson-ml/71648c4373c82c8ffeaa00c78d3722cb9347f2e6/images/training_linear_models/underfitting_learning_curves_plot.png -------------------------------------------------------------------------------- /index.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 핸즈온 머신러닝 노트북\n", 8 | "\n", 9 | "*핸즈온 머신러닝 레파지토리에 오신걸 환영합니다!*\n", 10 | "\n", 11 | "[필요한 기술](#Prerequisites) (아래를 참고하세요)\n", 12 | "\n", 13 | "## 노트북\n", 14 | "1. [한눈에 보는 머신러닝](01_the_machine_learning_landscape.ipynb)\n", 15 | "2. [머신러닝 프로젝트 처음부터 끝까지](02_end_to_end_machine_learning_project.ipynb)\n", 16 | "3. [분류](03_classification.ipynb)\n", 17 | "4. [모델 훈련](04_training_linear_models.ipynb)\n", 18 | "5. [서포트 벡터 머신](05_support_vector_machines.ipynb)\n", 19 | "6. [결정 트리](06_decision_trees.ipynb)\n", 20 | "7. [앙상블 학습과 랜덤 포레스트](07_ensemble_learning_and_random_forests.ipynb)\n", 21 | "8. [차원 축소](08_dimensionality_reduction.ipynb)\n", 22 | "9. [텐서플로 시작하기](09_up_and_running_with_tensorflow.ipynb)\n", 23 | "10. [인공 신경망 소개](10_introduction_to_artificial_neural_networks.ipynb)\n", 24 | "11. [심층 신경망 훈련](11_deep_learning.ipynb)\n", 25 | "12. [다중 머신과 장치를 위한 분산 텐서플로](12_distributed_tensorflow.ipynb)\n", 26 | "13. [합성곱 신경망](13_convolutional_neural_networks.ipynb)\n", 27 | "14. [순환 신경망](14_recurrent_neural_networks.ipynb)\n", 28 | "15. [오토인코더](15_autoencoders.ipynb)\n", 29 | "16. [강화 학습](16_reinforcement_learning.ipynb)\n", 30 | "\n", 31 | "## 파이썬 과학 라이브러리 튜토리얼\n", 32 | "* [넘파이(NumPy)](tools_numpy.ipynb)\n", 33 | "* [맷플롯립(Matplotlib)](tools_matplotlib.ipynb)\n", 34 | "* [판다스(Pandas)](tools_pandas.ipynb)\n", 35 | "\n", 36 | "## 수학 튜토리얼\n", 37 | "* [선형 대수](math_linear_algebra.ipynb)\n", 38 | "* 미적분 (coming soon)\n", 39 | "\n", 40 | "## 부가 자료\n", 41 | "* [캡슐 네트워크(Capsule Networks)](extra_capsnets.ipynb)\n", 42 | "\n", 43 | "## 그외\n", 44 | "* [수식](book_equations.ipynb) (책에 나온 수식을 모아 놓았습니다)\n" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": { 50 | "collapsed": true 51 | }, 52 | "source": [ 53 | "## 필요한 기술\n", 54 | "### 이해를 위해서는\n", 55 | "* **파이썬** – 파이썬 전문가일 필요는 없지만 기초적인 내용은 알고 있어야 합니다. 파이썬이 처음이라면 [파이썬 공식 튜토리얼](https://docs.python.org/3/tutorial/)을 참고하세요. 다른 프로그래밍 언어를 조금 알고 있다면 [번갯불에 파이썬 구워먹기](https://github.com/rickiepark/WhirlwindTourOfPython)를 참고하면 금방 배울 수 있습니다.\n", 56 | "* **파이썬 과학 패키지** – 여기서는 유명한 파이썬 라이브러리를 사용합니다. 특히 넘파이, 맷플롯립, 판다스를 사용합니다. 이런 라이브러리에 익숙하지 않다면 \"파이썬 과학 라이브러리 튜토리얼\"을 먼저 참고하세요(특히 넘파이).\n", 57 | "* **수학** – 이 책은 선형 대수, 미적분, 통계, 확률 이론 개념을 조금 사용합니다. 여기서는 매우 깊게 들어가지 않으므로 이전에 배운적이 있다면 따라갈 수 있을 것입니다. 만약 이 부분을 잘 모른다면 \"수학 튜토리얼\" 섹션에 있는 자료를 참고하세요.\n", 58 | "\n", 59 | "### 예제를 실행하기 위해서는\n", 60 | "* **주피터** – 이 노트북들은 주피터를 기반으로 합니다. 코드를 그냥 읽기만 한다면 더이상 무언가를 할 필요는 없습니다. 하지만 이 코드를 테스트해 보려면: * [설치](https://github.com/rickiepark/handson-ml/#%EC%84%A4%EC%B9%98)을 따라 필요한 패키지를 설치하세요.\n", 61 | " * 주피터를 사용하는 법을 배워야합니다. Help 메뉴에서 User Interface Tour를 선택해 보세요." 62 | ] 63 | } 64 | ], 65 | "metadata": { 66 | "kernelspec": { 67 | "display_name": "Python 3", 68 | "language": "python", 69 | "name": "python3" 70 | }, 71 | "language_info": { 72 | "codemirror_mode": { 73 | "name": "ipython", 74 | "version": 3 75 | }, 76 | "file_extension": ".py", 77 | "mimetype": "text/x-python", 78 | "name": "python", 79 | "nbconvert_exporter": "python", 80 | "pygments_lexer": "ipython3", 81 | "version": "3.5.5" 82 | }, 83 | "nav_menu": {}, 84 | "toc": { 85 | "navigate_menu": true, 86 | "number_sections": true, 87 | "sideBar": true, 88 | "threshold": 6, 89 | "toc_cell": false, 90 | "toc_section_display": "block", 91 | "toc_window_display": false 92 | } 93 | }, 94 | "nbformat": 4, 95 | "nbformat_minor": 1 96 | } 97 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # First make sure to update pip: 2 | # $ sudo pip install --upgrade pip 3 | # 4 | # Then you probably want to work in a virtualenv (optional): 5 | # $ sudo pip install --upgrade virtualenv 6 | # Or if you prefer you can install virtualenv using your favorite packaging 7 | # system. E.g., in Ubuntu: 8 | # $ sudo apt-get update && sudo apt-get install virtualenv 9 | # Then: 10 | # $ cd $my_work_dir 11 | # $ virtualenv my_env 12 | # $ . my_env/bin/activate 13 | # 14 | # Next, optionally uncomment the OpenAI gym lines (see below). 15 | # If you do, make sure to install the dependencies first. 16 | # If you are interested in xgboost for high performance Gradient Boosting, you 17 | # should uncomment the xgboost line (used in the ensemble learning notebook). 18 | # 19 | # Then install these requirements: 20 | # $ pip install --upgrade -r requirements.txt 21 | # 22 | # Finally, start jupyter: 23 | # $ jupyter notebook 24 | # 25 | 26 | 27 | ##### Core scientific packages 28 | jupyter==1.0.0 29 | matplotlib==2.2.2 30 | numpy==1.14.5 31 | pandas==0.22.0 32 | scipy==1.1.0 33 | 34 | 35 | ##### Machine Learning packages 36 | scikit-learn==0.19.1 37 | 38 | # Optional: the XGBoost library is only used in the ensemble learning chapter. 39 | #xgboost==0.71 40 | 41 | 42 | ##### Deep Learning packages 43 | 44 | # Replace tensorflow with tensorflow-gpu if you want GPU support. If so, 45 | # you need a GPU card with CUDA Compute Capability 3.0 or higher support, and 46 | # you must install CUDA, cuDNN and more: see tensorflow.org for the detailed 47 | # installation instructions. 48 | tensorflow==1.10.0 49 | #tensorflow-gpu==1.10.0 50 | 51 | # Forcing bleach to 1.5 to avoid version incompatibility when installing 52 | # TensorBoard. 53 | bleach==1.5.0 54 | 55 | Keras==2.1.6 56 | 57 | 58 | # Optional: OpenAI gym is only needed for the Reinforcement Learning chapter. 59 | # There are a few dependencies you need to install first, check out: 60 | # https://github.com/openai/gym#installing-everything 61 | #gym[all]==0.10.5 62 | # If you only want to install the Atari dependency, uncomment this line instead: 63 | #gym[atari]==0.10.5 64 | 65 | 66 | ##### Image manipulation 67 | imageio==2.3.0 68 | Pillow==5.1.0 69 | scikit-image==0.13.1 70 | 71 | 72 | ##### Extra packages (optional) 73 | 74 | # Nice utility to diff Jupyter Notebooks. 75 | nbdime==0.4.1 76 | 77 | # May be useful with Pandas for complex "where" clauses (e.g., Pandas 78 | # tutorial). 79 | numexpr==2.6.5 80 | 81 | # These libraries can be useful in the classification chapter, exercise 4. 82 | nltk==3.3 83 | urlextract==0.8.3 84 | 85 | # Optional: these are useful Jupyter extensions, in particular to display 86 | # the table of contents. 87 | jupyter-contrib-nbextensions==0.5.0 88 | -------------------------------------------------------------------------------- /tensorflow_graph_in_jupyter.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, division, print_function, unicode_literals 2 | 3 | # This module defines the show_graph() function to visualize a TensorFlow graph within Jupyter. 4 | 5 | # As far as I can tell, this code was originally written by Alex Mordvintsev at: 6 | # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/deepdream/deepdream.ipynb 7 | 8 | # The original code only worked on Chrome (because of the use of , but the version below 9 | # uses Polyfill (copied from this StackOverflow answer: https://stackoverflow.com/a/41463991/38626) 10 | # so that it can work on other browsers as well. 11 | 12 | import numpy as np 13 | import tensorflow as tf 14 | from IPython.display import clear_output, Image, display, HTML 15 | 16 | def strip_consts(graph_def, max_const_size=32): 17 | """Strip large constant values from graph_def.""" 18 | strip_def = tf.GraphDef() 19 | for n0 in graph_def.node: 20 | n = strip_def.node.add() 21 | n.MergeFrom(n0) 22 | if n.op == 'Const': 23 | tensor = n.attr['value'].tensor 24 | size = len(tensor.tensor_content) 25 | if size > max_const_size: 26 | tensor.tensor_content = b""%size 27 | return strip_def 28 | 29 | def show_graph(graph_def, max_const_size=32): 30 | """Visualize TensorFlow graph.""" 31 | if hasattr(graph_def, 'as_graph_def'): 32 | graph_def = graph_def.as_graph_def() 33 | strip_def = strip_consts(graph_def, max_const_size=max_const_size) 34 | code = """ 35 | 36 | 41 | 42 |
43 | 44 |
45 | """.format(data=repr(str(strip_def)), id='graph'+str(np.random.rand())) 46 | 47 | iframe = """ 48 | 49 | """.format(code.replace('"', '"')) 50 | display(HTML(iframe)) 51 | --------------------------------------------------------------------------------