diff --git a/code/R-notebook/r-03.ipynb b/code/R-notebook/r-03.ipynb index c38bd04..b71be39 100644 --- a/code/R-notebook/r-03.ipynb +++ b/code/R-notebook/r-03.ipynb @@ -1,7 +1,7 @@ { "cells": [ { - "id": "618119d6", + "id": "a6fef8a4", "cell_type": "markdown", "source": "[\u8fbb\u771f\u543e\u30fb\u77e2\u5439\u592a\u6717\u300e\u30bc\u30ed\u304b\u3089\u306f\u3058\u3081\u308b\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u5165\u9580\u300f\uff08\u8b1b\u8ac7\u793e,\u00a02021\uff09](https://github.com/taroyabuki/fromzero)", "metadata": {} @@ -21,10 +21,10 @@ " install.packages(c(\"ggplot2\"))\n", "}" ], - "id": "61861552-833b-4f7d-bf6a-3bb9b8cab174" + "id": "d5273778-f69b-4094-b629-b3f4dd7d0e1d" }, { - "id": "a87e65a7", + "id": "1de90bf7", "cell_type": "markdown", "source": "## 3.1 \u5165\u9580", "metadata": {} @@ -37,7 +37,7 @@ "source": [ "0x10" ], - "id": "3bc86324-84fd-475b-b447-62e78aad43ac" + "id": "3b4c306e-dc91-4bc1-b9c0-dfd3ea76699d" }, { "cell_type": "code", @@ -47,7 +47,7 @@ "source": [ "1.23e5" ], - "id": "6b822b95-9294-4690-bdd2-a2bc055fb100" + "id": "9dc00605-20e5-44a9-8e2c-d4c62d123f0b" }, { "cell_type": "code", @@ -57,7 +57,7 @@ "source": [ "2 * 3" ], - "id": "160e6604-6810-4f1a-80bb-c12cb5ebcf84" + "id": "e23dcc49-e9cf-4493-a28d-de8cbe96888e" }, { "cell_type": "code", @@ -67,7 +67,7 @@ "source": [ "10 / 3" ], - "id": "25c06183-7b89-457b-8421-1a1feeaa5dc1" + "id": "730b0a8a-f9fa-4819-9561-ae89631b3a80" }, { "cell_type": "code", @@ -79,7 +79,7 @@ "\n", "10 %% 3 # \u4f59\u308a" ], - "id": "7f8b384a-06b3-4f55-879c-d2913d020b43" + "id": "ef642593-9847-42d7-b9a3-4bd95a47263a" }, { "cell_type": "code", @@ -95,7 +95,7 @@ "c(x, y) %<-% c(20, 30) # \u307e\u3068\u3081\u3066\u540d\u4ed8\u3051\n", "x * y" ], - "id": "5aa24be4-223b-4af4-b069-f1cf182603bb" + "id": "a7b07ad9-4d09-483e-8649-26ce1840449b" }, { "cell_type": "code", @@ -108,7 +108,7 @@ "\n", "x # \u5909\u6570\u540d\u3092\u8a55\u4fa1\u3059\u308b\uff0e" ], - "id": "634327f4-60b0-4e89-971d-e43836648231" + "id": "6c76790f-a971-41dc-8464-55b09d72debd" }, { "cell_type": "code", @@ -118,7 +118,7 @@ "source": [ "my_s <- \"abcde\"" ], - "id": "074b5135-4608-43d9-b5e5-8a0df2b62a96" + "id": "75c862f7-519e-471a-9749-bf796e01acc0" }, { "cell_type": "code", @@ -128,7 +128,7 @@ "source": [ "nchar(my_s)" ], - "id": "68dba085-8542-4e93-9fef-c61b0f8df447" + "id": "e0067754-e2f0-4af0-bc20-db15798011a1" }, { "cell_type": "code", @@ -139,7 +139,7 @@ "library(tidyverse)\n", "str_c(\"This is \", \"a\", \" pen.\")" ], - "id": "30d4d756-bab1-46e7-9ccc-42635207db66" + "id": "83f7084b-6d31-4891-a45f-8ba4dbc68c5c" }, { "cell_type": "code", @@ -149,7 +149,7 @@ "source": [ "substr(x = my_s, start = 2, stop = 4)" ], - "id": "573a9fde-0f56-429e-8649-e513cbbafb44" + "id": "324ee6f1-f9c1-4e4b-8101-b04c8d07f539" }, { "cell_type": "code", @@ -160,7 +160,7 @@ "tmp <- \"%s is %s.\"\n", "sprintf(tmp, \"This\", \"a pen\")" ], - "id": "5ecc420b-cdd5-4f2d-9379-71d7d17f2fd8" + "id": "f87e2fcf-02fc-4ed8-9b79-e027f3d206fd" }, { "cell_type": "code", @@ -172,7 +172,7 @@ "\n", "1 < 0" ], - "id": "46c68971-89e4-48aa-86b1-3726a22e2fd7" + "id": "4bb46e2a-cad9-4f0c-80fb-e2e04481077a" }, { "cell_type": "code", @@ -184,7 +184,7 @@ "\n", "all.equal(0.1 + 0.1 + 0.1, 0.3)" ], - "id": "6e6c1b49-71d1-4bd4-8f19-1a7c79876903" + "id": "80fe3139-97eb-4f12-964d-557760ba5bd2" }, { "cell_type": "code", @@ -198,7 +198,7 @@ "\n", "!TRUE # \u5426\u5b9a\uff08\u3067\u306a\u3044\uff09" ], - "id": "4402473b-fd07-4caf-9529-b0ecdaf01daa" + "id": "4f49aeb7-15ff-4c6b-9aa3-4e5b2f2b765f" }, { "cell_type": "code", @@ -208,7 +208,7 @@ "source": [ "ifelse(3 < 5, 0, 10)" ], - "id": "49545880-01a6-4d5f-919c-b7b6238f5776" + "id": "1a44e29d-bd4f-465f-bea2-fb6e23ef03ba" }, { "cell_type": "code", @@ -218,7 +218,7 @@ "source": [ "getwd()" ], - "id": "1a8dfa71-946a-4923-b5bb-f16575583251" + "id": "f97e882d-325b-47bc-83ac-185282fd1f0c" }, { "cell_type": "code", @@ -229,10 +229,10 @@ "setwd(\"..\")\n", "getwd()" ], - "id": "f9389260-b21d-418a-b13a-6ed330203fd8" + "id": "6587b778-6541-47b3-9a89-7b2566969203" }, { - "id": "ead61c3a", + "id": "b0d4397b", "cell_type": "markdown", "source": "## 3.2 \u95a2\u6570", "metadata": {} @@ -245,7 +245,7 @@ "source": [ "sqrt(4)" ], - "id": "06285ed6-d0aa-4a47-890e-f58f5fc0bd35" + "id": "62aa00a5-a9e3-4a48-97ce-83d55ce27444" }, { "cell_type": "code", @@ -255,7 +255,7 @@ "source": [ "log(100, 10)" ], - "id": "20d09558-e1b2-44f9-b35e-0171c78cdf3c" + "id": "0d6c636a-11b9-4978-bbcb-e5e22e04e8b8" }, { "cell_type": "code", @@ -267,7 +267,7 @@ "# \u3042\u308b\u3044\u306f\n", "log(100, exp(1)) # \u7701\u7565\u3057\u306a\u3044\u5834\u5408\n" ], - "id": "bcac6f76-fd98-477c-bdb0-ba220c4a3128" + "id": "0dd229ef-8abb-459d-8f65-bebd8538093f" }, { "cell_type": "code", @@ -279,7 +279,7 @@ "\n", "log2(1024) # \u5e95\u304c2\u306e\u5bfe\u6570" ], - "id": "9f4de2ce-bf26-4bd2-943c-f38295ecd1dc" + "id": "0f8e844d-e888-4fc8-8eda-2f2430a88ba1" }, { "cell_type": "code", @@ -290,7 +290,7 @@ "library(tidyverse)\n", "4 %>% sqrt" ], - "id": "68672b4d-4035-4500-b502-732cabf3b0cd" + "id": "23cd5c9f-7b33-4513-a991-60d5ff6f2bac" }, { "cell_type": "code", @@ -302,7 +302,7 @@ "# \u3042\u308b\u3044\u306f\n", "5 %>% log %>% exp # \u30d1\u30a4\u30d7\u3092\u4f7f\u3046\u66f8\u304d\u65b9\n" ], - "id": "1cb9d631-9c0b-44e9-b31b-c366681c79f4" + "id": "984bb371-a29d-4e8f-9d37-9b9ed351485d" }, { "cell_type": "code", @@ -314,7 +314,7 @@ " a - b\n", "}" ], - "id": "3558081c-a98a-451d-aa33-48c215339af6" + "id": "8c603dbb-948b-4b56-9435-8176959e61f9" }, { "cell_type": "code", @@ -324,7 +324,7 @@ "source": [ "f(3, 5)" ], - "id": "a7af7378-b379-4f1f-a798-eda4ac9d2e63" + "id": "f6bd5b63-0d01-4606-baad-b13293d3cfcd" }, { "cell_type": "code", @@ -338,7 +338,7 @@ "\n", "f(3) # f(3, 5)\u3068\u540c\u3058\u3053\u3068" ], - "id": "6bddb36e-f0b2-4e95-bd4c-d9c23523e6af" + "id": "5f6a3057-c69b-451e-bea4-eddf5d305328" }, { "cell_type": "code", @@ -348,10 +348,10 @@ "source": [ "(function(a, b) { a - b })(3, 5)" ], - "id": "41e1ce95-d545-4155-afd2-1c4c9ade4aff" + "id": "8696eb6f-46fd-46ed-82af-ffb4dc893b5a" }, { - "id": "edd569f8", + "id": "adac5ec7", "cell_type": "markdown", "source": "## 3.3 \u30b3\u30ec\u30af\u30b7\u30e7\u30f3", "metadata": {} @@ -364,7 +364,7 @@ "source": [ "x <- c(\"foo\", \"bar\", \"baz\")" ], - "id": "f690cecf-48d6-49b7-a9d1-1ebc578106a3" + "id": "56302802-112b-430d-a7f8-e1496ca71a9c" }, { "cell_type": "code", @@ -374,7 +374,7 @@ "source": [ "length(x)" ], - "id": "e3efaa24-67cb-4676-b9c7-89d02d451f37" + "id": "596da5c7-82b3-403e-839e-cf824a5cf641" }, { "cell_type": "code", @@ -384,7 +384,7 @@ "source": [ "x[2]" ], - "id": "1b9850f4-fc53-4102-85c8-11b3efaf4397" + "id": "6d4ad99d-95a9-4fd2-b291-bf6069dac31c" }, { "cell_type": "code", @@ -397,7 +397,7 @@ "\n", "x[2] <- \"bar\" # \u5143\u306b\u623b\u3059\uff0e" ], - "id": "184b44ea-0e4c-4f00-a112-5a9aa4c20538" + "id": "131e9d37-435b-4faf-bb69-2e6f0e88581e" }, { "cell_type": "code", @@ -407,7 +407,7 @@ "source": [ "x[-2]" ], - "id": "b5100d18-baea-4145-ae14-d607330db80d" + "id": "6bc90401-401c-464c-8c61-59aad8d5205a" }, { "cell_type": "code", @@ -417,7 +417,7 @@ "source": [ "c(x, \"qux\")" ], - "id": "bb9ba6c2-eabb-464d-a001-4df14ba2813f" + "id": "d8e31819-192d-44f5-bed5-20eaae0e868b" }, { "cell_type": "code", @@ -428,7 +428,7 @@ "x <- c(x, \"qux\")\n", "x # \u7d50\u679c\u306e\u78ba\u8a8d" ], - "id": "a7488dad-e6d9-4615-98cd-b6171fae645c" + "id": "3ccfaa4d-40e4-4279-a875-9e7bb7caa471" }, { "cell_type": "code", @@ -438,7 +438,7 @@ "source": [ "1:5" ], - "id": "b088b567-bf39-4768-989b-69906d806dd7" + "id": "93666b4e-f4d4-4cba-82d0-e8972ed0b85e" }, { "cell_type": "code", @@ -448,7 +448,7 @@ "source": [ "seq(from = 0, to = 10, by = 2)" ], - "id": "3026b407-1793-4585-886c-571062b360f1" + "id": "2d0d1504-7f5e-44df-adde-da2f02894d42" }, { "cell_type": "code", @@ -458,7 +458,7 @@ "source": [ "seq(from = 0, to = 1, by = 0.5)" ], - "id": "f25d439a-14e3-49bb-99a1-0525e6021b00" + "id": "7237244b-0c4a-40ba-9481-a2800919c0b5" }, { "cell_type": "code", @@ -468,7 +468,7 @@ "source": [ "seq(from = 0, to = 100, length.out = 5)" ], - "id": "c2f44aa5-e1b7-4ccf-9014-4c4636bfbe05" + "id": "b916306b-c829-4ad8-b5d8-4edb6273e842" }, { "cell_type": "code", @@ -478,7 +478,7 @@ "source": [ "rep(x = 10, times = 5)" ], - "id": "4d9e9aea-c9c4-4626-80bb-aac8f25abda4" + "id": "87ab600b-c306-4125-bb51-94d8f3630ed2" }, { "cell_type": "code", @@ -490,7 +490,7 @@ "x <- factor(tmp, levels = c(\"\u30b0\u30fc\", \"\u30c1\u30e7\u30ad\", \"\u30d1\u30fc\"))\n", "x" ], - "id": "276f833c-d8c6-4cb2-b0c4-2de74c674cb9" + "id": "73190606-3ae8-46e6-9683-7379b5ee55b0" }, { "cell_type": "code", @@ -504,7 +504,7 @@ "\n", "x * 10 # \u4e57\u7b97" ], - "id": "02855241-8e36-4555-8460-75af9d7230d1" + "id": "2c088bf4-34e8-488e-8d76-dfa66e58a909" }, { "cell_type": "code", @@ -515,7 +515,7 @@ "x <- c(2, 3)\n", "sin(x)" ], - "id": "b341fba9-f6b5-447e-9f9a-2edc93f7b5f5" + "id": "a3f176f4-88ff-40f6-9299-57e9cbbdaa41" }, { "cell_type": "code", @@ -529,7 +529,7 @@ "\n", "x * y" ], - "id": "b53bdb29-c368-4e85-b2d0-13d487d7fabd" + "id": "fd2a5024-a6b8-4a2d-a10e-9cd985a6d2a5" }, { "cell_type": "code", @@ -539,7 +539,7 @@ "source": [ "sum(x * y)" ], - "id": "73c67010-3e8f-45ab-81a1-e4fe4c0bd37e" + "id": "1f87b8b7-c19e-4a2c-a632-c06c84be0b1f" }, { "cell_type": "code", @@ -551,7 +551,7 @@ "y <- c(TRUE, TRUE)\n", "x & y" ], - "id": "381c631f-1aff-4ed9-81e1-fc02f763b303" + "id": "82392d11-919a-4824-88e1-b6244dce587f" }, { "cell_type": "code", @@ -571,7 +571,7 @@ "\n", "u == w # \u8981\u7d20\u3054\u3068\u306e\u6bd4\u8f03" ], - "id": "f4b1f422-a7ef-41ae-a01e-f34889f4a215" + "id": "80730168-87ac-4016-8e85-f0ce72fb65d9" }, { "cell_type": "code", @@ -583,7 +583,7 @@ "\n", "mean(u == w) # \u540c\u3058\u8981\u7d20\u306e\u5272\u5408" ], - "id": "b5ffdf92-48c7-412c-8f8a-4f465b9cb8e5" + "id": "c1a6580a-1e1d-47dc-ae3f-3b267a277410" }, { "cell_type": "code", @@ -593,7 +593,7 @@ "source": [ "x <- list(1, \"two\")" ], - "id": "56574a73-6a9e-4d5d-bf65-74ca269effcb" + "id": "0cd1bd6e-fb17-4b9a-b4a3-b74d805557d4" }, { "cell_type": "code", @@ -603,7 +603,7 @@ "source": [ "x[[2]]" ], - "id": "e9f4e10c-0d10-478a-b5ca-11918560b34b" + "id": "45bb5dfd-e70d-4894-bf8e-f2dc1e548b35" }, { "cell_type": "code", @@ -614,7 +614,7 @@ "x <- list(\"apple\" = \"\u308a\u3093\u3054\",\n", " \"orange\" = \"\u307f\u304b\u3093\")" ], - "id": "562c4af6-9545-4a45-b2a7-e40157ddc843" + "id": "0c518547-28a5-4287-a211-dc3eedf48f11" }, { "cell_type": "code", @@ -624,7 +624,7 @@ "source": [ "x[[\"grape\"]] <- \"\u3076\u3069\u3046\"" ], - "id": "8d33707d-582a-4484-8ebc-c396b29910a2" + "id": "d7877f83-22ea-44f7-a35c-6352a0f11939" }, { "cell_type": "code", @@ -641,7 +641,7 @@ "tmp <- \"apple\"\n", "x[[tmp]]\n" ], - "id": "c9c01202-8974-430e-87e4-05a2455d0f60" + "id": "b15a3222-fe7b-4718-9d30-9eea66533f2d" }, { "cell_type": "code", @@ -656,10 +656,10 @@ "\n", "x # x\u306f\u5909\u308f\u3089\u306a\u3044\uff0e" ], - "id": "dfbbebf8-46b1-430a-a5d5-01b69f8a2bd5" + "id": "c0c8378e-3452-4493-8a68-8b22535ab24e" }, { - "id": "5d5143b8", + "id": "a4be963e", "cell_type": "markdown", "source": "## 3.4 \u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0", "metadata": {} @@ -672,7 +672,7 @@ "source": [ "library(tidyverse)" ], - "id": "23b3ad0c-fdb8-41b0-bd6d-2200f3301bcd" + "id": "17f57ec3-57a9-47a7-a9e3-02e79f7c623b" }, { "cell_type": "code", @@ -686,7 +686,7 @@ " math = c( 70, 80, 90, 100),\n", " gender = c(\"f\", \"m\", \"m\", \"f\"))" ], - "id": "f558fb78-4db4-453c-8a31-2e927c6caee0" + "id": "a07ff99b-45a5-42be-b2ae-c36d6726348b" }, { "cell_type": "code", @@ -701,7 +701,7 @@ " \"C\", 70, 90, \"m\",\n", " \"D\", 90, 100, \"f\")" ], - "id": "59d3e1c2-5de2-4438-a4ba-bae727dcfa68" + "id": "88bd12c8-d6d7-4318-8084-11b438ad4435" }, { "cell_type": "code", @@ -712,7 +712,7 @@ "head(my_df)\n", "# \u7d50\u679c\u306f\u5272\u611b" ], - "id": "72602599-2139-4740-b9bf-14b44d2d075b" + "id": "023ebbb7-277f-4ef2-936a-0e0759bdb299" }, { "cell_type": "code", @@ -726,7 +726,7 @@ "\n", "ncol(my_df) # \u5217\u6570" ], - "id": "e2c0383c-67d3-4f34-ae81-46a17f01ba71" + "id": "8e584d2a-11d7-46bc-be18-f8d025e4f81a" }, { "cell_type": "code", @@ -739,7 +739,7 @@ " Y = c(10, 100))\n", "my_df2" ], - "id": "66bb1831-3c6f-49c0-a3a3-7d40f128f5f4" + "id": "4e6721d1-0617-4f07-b3c4-28ab148c6225" }, { "cell_type": "code", @@ -749,7 +749,7 @@ "source": [ "colnames(my_df2)" ], - "id": "01ec8b68-389e-4299-bf67-3a10269c4de8" + "id": "fc32d68a-9da2-46fe-b1b7-d8f451c68a36" }, { "cell_type": "code", @@ -761,7 +761,7 @@ "my_df2\n", "# \u4ee5\u4e0b\u7701\u7565" ], - "id": "e2a3247e-62bd-4992-a5b3-f58fa8677b5f" + "id": "306fb393-4881-46a8-a7d8-52d448bb99cc" }, { "cell_type": "code", @@ -771,7 +771,7 @@ "source": [ "row.names(my_df)" ], - "id": "6db4d695-7a96-426e-9028-4f2eefe466ec" + "id": "8be4e398-12be-4df3-9188-7e3702aad7af" }, { "cell_type": "code", @@ -784,7 +784,7 @@ "my_df2\n", "# \u4ee5\u4e0b\u7701\u7565" ], - "id": "eda76f7f-1aef-4df2-b8e4-d2301b2a0363" + "id": "a4b71bbd-866c-4cf9-9d90-bd3a00ebe538" }, { "cell_type": "code", @@ -799,7 +799,7 @@ " row.names = c(\"A\", \"B\", \"C\", \"D\"))\n", "my_df3" ], - "id": "cb1777e5-0653-4c0f-8cd1-938e487f9f5c" + "id": "c2f4c4e5-0993-4328-b0da-a29c9261ab0d" }, { "cell_type": "code", @@ -814,7 +814,7 @@ " gender = \"m\")\n", "my_df2 <- rbind(my_df, tmp)" ], - "id": "8483b088-2422-4722-b792-a9a42a55722c" + "id": "842111c8-a5e6-4e7f-8724-af945c391923" }, { "cell_type": "code", @@ -825,7 +825,7 @@ "my_df2 <- my_df %>%\n", " mutate(id = c(1, 2, 3, 4))" ], - "id": "71cb4246-edf0-4fa3-913b-e33e5974ebbb" + "id": "53d63316-db1a-4101-acf6-1a39cc37cfc0" }, { "cell_type": "code", @@ -837,7 +837,7 @@ "my_df3[\"id\"] <- c(1, 2, 3, 4) # \u66f4\u65b0\n", "my_df3 # \u7d50\u679c\u306e\u78ba\u8a8d\uff08\u5272\u611b\uff09" ], - "id": "42ffbb42-5500-430f-89d4-3f55f8c7fd88" + "id": "6126e356-22e4-4fe2-962b-994ae2ff9ef5" }, { "cell_type": "code", @@ -847,7 +847,7 @@ "source": [ "my_df[1, 2]" ], - "id": "177ac7e8-87e4-4213-8932-adbad96253ef" + "id": "68e9f75d-dec0-4acd-b6d4-316d465f228d" }, { "cell_type": "code", @@ -868,7 +868,7 @@ "\n", "x # \u7d50\u679c\u306e\u78ba\u8a8d\uff08\u5272\u611b\uff09" ], - "id": "0b4ea29a-d4dd-42e3-a1c6-baba5e7c1cb7" + "id": "e4ff1eab-79e8-400b-b21e-53d37c6ba8d1" }, { "cell_type": "code", @@ -878,7 +878,7 @@ "source": [ "x <- my_df %>% select(name, math)" ], - "id": "184acfd0-ec5c-41e1-bd1d-dba248edb8f1" + "id": "bc8f1ce3-4f6e-45b1-93d9-a73a168f45a1" }, { "cell_type": "code", @@ -888,7 +888,7 @@ "source": [ "x <- my_df[, c(1, 3)]" ], - "id": "7672b7ff-c086-4df3-89a2-5901473508e2" + "id": "4595c6bc-1daa-41a3-8860-7621efb47c4d" }, { "cell_type": "code", @@ -901,7 +901,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df[, -c(2, 4)]" ], - "id": "5efc1d0c-6144-4af5-b3e3-290264f59c93" + "id": "483e99ae-8f12-4d5d-9f49-ae1c0c5c9168" }, { "cell_type": "code", @@ -911,7 +911,7 @@ "source": [ "x <- my_df[c(1, 3), ]" ], - "id": "88e018ec-2b7e-4170-9fdf-346d7e500262" + "id": "e88f00bc-ffc2-48ee-90db-539c3edf04c5" }, { "cell_type": "code", @@ -921,7 +921,7 @@ "source": [ "x <- my_df[-c(2, 4), ]" ], - "id": "d7f3dc71-7983-4eb2-a356-097286b92d3f" + "id": "3fea5f31-0f22-4a56-b72e-014c1b30958c" }, { "cell_type": "code", @@ -933,7 +933,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df %>% filter(gender == \"m\")" ], - "id": "ae098aaf-1272-4b64-be4b-a7432f5d3266" + "id": "ee78293d-418e-441d-a0c0-ad7b363f1b07" }, { "cell_type": "code", @@ -945,7 +945,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df %>% filter(english > 80 & gender == \"m\")" ], - "id": "be708d82-2761-4113-96d5-be18e19b4f9a" + "id": "ce0e9842-02b1-4623-8aab-33bca0e1c423" }, { "cell_type": "code", @@ -957,7 +957,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df %>% filter(english == max(my_df$english))" ], - "id": "c1cd053f-74f6-49f8-8a98-bce9abe5fedf" + "id": "16a3f2a3-8397-40dd-9e7d-48e6b9ae0391" }, { "cell_type": "code", @@ -968,7 +968,7 @@ "my_df2 <- my_df # \u30b3\u30d4\u30fc\n", "my_df2[my_df$gender == \"m\", ]$gender <- \"M\"" ], - "id": "f41c91c2-10e6-4898-a734-c8dd21c7eb82" + "id": "c2d06e7f-d5a3-42fc-a4a9-fa19a97c7c94" }, { "cell_type": "code", @@ -978,7 +978,7 @@ "source": [ "my_df2" ], - "id": "340db947-53c9-417b-8ea8-91d5c6e8bf7f" + "id": "fdf913f3-5b4a-4c83-bf33-539cf6037864" }, { "cell_type": "code", @@ -988,7 +988,7 @@ "source": [ "x <- my_df %>% arrange(english)" ], - "id": "701f287c-0740-4f82-826e-f6389df97f78" + "id": "4b32a2fc-c4bc-42f7-ba82-b63b60ff1cf4" }, { "cell_type": "code", @@ -998,7 +998,7 @@ "source": [ "x <- my_df %>% arrange(-english)" ], - "id": "fc7b5b46-234f-4d3c-99fc-8b976575bbb8" + "id": "c761f94f-7639-4c26-91f7-4c83303245fa" }, { "cell_type": "code", @@ -1014,7 +1014,7 @@ " byrow = TRUE) # \u884c\u3054\u3068\u306e\u751f\u6210\n", "A" ], - "id": "3c199262-ff78-4892-a287-642440d24c3a" + "id": "d0f211b6-2ded-4a2e-aa59-778f5c7a6db3" }, { "cell_type": "code", @@ -1025,7 +1025,7 @@ "A <- my_df[, c(2, 3)] %>% as.matrix\n", "A" ], - "id": "a1b374e1-a465-47d2-8796-061859691d20" + "id": "5f778752-11f1-4b81-95bd-b5016a89dbab" }, { "cell_type": "code", @@ -1035,7 +1035,7 @@ "source": [ "as.data.frame(A)" ], - "id": "fbc83b6e-480d-484f-bef6-1b712027b542" + "id": "51872921-ac8c-4bfc-980f-68be4d7fa878" }, { "cell_type": "code", @@ -1045,7 +1045,7 @@ "source": [ "t(A)" ], - "id": "8a6b23f6-8c9e-41f9-86a3-f1715d754494" + "id": "efff4b1f-2d73-44bd-9f1e-f7f483ba7438" }, { "cell_type": "code", @@ -1055,7 +1055,7 @@ "source": [ "t(A) %*% A" ], - "id": "83a755a0-76f0-471c-92ba-9b88202c1ffa" + "id": "86a93754-d3ad-40a4-bac9-ed5928623a38" }, { "cell_type": "code", @@ -1068,7 +1068,7 @@ " min = c(20, 21, 15),\n", " max = c(24, 27, 21))" ], - "id": "90546de1-f87e-4e58-b758-ed6ed6d9daed" + "id": "f59cf4ef-dfbe-43f4-9fa8-830e94512290" }, { "cell_type": "code", @@ -1080,7 +1080,7 @@ " pivot_longer(-day)\n", "my_longer" ], - "id": "ae735e1d-6136-489c-a180-0b1a889561b6" + "id": "30ad55a1-6845-4681-b777-6688538450e7" }, { "cell_type": "code", @@ -1090,7 +1090,7 @@ "source": [ "my_longer %>% pivot_wider()" ], - "id": "1ca817df-47da-4088-9ef2-aae6fdaf2915" + "id": "ae190b10-318e-420d-9047-8ba36c5b69db" }, { "cell_type": "code", @@ -1107,10 +1107,10 @@ " scale_x_continuous(\n", " breaks = my_longer$day) # x\u8ef8\u76ee\u76db\u308a" ], - "id": "2c84e1a9-2c99-4cf6-9703-8edb9e1bc4c0" + "id": "3edcf9a7-d416-4448-a4b9-642fc58ab3b0" }, { - "id": "506f9230", + "id": "f58a9a8d", "cell_type": "markdown", "source": "## 3.5 1\u6b21\u5143\u30c7\u30fc\u30bf\u306e\uff08\u975e\uff09\u985e\u4f3c\u5ea6", "metadata": {} @@ -1131,7 +1131,7 @@ "\n", "sum(AC^2)^0.5" ], - "id": "6bbdcdd6-ec01-44c5-a7ba-c7c24bdac88d" + "id": "4e03d784-8b19-40e1-8375-b42e25c5ee25" }, { "cell_type": "code", @@ -1143,7 +1143,7 @@ "\n", "sum(abs(AC))" ], - "id": "883c0d47-7d40-41b2-a744-a9bd65fb1c28" + "id": "7dab2b7e-1766-4837-8112-32f38118db61" }, { "cell_type": "code", @@ -1157,7 +1157,7 @@ "sum(A * C) /\n", " sum(A * A)^0.5 / sum(C * C)^0.5" ], - "id": "2a7b0a7d-3885-4c55-92ba-9e9c91f23d44" + "id": "11208345-50a7-49d0-802f-9f694ef8e424" }, { "cell_type": "code", @@ -1169,7 +1169,7 @@ "\n", "cor(A, C)" ], - "id": "6c665185-31fb-47a8-b0d7-5eab939774e2" + "id": "e76fc030-18cc-496f-a86f-d66514966571" }, { "cell_type": "code", @@ -1202,10 +1202,10 @@ "# \u76f8\u95a2\u4fc2\u6570\n", "my_df %>% proxy::simil(\"correlation\")" ], - "id": "a18dc3ec-4f7f-4fe6-9304-6680e21caf36" + "id": "2f3d3c66-23ba-428d-856c-bd60cf9ce5a6" }, { - "id": "9d6b6c6e", + "id": "282a5e51", "cell_type": "markdown", "source": "## 3.6 R\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\uff0cPython\u306e\u30e2\u30b8\u30e5\u30fc\u30eb", "metadata": {} @@ -1218,10 +1218,10 @@ "source": [ "library(tidyverse)" ], - "id": "e69712c4-6486-4dac-9684-2d0ef5424581" + "id": "7de1437b-9d29-4ee5-b4f4-01b3cd94345d" }, { - "id": "59187091", + "id": "e28e586e", "cell_type": "markdown", "source": "## 3.7 \u53cd\u5fa9\u51e6\u7406", "metadata": {} @@ -1234,7 +1234,7 @@ "source": [ "library(tidyverse)" ], - "id": "90080d91-f09d-44cb-b459-5ec7bc355f80" + "id": "75d79a0d-e8ad-4cf6-9217-5c0acf19a96a" }, { "cell_type": "code", @@ -1249,7 +1249,7 @@ "\n", "f1(10) # \u52d5\u4f5c\u78ba\u8a8d" ], - "id": "161c67fa-819d-496d-85e9-7e2e3c128f4b" + "id": "9d6ad48a-c208-4bb6-8901-bf0015c82554" }, { "cell_type": "code", @@ -1259,7 +1259,7 @@ "source": [ "replicate(n = 3, expr = f1(10))" ], - "id": "d63581fb-856e-477f-9199-500b95556c36" + "id": "0b4bfb74-e527-429c-9dff-117f174e6b0c" }, { "cell_type": "code", @@ -1269,7 +1269,7 @@ "source": [ "rep(x = f1(10), times = 3)" ], - "id": "8ad420a0-3c51-4ef2-935a-effe69c958af" + "id": "15c74918-f57d-43b0-a2e0-ac5e8881b318" }, { "cell_type": "code", @@ -1280,7 +1280,7 @@ "v <- c(5, 10, 100)\n", "v %>% map_dbl(f1)" ], - "id": "b87bd2ec-2373-416e-990e-5e43f11826c1" + "id": "07d9958e-a4c3-4222-b34f-e04f1ae40a51" }, { "cell_type": "code", @@ -1291,7 +1291,7 @@ "rep(x = 10, times = 3) %>% map_dbl(f1)\n", "# \u7d50\u679c\u306f\u5272\u611b" ], - "id": "f39c40ad-c6a4-4ada-b296-c9a9d0e34a0b" + "id": "155608c9-a3f8-4c8f-aabb-94eef32eb030" }, { "cell_type": "code", @@ -1308,7 +1308,7 @@ "\n", "f2(10) # \u52d5\u4f5c\u78ba\u8a8d" ], - "id": "58af6b3e-0ebd-4c8d-99aa-933c3bc7df94" + "id": "6bbe556f-0f4a-4ab0-a4a1-4596b38995aa" }, { "cell_type": "code", @@ -1319,7 +1319,7 @@ "v <- c(5, 10, 100)\n", "v %>% map_dfr(f2)" ], - "id": "716a6508-f657-460a-804f-a488996f8801" + "id": "f4d7957e-642b-40d4-a4c6-79bc7dde5aa6" }, { "cell_type": "code", @@ -1339,7 +1339,7 @@ "\n", "f3(x = 10, y = 6) # \u52d5\u4f5c\u78ba\u8a8d" ], - "id": "1f7ba21c-f8c9-4031-8f13-fc3048155dce" + "id": "c5e3c135-f22a-481e-9667-ded1004267d1" }, { "cell_type": "code", @@ -1353,7 +1353,7 @@ "\n", "my_df %>% pmap_dfr(f3)" ], - "id": "5cede40e-b7b4-437a-a686-6551f0412feb" + "id": "766fbc94-5557-491b-ba09-1450273e37fa" }, { "cell_type": "code", @@ -1369,10 +1369,10 @@ " furrr_options(seed = TRUE))\n", "# \u7d50\u679c\u306f\u5272\u611b" ], - "id": "a4c9c625-2f39-49de-93b4-124b8193c7a3" + "id": "a6dba167-173d-4391-80a3-c3e28befc5f7" }, { - "id": "3e54f793", + "id": "11b15f48", "cell_type": "markdown", "source": "## 3.8 \u305d\u306e\u4ed6", "metadata": {} @@ -1386,7 +1386,7 @@ "x <- 123\n", "typeof(x)" ], - "id": "9b22a892-cb48-4155-a793-6a87cb37b323" + "id": "475c549e-a346-4213-bb8b-77d9f1d8866c" }, { "cell_type": "code", @@ -1398,7 +1398,7 @@ "# \u3042\u308b\u3044\u306f\n", "help(log)" ], - "id": "f1daafbc-de15-4622-aca7-2f00d24a145d" + "id": "5bea21cb-6e28-47d3-a634-59f45202115f" }, { "cell_type": "code", @@ -1409,7 +1409,7 @@ "v <- c(1, NA, 3)\n", "v" ], - "id": "be480b99-77fa-4a50-848d-362993118358" + "id": "9a979b89-0718-48b1-a664-6143c93336f1" }, { "cell_type": "code", @@ -1421,7 +1421,7 @@ "\n", "v[2] == NA # \u8aa4\u308a" ], - "id": "42713f99-af67-4b47-a67a-ffdcdad3e508" + "id": "0a7e69ca-52eb-4ee6-ab65-6a7b652f80c8" } ], "nbformat": 4, diff --git a/code/R-notebook/r-11.ipynb b/code/R-notebook/r-11.ipynb index 31b28d9..2fe8d92 100644 --- a/code/R-notebook/r-11.ipynb +++ b/code/R-notebook/r-11.ipynb @@ -1,7 +1,7 @@ { "cells": [ { - "id": "da445c5b", + "id": "2e4c0f79", "cell_type": "markdown", "source": "[\u8fbb\u771f\u543e\u30fb\u77e2\u5439\u592a\u6717\u300e\u30bc\u30ed\u304b\u3089\u306f\u3058\u3081\u308b\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u5165\u9580\u300f\uff08\u8b1b\u8ac7\u793e,\u00a02021\uff09](https://github.com/taroyabuki/fromzero)", "metadata": {} @@ -20,10 +20,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "3c085e15-756b-4037-99a6-f7033fc4bcb1" + "id": "3f399423-d67c-41fe-923d-bc027c265f3a" }, { - "id": "f6225eee", + "id": "3e243ea3", "cell_type": "markdown", "source": "## 11.1 Keras\u306b\u3088\u308b\u56de\u5e30", "metadata": {} @@ -44,7 +44,7 @@ " \"/fromzero/master/data/wine.csv\")\n", "tmp <- read_csv(my_url)" ], - "id": "157a4b0a-2936-46f4-a1db-abe6b166c9fa" + "id": "c09d57b1-6d02-4b16-aeae-97ffd7f5f09b" }, { "cell_type": "code", @@ -54,7 +54,7 @@ "source": [ "my_data <- tmp[sample(nrow(tmp)), ]" ], - "id": "894fb31e-944a-41b4-9a99-fd65d0008e3d" + "id": "12417b8c-34f7-4dc1-8908-b2d89e917b07" }, { "cell_type": "code", @@ -66,7 +66,7 @@ " select(-LPRICE2) %>% scale\n", "y <- my_data$LPRICE2" ], - "id": "829429fa-c46e-4f26-b682-44207ea1988b" + "id": "324c8142-9ca9-445a-832a-c77331cf05a3" }, { "cell_type": "code", @@ -76,7 +76,7 @@ "source": [ "curve(activation_relu(x), -3, 3)" ], - "id": "ff60523f-d831-4cbc-8f9e-3b25280f4e77" + "id": "3e596b2c-a39e-4064-9b91-d268f3c823b0" }, { "cell_type": "code", @@ -91,7 +91,7 @@ "summary(my_model) # \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u6982\u8981\n", "# \u5272\u611b\uff08Python\u306e\u7d50\u679c\u3092\u53c2\u7167\uff09" ], - "id": "a2f63dc7-16f5-473e-a278-e2baebc5aefa" + "id": "28fff2df-8df8-4cad-a2dd-1bc1c04e55b3" }, { "cell_type": "code", @@ -103,7 +103,7 @@ " loss = \"mse\",\n", " optimizer = \"rmsprop\")" ], - "id": "d3f35d56-4881-49d0-a09a-3478864391d9" + "id": "03935f89-4af8-43df-be20-f89852eb4873" }, { "cell_type": "code", @@ -115,7 +115,7 @@ " patience = 20,\n", " restore_best_weights = TRUE)" ], - "id": "73e8a12a-3dea-4e50-81cb-883cbdfe399d" + "id": "67b26bd5-5095-434c-9a6a-e71098c302cc" }, { "cell_type": "code", @@ -132,7 +132,7 @@ " callbacks = list(my_cb),\n", " verbose = 0)" ], - "id": "da87bb0d-325c-4d27-89b8-702d35fd0ca6" + "id": "46c649d3-4dee-4c77-bb0e-2bd4664f0380" }, { "cell_type": "code", @@ -142,7 +142,7 @@ "source": [ "plot(my_history)" ], - "id": "c43f5f78-a4b5-4607-9177-caa57be630df" + "id": "172ac024-a98c-43a5-85ae-4d600248e663" }, { "cell_type": "code", @@ -152,7 +152,7 @@ "source": [ "my_history" ], - "id": "4532a621-dddd-4340-a73f-2210c436d26e" + "id": "b254ead5-3e38-47ed-9829-774294010e9e" }, { "cell_type": "code", @@ -163,10 +163,10 @@ "y_ <- my_model %>% predict(X)\n", "mean((y_ - y)^2)**0.5" ], - "id": "a7488a1d-ac3d-4c5e-9d1e-4008074a0c11" + "id": "353c60a3-2620-4e19-b165-7d9926a3b74a" }, { - "id": "28850e7e", + "id": "2813f897", "cell_type": "markdown", "source": "## 11.2 Keras\u306b\u3088\u308b\u5206\u985e", "metadata": {} @@ -185,7 +185,7 @@ "library(tidyverse)\n", "my_data <- iris[sample(nrow(iris)), ]" ], - "id": "1772cf4d-3043-46c8-b50c-09063f9df66f" + "id": "1910ec23-b6f0-43af-a856-6b34b2bbe8a4" }, { "cell_type": "code", @@ -197,7 +197,7 @@ " select(-Species) %>% scale\n", "y <- as.integer(my_data$Species) - 1" ], - "id": "5e326180-63d3-4093-8358-4ce6f0f87b8e" + "id": "a78a0d6e-829d-4882-8532-bca967714f91" }, { "cell_type": "code", @@ -209,7 +209,7 @@ " layer_dense(units = 3, activation = \"relu\", input_shape = c(4)) %>%\n", " layer_dense(units = 3, activation = \"softmax\")" ], - "id": "71032aeb-ee62-496b-a300-8abc9666e188" + "id": "e7b23634-7b64-41d1-9ec7-c7a11a5ea9d7" }, { "cell_type": "code", @@ -221,7 +221,7 @@ " optimizer = \"rmsprop\",\n", " metrics = c(\"accuracy\"))" ], - "id": "01548508-8256-4fc3-9fbc-c9fddb794e2b" + "id": "8c1aea28-dcf2-460c-abb9-990a8059fe06" }, { "cell_type": "code", @@ -244,7 +244,7 @@ "\n", "plot(my_history)" ], - "id": "d1ed59f0-3d67-46c9-8d3c-1fcf161cf511" + "id": "843cad5b-0b39-47db-8a08-321e632ee1c9" }, { "cell_type": "code", @@ -254,7 +254,7 @@ "source": [ "my_history" ], - "id": "5565c5ba-be96-4eef-9859-b98f2f3c1dd2" + "id": "8ca9ef80-45f6-4c35-9b6b-56f5f60ec6cf" }, { "cell_type": "code", @@ -266,7 +266,7 @@ "y_ <- apply(tmp, 1, which.max) - 1\n", "mean(y_ == y)" ], - "id": "3b4c2a51-2e34-4c4c-8117-00033c92dcc8" + "id": "9b242586-d0f4-401f-9b4b-e51fd9b19710" }, { "cell_type": "code", @@ -278,7 +278,7 @@ "\n", "-mean(log(c(0.7, 0.6, 0.2, 0.7)))" ], - "id": "c4990744-0cdb-4a2a-9fd7-fca1f99f6971" + "id": "8a4c26ab-6bd5-493c-93e0-68d408ece610" }, { "cell_type": "code", @@ -296,7 +296,7 @@ " c(0.2, 0.5, 0.3),\n", " c(0.2, 0.7, 0.1))" ], - "id": "7d4f36ab-cc55-4fd2-9993-8197db758e2b" + "id": "f646b08e-40e6-4b9a-a858-38b36422f9aa" }, { "cell_type": "code", @@ -307,10 +307,10 @@ "c(mean(as.array(loss_sparse_categorical_crossentropy(y_true = y, y_pred = y_1))),\n", " mean(as.array(loss_sparse_categorical_crossentropy(y_true = y, y_pred = y_2))))" ], - "id": "531b3c77-7281-4564-b949-14e29f80b6a3" + "id": "3768ff36-516a-4070-ad6f-a4a86b113532" }, { - "id": "83440c01", + "id": "f5d6b896", "cell_type": "markdown", "source": "## 11.3 MNIST\uff1a\u624b\u66f8\u304d\u6570\u5b57\u306e\u5206\u985e", "metadata": {} @@ -326,11 +326,10 @@ "} else {\n", " library(keras)\n", "}\n", - "library(zeallot)\n", - "c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()\n", - "library(tidyverse)" + "library(tidyverse)\n", + "c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()" ], - "id": "d685105c-4f4c-4fd2-8e8d-047cb4796361" + "id": "56fd2f5a-1367-43f1-9497-acc77c222623" }, { "cell_type": "code", @@ -340,7 +339,7 @@ "source": [ "dim(x_train)" ], - "id": "1b9ee597-9dcc-45d2-bfb2-89eb3eaf74ba" + "id": "8ff80389-e942-4e1d-a5d8-6525c220177b" }, { "cell_type": "code", @@ -350,7 +349,7 @@ "source": [ "x_train[5, , ]" ], - "id": "de58dbbf-b383-4955-acf9-172c31f91fb5" + "id": "70037f69-4be6-4ca8-a4e8-cc37bb796577" }, { "cell_type": "code", @@ -361,7 +360,7 @@ "plot(as.raster(x = x_train[5, , ],\n", " max = max(x_train)))" ], - "id": "9ea901bf-5dfd-43ea-b8ac-0252c91eca93" + "id": "b4a109b5-10a1-42f6-ae31-e99ca7b52ff4" }, { "cell_type": "code", @@ -371,7 +370,7 @@ "source": [ "head(y_train)" ], - "id": "ccab10d8-5889-4f57-818b-032ff9026742" + "id": "7700d893-82b3-43d8-a33a-00a0a8129499" }, { "cell_type": "code", @@ -381,7 +380,7 @@ "source": [ "c(min(x_train), max(x_train))" ], - "id": "73ced841-5f56-46a5-90c3-fe26db8d7e99" + "id": "78cb3b64-b219-432f-9387-7cbb7c94442e" }, { "cell_type": "code", @@ -392,7 +391,7 @@ "x_train <- x_train / 255\n", "x_test <- x_test / 255" ], - "id": "f375bd1b-f50c-4107-8d42-cde8bec0324a" + "id": "1c4b2514-1ca2-4270-8b34-fe13d10c5171" }, { "cell_type": "code", @@ -404,7 +403,7 @@ "x_train <- x_train[my_index, , ]\n", "y_train <- y_train[my_index]" ], - "id": "87ee58ff-19e3-45bf-b800-e2bc77282176" + "id": "904bf052-a903-428d-b9b7-067942f0bda4" }, { "cell_type": "code", @@ -426,7 +425,7 @@ "my_cb <- callback_early_stopping(patience = 5,\n", " restore_best_weights = TRUE)" ], - "id": "507be3c9-d1e5-46c0-b4e8-6d1f7a6690c7" + "id": "c56b4c2f-2b6f-45df-9e58-7094f5ddacb2" }, { "cell_type": "code", @@ -445,7 +444,7 @@ "\n", "plot(my_history)" ], - "id": "251e97c6-9dd1-4253-8d1d-2390bdbfb638" + "id": "1033a96a-66f3-4d32-86b8-d5be0767196f" }, { "cell_type": "code", @@ -457,7 +456,7 @@ "y_ <- apply(tmp, 1, which.max) - 1\n", "table(y_, y_test)" ], - "id": "0667d845-b272-4e63-b8b2-73e01f369478" + "id": "943bc119-5353-46be-8586-a76ce5631b39" }, { "cell_type": "code", @@ -465,7 +464,7 @@ "metadata": {}, "outputs": [], "source": [], - "id": "b1ed2d98-859e-4e9c-9f44-fec201dea68e" + "id": "22c64c12-9244-4116-9142-45b45d9c1e88" }, { "cell_type": "code", @@ -475,7 +474,7 @@ "source": [ "mean(y_ == y_test)" ], - "id": "819db9bd-aa28-4514-8d19-dbb3a5149729" + "id": "1b004fba-293a-484b-8aa3-d994d90ade96" }, { "cell_type": "code", @@ -486,7 +485,7 @@ "my_model %>%\n", " evaluate(x = x_test, y = y_test)" ], - "id": "60e982cf-2aac-4212-b0bd-3c441e21fa8a" + "id": "ee423c18-78b3-45d3-96ff-fac301f0b14f" }, { "cell_type": "code", @@ -497,7 +496,7 @@ "x_train2d <- x_train %>% array_reshape(c(-1, 28, 28, 1))\n", "x_test2d <- x_test %>% array_reshape(c(-1, 28, 28, 1))" ], - "id": "e40fdb76-25a8-429d-827d-3bfd8d446379" + "id": "ddea71cb-788a-4541-a129-583ebdf9cba9" }, { "cell_type": "code", @@ -524,7 +523,7 @@ "my_cb <- callback_early_stopping(patience = 5,\n", " restore_best_weights = TRUE)" ], - "id": "d9c869ab-ea07-4347-a027-095b07b8d943" + "id": "90925820-8477-412c-848a-7d305ad44a3e" }, { "cell_type": "code", @@ -543,7 +542,7 @@ "\n", "plot(my_history)" ], - "id": "51214782-bd76-4719-a075-713c5c3681e5" + "id": "1885a22b-fd78-412b-ad7f-3822a031fc4a" }, { "cell_type": "code", @@ -554,7 +553,7 @@ "my_model %>%\n", " evaluate(x = x_test2d, y = y_test)" ], - "id": "c133d393-2cf5-4094-a53a-3233a37fa7df" + "id": "fac895c1-94a6-4f25-87d9-1724d81a5c59" }, { "cell_type": "code", @@ -582,7 +581,7 @@ "my_cb <- callback_early_stopping(patience = 5,\n", " restore_best_weights = TRUE)" ], - "id": "f69578cd-9aa9-4ae5-9f18-4ddbdcf13fe0" + "id": "1c52dc68-4f32-4c39-9f79-34df68121750" }, { "cell_type": "code", @@ -601,7 +600,7 @@ "\n", "plot(my_history)" ], - "id": "b8d62e8b-7ccd-4d66-984f-9504000ddd03" + "id": "01cff13f-3ec5-4a6e-bd33-f79b0955829f" }, { "cell_type": "code", @@ -612,7 +611,7 @@ "my_model %>%\n", " evaluate(x = x_test2d, y = y_test)" ], - "id": "2e1b97d6-9b97-448b-bb25-309df60d1c7e" + "id": "a80b3800-35c0-4ec0-ae00-8d6440ef512e" }, { "cell_type": "code", @@ -630,7 +629,7 @@ " filter(y_ != y) %>% # \u4e88\u6e2c\u304c\u306f\u305a\u308c\u305f\u3082\u306e\u3092\u6b8b\u3059\n", " arrange(desc(y_prob)) # \u78ba\u7387\u306e\u5927\u304d\u3044\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b" ], - "id": "ea6ebea8-e611-4e6f-bf44-106fd93eea96" + "id": "72ab38c7-a8c0-48a9-afe0-590be1f90594" }, { "cell_type": "code", @@ -640,7 +639,7 @@ "source": [ "head(my_result)" ], - "id": "257dd23f-2df4-4d62-931f-f619a9db868d" + "id": "f68c9f2b-9f49-4c1a-8ddd-564d0cbfa9ca" }, { "cell_type": "code", @@ -666,10 +665,10 @@ " theme(legend.position = \"none\") +\n", " facet_grid(. ~ label)" ], - "id": "660a6b6e-460a-401c-b0b1-0e91a4cead16" + "id": "e290b2d6-0880-4946-b44c-8f3b277865eb" }, { - "id": "8aefc561", + "id": "12d9d7bf", "cell_type": "markdown", "source": "## 11.4 AutoML", "metadata": {} @@ -692,7 +691,7 @@ "h2o.no_progress()\n", "# h2o.shutdown(prompt = FALSE) # \u505c\u6b62" ], - "id": "9b3f4304-e423-4ecb-97d9-e803dacf2f80" + "id": "15ff46a0-2fa5-43ea-aefc-5b34c004a397" }, { "cell_type": "code", @@ -707,7 +706,7 @@ "# \u3042\u308b\u3044\u306f\n", "my_frame <- h2o.importFile(my_url, header = TRUE) # \u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\uff0e" ], - "id": "a96a50e1-57ea-46ff-ae47-6c75c51023a2" + "id": "a7e4f23c-e23b-4d03-b4dd-86491a914904" }, { "cell_type": "code", @@ -721,7 +720,7 @@ "my_frame %>% as.data.frame %>% head\n", "# \u7d50\u679c\u306f\u5272\u611b\uff08\u898b\u305f\u76ee\u306f\u540c\u3058\uff09" ], - "id": "5c46a53a-ff5b-4aaa-84c6-3862152ce1bf" + "id": "afe52753-8b19-4ce6-9679-a711918a2167" }, { "cell_type": "code", @@ -734,7 +733,7 @@ " training_frame = my_frame,\n", " max_runtime_secs = 60)" ], - "id": "fc4e97d3-a2e1-492d-9995-59f1e3277818" + "id": "1d9a16b2-204a-40cd-b22e-05df8455425d" }, { "cell_type": "code", @@ -744,7 +743,7 @@ "source": [ "min(my_model@leaderboard$rmse)" ], - "id": "ecf3e987-5f12-4bf1-8495-18062a81d818" + "id": "6d68e8ec-dd1e-4776-9970-799b4b00234e" }, { "cell_type": "code", @@ -760,7 +759,7 @@ "\n", "plot(y, y_)" ], - "id": "563b05fc-395e-486f-879e-003839e08ecc" + "id": "ba96c7dd-de1c-4946-95ca-63e98922e516" }, { "cell_type": "code", @@ -768,13 +767,12 @@ "metadata": {}, "outputs": [], "source": [ - "library(zeallot)\n", "c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()\n", "my_index <- sample(1:60000, 6000)\n", "x_train <- x_train[my_index, , ]\n", "y_train <- y_train[my_index]" ], - "id": "0571c82f-f489-40ad-aaf2-4e1516a51109" + "id": "8c733ab4-8e1f-475d-a003-86ff79b765c6" }, { "cell_type": "code", @@ -793,7 +791,7 @@ " as.data.frame\n", "my_test <- as.h2o(tmp)" ], - "id": "6c71fb42-0d54-42f8-af93-972746d05df5" + "id": "65042e18-132b-4a91-9e9c-96104ec5281d" }, { "cell_type": "code", @@ -806,7 +804,7 @@ " training_frame = my_train,\n", " max_runtime_secs = 120)" ], - "id": "7752ac08-80fb-432b-bf93-4493a99140ca" + "id": "45fbacc6-dd4f-4069-9191-356c5c8471af" }, { "cell_type": "code", @@ -817,7 +815,7 @@ "min(my_model@leaderboard$\n", " mean_per_class_error)" ], - "id": "e90b4421-8522-4e76-8aa8-0bfc685c1a0d" + "id": "32846b68-2b23-4d77-8dc0-d902c8d73191" }, { "cell_type": "code", @@ -831,7 +829,7 @@ "\n", "mean(y_ == y_test)" ], - "id": "8ef037cc-684c-4d2a-aaa8-6284f3e56bea" + "id": "a01135a7-e333-4715-9463-77030fcd1345" } ], "nbformat": 4, diff --git a/code/r.Rmd b/code/r.Rmd index ee0729e..9dac73e 100644 --- a/code/r.Rmd +++ b/code/r.Rmd @@ -2766,9 +2766,8 @@ if (Sys.getenv("COLAB_JUPYTER_IP") != "") { } else { library(keras) } -library(zeallot) -c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist() library(tidyverse) +c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist() ``` ```{r} @@ -3025,7 +3024,6 @@ plot(y, y_) ``` ```{r} -library(zeallot) c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist() my_index <- sample(1:60000, 6000) x_train <- x_train[my_index, , ] diff --git a/code/r.ipynb b/code/r.ipynb index a93da85..d170520 100644 --- a/code/r.ipynb +++ b/code/r.ipynb @@ -1,7 +1,7 @@ { "cells": [ { - "id": "5f29fb63", + "id": "a8e4f386", "cell_type": "markdown", "source": "[\u8fbb\u771f\u543e\u30fb\u77e2\u5439\u592a\u6717\u300e\u30bc\u30ed\u304b\u3089\u306f\u3058\u3081\u308b\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u5165\u9580\u300f\uff08\u8b1b\u8ac7\u793e,\u00a02021\uff09](https://github.com/taroyabuki/fromzero)", "metadata": {} @@ -15,64 +15,64 @@ "# \u3053\u308c\u306fR\u306e\u30b3\u30fc\u30c9\u306e\u4f8b\u3067\u3059\uff0e\n", "1 + 1" ], - "id": "c73e7cd3-4983-44b3-814d-168e5b3c4604" + "id": "240b5c18-7d52-4447-963e-2757f7585738" }, { - "id": "c868ecad", + "id": "421a31bd", "cell_type": "markdown", "source": "# 1 \u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u3068\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\n\n\n", "metadata": {} }, { - "id": "c58e678a", + "id": "215431b9", "cell_type": "markdown", "source": "## 1.1 \u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306e\u57fa\u672c\u64cd\u4f5c\n\n\n", "metadata": {} }, { - "id": "750c0484", + "id": "7baa80d1", "cell_type": "markdown", "source": "## 1.2 \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u4ed5\u7d44\u307f\n\n\n", "metadata": {} }, { - "id": "83c1ddf3", + "id": "1a7a0351", "cell_type": "markdown", "source": "# 2 \u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u306e\u305f\u3081\u306e\u74b0\u5883\n\n\n", "metadata": {} }, { - "id": "407659db", + "id": "d4299150", "cell_type": "markdown", "source": "## 2.1 \u5b9f\u884c\u74b0\u5883\u306e\u9078\u629e\n\n\n", "metadata": {} }, { - "id": "7d4ee898", + "id": "231a0999", "cell_type": "markdown", "source": "## 2.2 \u30af\u30e9\u30a6\u30c9\n\n\n", "metadata": {} }, { - "id": "9af4238b", + "id": "3373d73e", "cell_type": "markdown", "source": "## 2.3 Docker\n\n\n", "metadata": {} }, { - "id": "c7824e91", + "id": "250f557a", "cell_type": "markdown", "source": "## 2.4 \u30bf\u30fc\u30df\u30ca\u30eb\u306e\u4f7f\u3044\u65b9\n\n\n", "metadata": {} }, { - "id": "8099289b", + "id": "7d2bc194", "cell_type": "markdown", "source": "## 2.5 R\u3068Python\n\n\n", "metadata": {} }, { - "id": "b92efd03", + "id": "c4bb5a45", "cell_type": "markdown", "source": "## 2.6 \u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u5229\u7528", "metadata": {} @@ -89,10 +89,10 @@ "\n", "1 + 3" ], - "id": "4dd8d34c-3008-4dc2-b8be-d3484470632f" + "id": "ff9d95bc-b223-452f-b594-987f17a9d55a" }, { - "id": "4cb39678", + "id": "0fb9d3df", "cell_type": "markdown", "source": "# 3 R\u3068Python", "metadata": {} @@ -112,10 +112,10 @@ " install.packages(c(\"ggplot2\"))\n", "}" ], - "id": "0ed4a0e8-f316-4066-bfcb-817f611fff5f" + "id": "e0c0235b-3aff-4668-ac7a-2344f36a29ed" }, { - "id": "9a3d8901", + "id": "9d5b5352", "cell_type": "markdown", "source": "## 3.1 \u5165\u9580", "metadata": {} @@ -128,7 +128,7 @@ "source": [ "0x10" ], - "id": "23b92de8-d930-4337-a23b-76ac2d387d0d" + "id": "7cca6403-6a75-41aa-9e22-fec1ec513779" }, { "cell_type": "code", @@ -138,7 +138,7 @@ "source": [ "1.23e5" ], - "id": "c6e4041e-696b-464d-b50d-11dfc3c7b2d9" + "id": "1475b9bb-db85-4945-95d7-ebcc33434a25" }, { "cell_type": "code", @@ -148,7 +148,7 @@ "source": [ "2 * 3" ], - "id": "7df594db-bd31-47b5-8981-5512cd5ab317" + "id": "3178e52b-c975-4079-81e7-74ea791bba29" }, { "cell_type": "code", @@ -158,7 +158,7 @@ "source": [ "10 / 3" ], - "id": "1465f41c-6a53-48a0-b40e-d88e3e4a650c" + "id": "cafff2a4-b309-49d1-a8bc-2d8dd378da7d" }, { "cell_type": "code", @@ -170,7 +170,7 @@ "\n", "10 %% 3 # \u4f59\u308a" ], - "id": "2fcd3885-5467-4ca3-84fd-d777da3f8d7a" + "id": "ba32139b-292e-4411-bda4-887ad8889ae7" }, { "cell_type": "code", @@ -186,7 +186,7 @@ "c(x, y) %<-% c(20, 30) # \u307e\u3068\u3081\u3066\u540d\u4ed8\u3051\n", "x * y" ], - "id": "e2864993-d0bd-4eab-bfbe-adc30dce3e8c" + "id": "b8b5eeb8-2b6f-4fd9-bcb1-6e79b7728891" }, { "cell_type": "code", @@ -199,7 +199,7 @@ "\n", "x # \u5909\u6570\u540d\u3092\u8a55\u4fa1\u3059\u308b\uff0e" ], - "id": "1e9a8585-b57f-4192-8c3e-4525711e4d7c" + "id": "ec566762-762f-466c-8856-20f4065b98cf" }, { "cell_type": "code", @@ -209,7 +209,7 @@ "source": [ "my_s <- \"abcde\"" ], - "id": "322b8a4b-8b11-4b4a-88d7-4939d90a512c" + "id": "879763eb-4668-4cfa-8665-08544e5b269c" }, { "cell_type": "code", @@ -219,7 +219,7 @@ "source": [ "nchar(my_s)" ], - "id": "7be4044e-7184-4948-8129-caa536d69989" + "id": "63b203b6-cd2c-475c-b2ae-2f9ef3f2a24e" }, { "cell_type": "code", @@ -230,7 +230,7 @@ "library(tidyverse)\n", "str_c(\"This is \", \"a\", \" pen.\")" ], - "id": "9b69489a-ea06-4aca-af7e-cf90901b029a" + "id": "dab73eb0-9083-4398-8649-a38cecd2897b" }, { "cell_type": "code", @@ -240,7 +240,7 @@ "source": [ "substr(x = my_s, start = 2, stop = 4)" ], - "id": "ac88598d-311e-444b-871c-aa8e9f7ff616" + "id": "99411aac-eecc-469d-b13f-e2b5d545f2e9" }, { "cell_type": "code", @@ -251,7 +251,7 @@ "tmp <- \"%s is %s.\"\n", "sprintf(tmp, \"This\", \"a pen\")" ], - "id": "79d9dba3-a931-4113-a3a0-b922a18a5a59" + "id": "7b6b127c-f9db-4d9b-8e50-c419b2fe21c4" }, { "cell_type": "code", @@ -263,7 +263,7 @@ "\n", "1 < 0" ], - "id": "fd5007a5-af20-4110-ab79-87e878c254bf" + "id": "ff6a38c9-d822-4990-951b-be028878874b" }, { "cell_type": "code", @@ -275,7 +275,7 @@ "\n", "all.equal(0.1 + 0.1 + 0.1, 0.3)" ], - "id": "fc7073c4-9fd5-4886-b972-c64c8c5d3f71" + "id": "1196e3d5-7cc9-4a3b-a2a2-fa83f5c80229" }, { "cell_type": "code", @@ -289,7 +289,7 @@ "\n", "!TRUE # \u5426\u5b9a\uff08\u3067\u306a\u3044\uff09" ], - "id": "12213672-5f65-4e62-9459-85b4c5d17b9c" + "id": "9a3ee5b5-1417-4b33-bd56-21374c55031e" }, { "cell_type": "code", @@ -299,7 +299,7 @@ "source": [ "ifelse(3 < 5, 0, 10)" ], - "id": "fe9b71c3-d592-4e00-938e-6ac5ac42fc8e" + "id": "75b5ad73-65d1-42a0-b053-bb085a6fcf42" }, { "cell_type": "code", @@ -309,7 +309,7 @@ "source": [ "getwd()" ], - "id": "a6d73248-d1c3-44d0-b384-50d61ea35cdc" + "id": "bd00f66f-7232-4156-927e-071d548295ca" }, { "cell_type": "code", @@ -320,10 +320,10 @@ "setwd(\"..\")\n", "getwd()" ], - "id": "9f7ebf70-c3bd-43fc-8f64-31d472f23ce9" + "id": "7ceff68d-9a5d-4e5b-8350-ef9f1049daf5" }, { - "id": "28ece058", + "id": "fb92e107", "cell_type": "markdown", "source": "## 3.2 \u95a2\u6570", "metadata": {} @@ -336,7 +336,7 @@ "source": [ "sqrt(4)" ], - "id": "d0bb1a82-150b-480a-9c29-1c673910c27b" + "id": "3c681445-937e-4719-987b-6ba5f42003d0" }, { "cell_type": "code", @@ -346,7 +346,7 @@ "source": [ "log(100, 10)" ], - "id": "05db29f3-d70c-4c09-9381-02e0001a1f92" + "id": "a60939ef-6d03-4715-9e05-4b4d3fdb7456" }, { "cell_type": "code", @@ -358,7 +358,7 @@ "# \u3042\u308b\u3044\u306f\n", "log(100, exp(1)) # \u7701\u7565\u3057\u306a\u3044\u5834\u5408\n" ], - "id": "f86d33e5-7128-4e53-be3a-32be36091387" + "id": "4bf60531-c9f5-4071-88d0-f66109504d9f" }, { "cell_type": "code", @@ -370,7 +370,7 @@ "\n", "log2(1024) # \u5e95\u304c2\u306e\u5bfe\u6570" ], - "id": "a81d5acd-6299-436e-8258-68daf1ac3e3c" + "id": "bf19af0a-166d-4e17-a559-ee532d8741bf" }, { "cell_type": "code", @@ -381,7 +381,7 @@ "library(tidyverse)\n", "4 %>% sqrt" ], - "id": "d6c94e0a-850a-46eb-b024-c541120749fd" + "id": "74342ce9-8a39-4244-b1d4-81643334bd16" }, { "cell_type": "code", @@ -393,7 +393,7 @@ "# \u3042\u308b\u3044\u306f\n", "5 %>% log %>% exp # \u30d1\u30a4\u30d7\u3092\u4f7f\u3046\u66f8\u304d\u65b9\n" ], - "id": "a40a7ea2-569c-47de-bf69-bd66e3de4504" + "id": "7c1ae7cf-90ba-4c65-a8f8-32e76695cc35" }, { "cell_type": "code", @@ -405,7 +405,7 @@ " a - b\n", "}" ], - "id": "10c889bb-9785-42c7-a946-98009cf37b0f" + "id": "082db692-a091-415d-a01b-447995bb6bbe" }, { "cell_type": "code", @@ -415,7 +415,7 @@ "source": [ "f(3, 5)" ], - "id": "aa845cfa-b113-433a-b7e8-7af4b43d0258" + "id": "90c703a1-4291-42bd-9a09-03ef2282af8f" }, { "cell_type": "code", @@ -429,7 +429,7 @@ "\n", "f(3) # f(3, 5)\u3068\u540c\u3058\u3053\u3068" ], - "id": "1b4a2498-2cc8-4a93-ab49-2bba40a5ce78" + "id": "ba83a6af-6bc5-4470-a155-8145bb34c147" }, { "cell_type": "code", @@ -439,10 +439,10 @@ "source": [ "(function(a, b) { a - b })(3, 5)" ], - "id": "a3034b23-7efa-43ae-8bc2-bbc047330691" + "id": "0d21f7f9-bb6d-4aa1-9567-9371740a4564" }, { - "id": "02bdd229", + "id": "ebdcd65e", "cell_type": "markdown", "source": "## 3.3 \u30b3\u30ec\u30af\u30b7\u30e7\u30f3", "metadata": {} @@ -455,7 +455,7 @@ "source": [ "x <- c(\"foo\", \"bar\", \"baz\")" ], - "id": "f2087be2-b56f-4d11-96bc-e36544a1c37e" + "id": "ac675c4f-f49c-4e07-a445-dec46fdf2d55" }, { "cell_type": "code", @@ -465,7 +465,7 @@ "source": [ "length(x)" ], - "id": "fd2c5405-485b-480c-85e1-4f827fa3bcf6" + "id": "08c706a9-bb33-4158-a814-337e33f88bcc" }, { "cell_type": "code", @@ -475,7 +475,7 @@ "source": [ "x[2]" ], - "id": "43722ef1-3d07-4c12-8f0e-09ec8a981e2e" + "id": "bc21529b-9da5-4be6-a067-0fd993909a86" }, { "cell_type": "code", @@ -488,7 +488,7 @@ "\n", "x[2] <- \"bar\" # \u5143\u306b\u623b\u3059\uff0e" ], - "id": "88b3fa57-3300-4e02-aad7-6ae8ce8c211a" + "id": "a21fc02a-a231-439b-955a-ef7c5dbc954e" }, { "cell_type": "code", @@ -498,7 +498,7 @@ "source": [ "x[-2]" ], - "id": "1644dd74-9ff1-4888-b39a-eb6ad986c777" + "id": "626ecf42-03e1-46fe-94cc-9da913cff8d6" }, { "cell_type": "code", @@ -508,7 +508,7 @@ "source": [ "c(x, \"qux\")" ], - "id": "5cfcc9a1-afaa-4146-938b-56851c223a77" + "id": "cd276b4b-03ff-4bec-b6e2-a83b5e795558" }, { "cell_type": "code", @@ -519,7 +519,7 @@ "x <- c(x, \"qux\")\n", "x # \u7d50\u679c\u306e\u78ba\u8a8d" ], - "id": "4671159b-a7d7-4c53-a760-530316b1c3ec" + "id": "db6a1dcc-b96b-49a0-b537-ac44b4062d59" }, { "cell_type": "code", @@ -529,7 +529,7 @@ "source": [ "1:5" ], - "id": "4d01dfd9-0406-4ad2-8af2-2e80991e7ca8" + "id": "e987374b-e68a-43f5-935e-035e49f5eb7f" }, { "cell_type": "code", @@ -539,7 +539,7 @@ "source": [ "seq(from = 0, to = 10, by = 2)" ], - "id": "501725da-95d5-4d92-8b87-4f5aea5300a2" + "id": "1fc65ac4-907b-4d70-b4e6-1879e586e215" }, { "cell_type": "code", @@ -549,7 +549,7 @@ "source": [ "seq(from = 0, to = 1, by = 0.5)" ], - "id": "c3bc2fb2-cacc-4089-a7a8-602922ca588f" + "id": "c28667a8-c011-4685-934b-8eabcaa71c29" }, { "cell_type": "code", @@ -559,7 +559,7 @@ "source": [ "seq(from = 0, to = 100, length.out = 5)" ], - "id": "b90c12da-85c2-487b-95d6-238a524dc12a" + "id": "a50bdb95-7e17-4dd4-8b59-a8252ad07501" }, { "cell_type": "code", @@ -569,7 +569,7 @@ "source": [ "rep(x = 10, times = 5)" ], - "id": "036d689b-0caa-4c6c-856f-4602abacd9f3" + "id": "5ca0deae-88ab-4405-a6f4-74b389b2fe28" }, { "cell_type": "code", @@ -581,7 +581,7 @@ "x <- factor(tmp, levels = c(\"\u30b0\u30fc\", \"\u30c1\u30e7\u30ad\", \"\u30d1\u30fc\"))\n", "x" ], - "id": "6af13fa7-f3a0-42ec-a433-810bab2c0bf7" + "id": "2adbb709-d924-4e18-8912-dd503082aa4e" }, { "cell_type": "code", @@ -595,7 +595,7 @@ "\n", "x * 10 # \u4e57\u7b97" ], - "id": "f6a0e8a8-d2b9-41d7-90c4-e0325ea6ff95" + "id": "b7d17fd8-f47f-427a-bf9e-2843b095843e" }, { "cell_type": "code", @@ -606,7 +606,7 @@ "x <- c(2, 3)\n", "sin(x)" ], - "id": "321eb0cf-06b6-4240-b622-f19674bf9cd6" + "id": "85c85767-82b5-45e8-bc5e-fbb69a5738eb" }, { "cell_type": "code", @@ -620,7 +620,7 @@ "\n", "x * y" ], - "id": "1a2b56e2-3deb-480b-a4ef-07650710b370" + "id": "200533de-463d-4ce9-9148-8fbaec8eb7b8" }, { "cell_type": "code", @@ -630,7 +630,7 @@ "source": [ "sum(x * y)" ], - "id": "15fbd081-ce13-472d-9270-9cac09195204" + "id": "f8238b9c-512f-458a-b9d2-bf4836b4ba2f" }, { "cell_type": "code", @@ -642,7 +642,7 @@ "y <- c(TRUE, TRUE)\n", "x & y" ], - "id": "3579cb17-d2df-4016-9d23-d226708b2954" + "id": "2621b552-d7d6-49d3-be58-169dcb49d485" }, { "cell_type": "code", @@ -662,7 +662,7 @@ "\n", "u == w # \u8981\u7d20\u3054\u3068\u306e\u6bd4\u8f03" ], - "id": "4229bd2d-7b83-44fa-9171-aa672048ff3a" + "id": "6c290804-ee14-4f11-a615-ca41c710b222" }, { "cell_type": "code", @@ -674,7 +674,7 @@ "\n", "mean(u == w) # \u540c\u3058\u8981\u7d20\u306e\u5272\u5408" ], - "id": "c90564fc-89f6-41d3-8477-6f07b17597ee" + "id": "5e80e6fc-d5a6-4d91-9913-6b01852e5b92" }, { "cell_type": "code", @@ -684,7 +684,7 @@ "source": [ "x <- list(1, \"two\")" ], - "id": "ae10b4f9-95e7-496f-a5de-ce4b45a1e8e8" + "id": "9b3d874c-595a-4d56-ba6d-b66fda85d307" }, { "cell_type": "code", @@ -694,7 +694,7 @@ "source": [ "x[[2]]" ], - "id": "41104509-6069-4d92-8ed2-a5475528a2e3" + "id": "1b0742fa-8907-4075-9e11-d65c41812397" }, { "cell_type": "code", @@ -705,7 +705,7 @@ "x <- list(\"apple\" = \"\u308a\u3093\u3054\",\n", " \"orange\" = \"\u307f\u304b\u3093\")" ], - "id": "9d45334f-13cd-4c86-85c4-b718bdd5ce53" + "id": "3e827f95-9612-445f-a7ec-be863af935bb" }, { "cell_type": "code", @@ -715,7 +715,7 @@ "source": [ "x[[\"grape\"]] <- \"\u3076\u3069\u3046\"" ], - "id": "5ccbce32-cc7d-4e93-85ac-7d4ec76552b4" + "id": "2fd47ff4-ec0f-4e93-8c0c-955304f1658c" }, { "cell_type": "code", @@ -732,7 +732,7 @@ "tmp <- \"apple\"\n", "x[[tmp]]\n" ], - "id": "1784fb25-e3b8-4ed9-84cc-95f36366ac1e" + "id": "7a33b198-2431-4a95-8b48-06b7331c11b2" }, { "cell_type": "code", @@ -747,10 +747,10 @@ "\n", "x # x\u306f\u5909\u308f\u3089\u306a\u3044\uff0e" ], - "id": "20807bc5-dbe3-4e0c-94c4-be8fff44df80" + "id": "3f976917-41a0-4fa1-bb42-db7385ae2058" }, { - "id": "373cbd3c", + "id": "c13ab980", "cell_type": "markdown", "source": "## 3.4 \u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0", "metadata": {} @@ -763,7 +763,7 @@ "source": [ "library(tidyverse)" ], - "id": "6855ffb3-b495-4100-93e8-96df189dc053" + "id": "7e8cd35f-7c66-4117-8a82-c82c117ea5b4" }, { "cell_type": "code", @@ -777,7 +777,7 @@ " math = c( 70, 80, 90, 100),\n", " gender = c(\"f\", \"m\", \"m\", \"f\"))" ], - "id": "b008e5fa-b572-442f-b199-8298b287f807" + "id": "145ded96-34c9-4bb6-8fa3-f26e5b40eb02" }, { "cell_type": "code", @@ -792,7 +792,7 @@ " \"C\", 70, 90, \"m\",\n", " \"D\", 90, 100, \"f\")" ], - "id": "7fa1e01a-4614-47c4-920f-feb7d934b789" + "id": "88a21e7d-877c-4916-b105-05b596cf836a" }, { "cell_type": "code", @@ -803,7 +803,7 @@ "head(my_df)\n", "# \u7d50\u679c\u306f\u5272\u611b" ], - "id": "a0be05ab-29ae-4aac-9533-84a90fac7da7" + "id": "ae94eba1-d305-4f4d-9439-59093f9065c3" }, { "cell_type": "code", @@ -817,7 +817,7 @@ "\n", "ncol(my_df) # \u5217\u6570" ], - "id": "3b6439a2-7f87-443c-9a1a-a5747a884af4" + "id": "70bcd9e9-316d-4623-b200-f3f03a4165fe" }, { "cell_type": "code", @@ -830,7 +830,7 @@ " Y = c(10, 100))\n", "my_df2" ], - "id": "dffaf3a3-6f51-4836-b136-7e91841984cb" + "id": "1dd1d45c-f928-4fdc-bae8-acbbae9f2b47" }, { "cell_type": "code", @@ -840,7 +840,7 @@ "source": [ "colnames(my_df2)" ], - "id": "810ff406-2919-4188-9c34-980e3773c9f4" + "id": "9fdc41d9-f213-4955-bda4-a7154ba48dba" }, { "cell_type": "code", @@ -852,7 +852,7 @@ "my_df2\n", "# \u4ee5\u4e0b\u7701\u7565" ], - "id": "7c6a5b3e-3bec-454e-b339-757b72def7f8" + "id": "99fa7c9c-4e23-41f6-a11c-85b4e433519b" }, { "cell_type": "code", @@ -862,7 +862,7 @@ "source": [ "row.names(my_df)" ], - "id": "60f58441-ec18-427f-82a5-5abe41fa0da8" + "id": "f9c8deb0-7f00-4ddd-bbf0-317535bad16d" }, { "cell_type": "code", @@ -875,7 +875,7 @@ "my_df2\n", "# \u4ee5\u4e0b\u7701\u7565" ], - "id": "6dd38c51-419f-4ce1-ba17-ed38e38817bb" + "id": "fd920220-9aea-49b6-ae61-95f85e6768b7" }, { "cell_type": "code", @@ -890,7 +890,7 @@ " row.names = c(\"A\", \"B\", \"C\", \"D\"))\n", "my_df3" ], - "id": "91959b2c-db04-43aa-b793-9f1dae81762d" + "id": "a561208f-de03-4407-a80c-7dd946d051ce" }, { "cell_type": "code", @@ -905,7 +905,7 @@ " gender = \"m\")\n", "my_df2 <- rbind(my_df, tmp)" ], - "id": "8eefaae5-4bd1-4367-816c-35a1dba01c06" + "id": "232b397a-746d-4e4e-9d14-0115f9bc0f88" }, { "cell_type": "code", @@ -916,7 +916,7 @@ "my_df2 <- my_df %>%\n", " mutate(id = c(1, 2, 3, 4))" ], - "id": "bcfc240f-a40f-49cc-a22f-b60aec5c3c40" + "id": "b7089670-f55f-4281-b629-73a2239c5806" }, { "cell_type": "code", @@ -928,7 +928,7 @@ "my_df3[\"id\"] <- c(1, 2, 3, 4) # \u66f4\u65b0\n", "my_df3 # \u7d50\u679c\u306e\u78ba\u8a8d\uff08\u5272\u611b\uff09" ], - "id": "1895ae6b-690c-4596-9bb9-88e19ac6747a" + "id": "40507d12-8465-4371-9b31-bfb51a0a0268" }, { "cell_type": "code", @@ -938,7 +938,7 @@ "source": [ "my_df[1, 2]" ], - "id": "eda3183f-cc72-43b8-b8bf-fcc6d29344e5" + "id": "ecc18a04-b1b9-4834-a1da-8436d27ad9ce" }, { "cell_type": "code", @@ -959,7 +959,7 @@ "\n", "x # \u7d50\u679c\u306e\u78ba\u8a8d\uff08\u5272\u611b\uff09" ], - "id": "b65630c2-ed48-4163-b3bd-fd00448f1da1" + "id": "97ad08e6-19f8-48a0-bed8-d80b384f60a7" }, { "cell_type": "code", @@ -969,7 +969,7 @@ "source": [ "x <- my_df %>% select(name, math)" ], - "id": "7eafb7ad-3e4b-48e2-bb1a-9da7337f5721" + "id": "67bf29c5-4419-4f51-94ae-1bd88eee9b27" }, { "cell_type": "code", @@ -979,7 +979,7 @@ "source": [ "x <- my_df[, c(1, 3)]" ], - "id": "3a57170c-b27a-4626-9927-263beb5f0d0a" + "id": "065c7877-3bc8-4cc8-b9e6-3404e568dc92" }, { "cell_type": "code", @@ -992,7 +992,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df[, -c(2, 4)]" ], - "id": "8f8e1041-0b57-497a-baa3-9fc338530b42" + "id": "9b7adff3-4ec7-494d-8332-ccffcd31f9fc" }, { "cell_type": "code", @@ -1002,7 +1002,7 @@ "source": [ "x <- my_df[c(1, 3), ]" ], - "id": "472426e2-373f-4987-be76-66f374b18e70" + "id": "4bc0997b-f831-4360-a52f-a8adaa28ae7e" }, { "cell_type": "code", @@ -1012,7 +1012,7 @@ "source": [ "x <- my_df[-c(2, 4), ]" ], - "id": "263c0d27-d19f-44b4-8118-d3d2d161e102" + "id": "821983cb-b4c1-4eb0-acf7-6e12b7a95780" }, { "cell_type": "code", @@ -1024,7 +1024,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df %>% filter(gender == \"m\")" ], - "id": "ee8aaac4-3aac-4e19-b37b-e81800f95c7f" + "id": "69a56524-6c01-46b8-8fb5-af6faacb983c" }, { "cell_type": "code", @@ -1036,7 +1036,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df %>% filter(english > 80 & gender == \"m\")" ], - "id": "092e7a57-7558-4b87-a7ef-862e33bb3bf6" + "id": "213f95ac-c2f9-4d90-a386-db577330fd61" }, { "cell_type": "code", @@ -1048,7 +1048,7 @@ "# \u3042\u308b\u3044\u306f\n", "x <- my_df %>% filter(english == max(my_df$english))" ], - "id": "629a66f3-c7ae-49fd-ab03-d1f902a27edb" + "id": "e52752f4-42e2-48c7-8386-07549bbc78dc" }, { "cell_type": "code", @@ -1059,7 +1059,7 @@ "my_df2 <- my_df # \u30b3\u30d4\u30fc\n", "my_df2[my_df$gender == \"m\", ]$gender <- \"M\"" ], - "id": "f6c59d98-ef9d-4a3a-a024-6f3934ee3c52" + "id": "0eaa1c31-8d40-44b7-9e76-c2d09ac7c9ca" }, { "cell_type": "code", @@ -1069,7 +1069,7 @@ "source": [ "my_df2" ], - "id": "736c56f5-e8e3-4b00-b8e8-dedfa7d04799" + "id": "f2ed4ccf-ad7a-43f9-8cc4-2f48f777ebe3" }, { "cell_type": "code", @@ -1079,7 +1079,7 @@ "source": [ "x <- my_df %>% arrange(english)" ], - "id": "9511428e-c6ae-4392-9df9-d0041102e0c3" + "id": "e2aaeb60-2c0d-4489-94ea-d7ed201e54fd" }, { "cell_type": "code", @@ -1089,7 +1089,7 @@ "source": [ "x <- my_df %>% arrange(-english)" ], - "id": "0bac300f-5216-4223-8e07-d82dd254028c" + "id": "74e34e43-6ff1-4f6f-94c7-bb2f115416da" }, { "cell_type": "code", @@ -1105,7 +1105,7 @@ " byrow = TRUE) # \u884c\u3054\u3068\u306e\u751f\u6210\n", "A" ], - "id": "9c8d7cf6-5141-49c6-ba52-e9953bf23bb4" + "id": "ee5720e8-742a-4efe-904d-eb58255d6fc6" }, { "cell_type": "code", @@ -1116,7 +1116,7 @@ "A <- my_df[, c(2, 3)] %>% as.matrix\n", "A" ], - "id": "d012fccf-4ac3-47da-a437-be0c4d3a75c1" + "id": "f53ac63a-a33b-4950-aeeb-cae1557281dc" }, { "cell_type": "code", @@ -1126,7 +1126,7 @@ "source": [ "as.data.frame(A)" ], - "id": "d7168339-718a-4ee0-8106-958ccd3a8a22" + "id": "be848dfa-54f9-436e-9be7-1b8f944800d7" }, { "cell_type": "code", @@ -1136,7 +1136,7 @@ "source": [ "t(A)" ], - "id": "046d7af4-7efb-4f4e-8353-29b537dfb18a" + "id": "96a2cb69-fe60-427d-a1fb-0ba179434413" }, { "cell_type": "code", @@ -1146,7 +1146,7 @@ "source": [ "t(A) %*% A" ], - "id": "552fa0f4-d680-40b8-97db-7b27551d9209" + "id": "4aa81944-0c82-4d8a-9cbe-fc8975b5ed17" }, { "cell_type": "code", @@ -1159,7 +1159,7 @@ " min = c(20, 21, 15),\n", " max = c(24, 27, 21))" ], - "id": "91c906dc-00fd-4648-9567-567ccdfa8761" + "id": "12440534-6cef-4ae1-b70c-5e119f77be49" }, { "cell_type": "code", @@ -1171,7 +1171,7 @@ " pivot_longer(-day)\n", "my_longer" ], - "id": "49e96afa-2eb0-4f33-ab85-65348e14d278" + "id": "8c0bb525-4bcd-4b26-af5c-d17724b71b82" }, { "cell_type": "code", @@ -1181,7 +1181,7 @@ "source": [ "my_longer %>% pivot_wider()" ], - "id": "45071fea-c37e-4cc1-b8f2-2313697c1444" + "id": "ebb17dd2-036b-4943-98cd-94d12f24f4ef" }, { "cell_type": "code", @@ -1198,10 +1198,10 @@ " scale_x_continuous(\n", " breaks = my_longer$day) # x\u8ef8\u76ee\u76db\u308a" ], - "id": "30da3453-88d6-4129-bd8a-c593e3a7a800" + "id": "1ab984c2-1ea5-4e7c-aa64-7f36f55e335a" }, { - "id": "d1510abf", + "id": "17f67904", "cell_type": "markdown", "source": "## 3.5 1\u6b21\u5143\u30c7\u30fc\u30bf\u306e\uff08\u975e\uff09\u985e\u4f3c\u5ea6", "metadata": {} @@ -1222,7 +1222,7 @@ "\n", "sum(AC^2)^0.5" ], - "id": "fe22229f-3ed4-48cf-a262-04216ce1342c" + "id": "0142a366-7d6f-4e5c-a9f7-b02bd263424b" }, { "cell_type": "code", @@ -1234,7 +1234,7 @@ "\n", "sum(abs(AC))" ], - "id": "3a67fe9e-97a7-4b96-9b2f-46c8f99915d0" + "id": "5169cd8b-a2ee-4767-9093-57e142bf2195" }, { "cell_type": "code", @@ -1248,7 +1248,7 @@ "sum(A * C) /\n", " sum(A * A)^0.5 / sum(C * C)^0.5" ], - "id": "b4fcd488-0dc2-4dc5-89e5-e6dc8a30e8fd" + "id": "7f87299b-ee2f-452f-96c4-0e25e4037059" }, { "cell_type": "code", @@ -1260,7 +1260,7 @@ "\n", "cor(A, C)" ], - "id": "148b4844-9157-4e7e-8eb3-3b8633ab2704" + "id": "d6b67401-4e55-41c3-80c4-e025a4d23908" }, { "cell_type": "code", @@ -1293,10 +1293,10 @@ "# \u76f8\u95a2\u4fc2\u6570\n", "my_df %>% proxy::simil(\"correlation\")" ], - "id": "f669eed8-8d44-4c73-a736-0d90878122f9" + "id": "ef192a43-e703-4f6a-b880-866a0f79c831" }, { - "id": "1cea50de", + "id": "f469f739", "cell_type": "markdown", "source": "## 3.6 R\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\uff0cPython\u306e\u30e2\u30b8\u30e5\u30fc\u30eb", "metadata": {} @@ -1309,10 +1309,10 @@ "source": [ "library(tidyverse)" ], - "id": "01ce90ea-9a15-4852-8a36-d7502ef44e15" + "id": "0e3291fd-3656-4f79-adbd-093f33d8daa3" }, { - "id": "b48ce4aa", + "id": "77867623", "cell_type": "markdown", "source": "## 3.7 \u53cd\u5fa9\u51e6\u7406", "metadata": {} @@ -1325,7 +1325,7 @@ "source": [ "library(tidyverse)" ], - "id": "556c3089-922b-49d5-8988-a3859c60c7e0" + "id": "187fc384-7e27-44d5-bdb8-91a45a541e5d" }, { "cell_type": "code", @@ -1340,7 +1340,7 @@ "\n", "f1(10) # \u52d5\u4f5c\u78ba\u8a8d" ], - "id": "7b6544b7-fff4-4b04-a466-01cdd4387a8f" + "id": "b351e561-2fd6-4791-b65f-313757f57afc" }, { "cell_type": "code", @@ -1350,7 +1350,7 @@ "source": [ "replicate(n = 3, expr = f1(10))" ], - "id": "d4cbbb42-7eb4-4719-81c7-cdc2a47fc2bc" + "id": "7706b322-7141-496e-b5b9-399ec82abcbe" }, { "cell_type": "code", @@ -1360,7 +1360,7 @@ "source": [ "rep(x = f1(10), times = 3)" ], - "id": "db2ebb0c-4a2d-4520-9c8b-c5452a870614" + "id": "14038f15-fd77-421e-933c-b46e92de435e" }, { "cell_type": "code", @@ -1371,7 +1371,7 @@ "v <- c(5, 10, 100)\n", "v %>% map_dbl(f1)" ], - "id": "96e1a2e4-43e2-4efb-b160-b17dbc37d2ce" + "id": "1d219fd3-629d-423b-a8ba-41a2bb304da1" }, { "cell_type": "code", @@ -1382,7 +1382,7 @@ "rep(x = 10, times = 3) %>% map_dbl(f1)\n", "# \u7d50\u679c\u306f\u5272\u611b" ], - "id": "769f9e2d-845d-49a1-8471-826a5710f52e" + "id": "49b60f27-18f5-4792-b780-957b616d87a5" }, { "cell_type": "code", @@ -1399,7 +1399,7 @@ "\n", "f2(10) # \u52d5\u4f5c\u78ba\u8a8d" ], - "id": "e5ceaa9a-5bf3-4f48-b768-8bbb43f2c9d2" + "id": "36f4812e-5898-454f-a684-90d7a08e0ccd" }, { "cell_type": "code", @@ -1410,7 +1410,7 @@ "v <- c(5, 10, 100)\n", "v %>% map_dfr(f2)" ], - "id": "e1fa637d-b2d2-406b-9b2d-0a0184661377" + "id": "2cd415e7-8410-4c6d-a7cc-38d2323ddb47" }, { "cell_type": "code", @@ -1430,7 +1430,7 @@ "\n", "f3(x = 10, y = 6) # \u52d5\u4f5c\u78ba\u8a8d" ], - "id": "62bb7ac3-eaf6-4f05-9352-27aa2afa2116" + "id": "f544fb39-80bf-4418-88b4-f6a3cb9d925c" }, { "cell_type": "code", @@ -1444,7 +1444,7 @@ "\n", "my_df %>% pmap_dfr(f3)" ], - "id": "cba71d5b-238c-477f-a47a-f9783c0904e3" + "id": "9a6d19b1-b7e6-4cd3-86e2-da2a0ee9cb57" }, { "cell_type": "code", @@ -1460,10 +1460,10 @@ " furrr_options(seed = TRUE))\n", "# \u7d50\u679c\u306f\u5272\u611b" ], - "id": "bbe2233d-64bc-44b5-8bfa-24cac9577022" + "id": "21dafbe4-bfaa-4a4b-8c68-7e805149c44f" }, { - "id": "dc86e595", + "id": "1b9c303f", "cell_type": "markdown", "source": "## 3.8 \u305d\u306e\u4ed6", "metadata": {} @@ -1477,7 +1477,7 @@ "x <- 123\n", "typeof(x)" ], - "id": "6185226a-cda5-467b-bc73-90e0ed035a16" + "id": "cdfb47a0-3cd7-4182-9953-bdeec65d8020" }, { "cell_type": "code", @@ -1489,7 +1489,7 @@ "# \u3042\u308b\u3044\u306f\n", "help(log)" ], - "id": "042f4d3f-898e-4991-af8a-31ebf54e9798" + "id": "43e0f294-d752-4c53-9597-86fdac9a5ce4" }, { "cell_type": "code", @@ -1500,7 +1500,7 @@ "v <- c(1, NA, 3)\n", "v" ], - "id": "843626d4-175e-4660-ae80-e8918d6e3e7b" + "id": "afc52099-a152-42eb-86ef-4a59fb5c3498" }, { "cell_type": "code", @@ -1512,10 +1512,10 @@ "\n", "v[2] == NA # \u8aa4\u308a" ], - "id": "20536ca4-a746-44ff-a6c4-05cdcd2a8132" + "id": "d8a529f6-1f4f-4ea3-a2f3-ea6f2f560d9b" }, { - "id": "7b3960e6", + "id": "eeaae488", "cell_type": "markdown", "source": "# 4 \u7d71\u8a08\u5165\u9580", "metadata": {} @@ -1534,10 +1534,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "f328c39f-4cc9-4789-9cfd-66d92dccf673" + "id": "1bc6ca8d-2107-4930-9a62-4bb154a9dd81" }, { - "id": "354495ac", + "id": "f1585303", "cell_type": "markdown", "source": "## 4.1 \u8a18\u8ff0\u7d71\u8a08", "metadata": {} @@ -1551,7 +1551,7 @@ "x <- c(165, 170, 175, 180, 185)\n", "mean(x) # \u5e73\u5747" ], - "id": "dbdd2256-08b5-4a9c-b597-bb767da95d59" + "id": "9ba92b45-d8f7-4cf4-afeb-4b1b4e86f4b1" }, { "cell_type": "code", @@ -1562,7 +1562,7 @@ "n <- length(x) # \u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\n", "sum(x) / n" ], - "id": "a69fe5f3-1271-4c66-a0a3-68e861aaa590" + "id": "732b0eb9-536e-4c5d-be79-65105df4fd68" }, { "cell_type": "code", @@ -1573,7 +1573,7 @@ "y <- c(173, 174, 175, 176, 177)\n", "mean(y)" ], - "id": "30d90a1e-44f9-43ae-9095-158c1295275c" + "id": "b5cf31d1-661f-420d-81e5-720375b2251e" }, { "cell_type": "code", @@ -1585,7 +1585,7 @@ "\n", "var(y) # y\u306e\u5206\u6563" ], - "id": "967b268d-b396-4ea0-aad6-7c8c4eccc7a7" + "id": "9da21e67-01da-4112-8a1b-1b0c31a41e8b" }, { "cell_type": "code", @@ -1595,7 +1595,7 @@ "source": [ "sum((x - mean(x))^2) / (n - 1)" ], - "id": "be5f2fdd-bd2e-43f8-b719-7ece8052429f" + "id": "90a0bb0b-403d-42a8-8720-186093882bad" }, { "cell_type": "code", @@ -1607,7 +1607,7 @@ "\n", "sd(y) # y\u306e\u6a19\u6e96\u504f\u5dee" ], - "id": "34988514-a430-4ec2-bf26-9243b7ad9967" + "id": "a9d3183b-f46e-4994-bc0f-2d64e63624d5" }, { "cell_type": "code", @@ -1617,7 +1617,7 @@ "source": [ "var(x)**0.5 # x\u306e\u6a19\u6e96\u504f\u5dee" ], - "id": "e097f1f6-5fe1-4fa4-a031-3386b22cb039" + "id": "6d37239b-abdd-4a30-ae15-af01e31cb854" }, { "cell_type": "code", @@ -1631,7 +1631,7 @@ "\n", "pastecs::stat.desc(x)" ], - "id": "f2ae646b-a424-4699-b4fc-e54359eeeff5" + "id": "b0ac85f2-5cab-4a94-aed2-9ff986a36a3e" }, { "cell_type": "code", @@ -1641,7 +1641,7 @@ "source": [ "quantile(x)" ], - "id": "58a8eb38-f44e-43bf-8fc4-47b51a3fca0f" + "id": "15e081da-b30c-44ad-bd77-3a17f59fcd4a" }, { "cell_type": "code", @@ -1658,7 +1658,7 @@ "n <- length(x)\n", "var(x) * (n - 1) / n # \u6a19\u672c\u5206\u6563" ], - "id": "48f070cb-8015-41b0-8e99-13eb39da2ff3" + "id": "a6389cf3-e037-4253-9581-46f7dd9faaba" }, { "cell_type": "code", @@ -1672,7 +1672,7 @@ "# \u3042\u308b\u3044\u306f\n", "sd(x) * sqrt((n - 1) / n) # \u221a\u6a19\u672c\u5206\u6563" ], - "id": "3699afcc-9f2f-44df-b64d-303b3ab4c79d" + "id": "9a2ab9cb-4993-4e23-8fd5-fc64337cc8e4" }, { "cell_type": "code", @@ -1682,7 +1682,7 @@ "source": [ "sd(x) / length(x)**0.5" ], - "id": "8013fa23-09b4-487e-81e6-36091b674ff9" + "id": "51d82a42-9197-4515-b866-1b93a68f74d4" }, { "cell_type": "code", @@ -1698,7 +1698,7 @@ " math = c( 70, 80, 90, 100),\n", " gender = c(\"f\", \"m\", \"m\", \"f\"))" ], - "id": "cc30fcbe-79fa-445a-8dc4-8a0ee4a43c7f" + "id": "84f2b867-da79-4d8b-a039-b0b88f396b27" }, { "cell_type": "code", @@ -1708,7 +1708,7 @@ "source": [ "var(my_df$english)" ], - "id": "44059c6d-465b-441a-b4cf-1823db567495" + "id": "3bab0b68-13e6-49fe-9777-96f103271bf4" }, { "cell_type": "code", @@ -1738,7 +1738,7 @@ " where(is.numeric), # \u6570\u5024\u306e\u5217\u306e\n", " function(x) { var(x) })) # \u4e0d\u504f\u5206\u6563\n" ], - "id": "509cdd8f-0676-4541-81cc-f19e603d51fe" + "id": "42f467d7-19d8-4f44-88ea-52d4e7175642" }, { "cell_type": "code", @@ -1753,7 +1753,7 @@ "pastecs::stat.desc(my_df)\n", "# \u4ee5\u4e0b\u7701\u7565" ], - "id": "9377852c-26d7-4038-9d05-bd95a2d395a5" + "id": "241a942b-f455-4c37-8878-0670707fb766" }, { "cell_type": "code", @@ -1763,7 +1763,7 @@ "source": [ "table(my_df$gender)\n" ], - "id": "f0cc5f87-0c3e-45db-a805-28e3cc70b4d0" + "id": "9bba615e-f295-4e26-ab1b-f98fad87a7c7" }, { "cell_type": "code", @@ -1776,7 +1776,7 @@ " excel = my_df$math >= 80)\n", "table(my_df2)\n" ], - "id": "f91d0e7b-cfb1-4b29-b099-595008715a80" + "id": "18a04dfd-c340-4835-8641-d197a717dcc8" }, { "cell_type": "code", @@ -1789,10 +1789,10 @@ " where(is.numeric), mean),\n", " .groups = \"drop\") # \u30b0\u30eb\u30fc\u30d7\u5316\u89e3\u9664\n" ], - "id": "46353033-0d86-450a-8dac-ef4bc7b440a6" + "id": "e577ad89-e6a5-45e5-bf84-27f467597551" }, { - "id": "cc4b9e21", + "id": "e8b863c8", "cell_type": "markdown", "source": "## 4.2 \u30c7\u30fc\u30bf\u306e\u53ef\u8996\u5316", "metadata": {} @@ -1805,7 +1805,7 @@ "source": [ "head(iris)" ], - "id": "2da8e68c-8e36-4b47-91bf-f04072974578" + "id": "883dfe20-69ee-4c1a-bd1a-0d354b30ecec" }, { "cell_type": "code", @@ -1815,7 +1815,7 @@ "source": [ "hist(iris$Sepal.Length)" ], - "id": "2990ff59-65d1-422d-8111-dab9fa9277c0" + "id": "0b749b0f-e2f1-4d98-807d-a011841d5445" }, { "cell_type": "code", @@ -1826,7 +1826,7 @@ "x <- c(10, 20, 30)\n", "hist(x, breaks = 2) # \u968e\u7d1a\u6570\u306f2" ], - "id": "cb9548bb-93f5-4bd1-ba82-c26c6542b4cd" + "id": "3829e10d-87b7-41b0-bf40-25de1ee5bda1" }, { "cell_type": "code", @@ -1839,7 +1839,7 @@ " length.out = 10)\n", "hist(x, breaks = tmp, right = FALSE)" ], - "id": "3a66d267-faba-4380-8675-24290dc9ea48" + "id": "5e5ded28-ef53-4c55-92e9-9be395efe23c" }, { "cell_type": "code", @@ -1850,7 +1850,7 @@ "plot(iris$Sepal.Length,\n", " iris$Sepal.Width)" ], - "id": "334b083d-9a87-4bcd-a139-2f9bb181e1a8" + "id": "be774a5b-2e7b-43fd-86a7-29b547706190" }, { "cell_type": "code", @@ -1860,7 +1860,7 @@ "source": [ "boxplot(iris[, -5])" ], - "id": "06aabf23-6a09-4a1c-a540-867a16e886a9" + "id": "4341c44e-ada8-49bb-9c1d-90d2e6d67573" }, { "cell_type": "code", @@ -1872,7 +1872,7 @@ "my_df <- psych::describe(iris[, -5])\n", "my_df %>% select(mean, sd, se)" ], - "id": "5fd164f1-bf03-4d9d-b86b-9f8dad9dac8e" + "id": "bb895ee1-ba11-4fdc-94e4-d0ab19cd0f2d" }, { "cell_type": "code", @@ -1886,7 +1886,7 @@ " geom_errorbar(aes(ymin = mean - se, ymax = mean + se)) +\n", " xlab(NULL)" ], - "id": "067b3933-e14f-4a70-a5a8-70ebf7953e5a" + "id": "b375ed6e-9ab7-48e0-ab5b-c8380bd76b66" }, { "cell_type": "code", @@ -1907,7 +1907,7 @@ "my_df$se <- tmp$value\n", "head(my_df)" ], - "id": "142f4b09-63dd-4e0e-bd78-23a31ed6eb58" + "id": "3f41f21d-b059-4532-8069-a3470f8f2126" }, { "cell_type": "code", @@ -1920,7 +1920,7 @@ " geom_col(position = \"dodge\") +\n", " geom_errorbar(aes(ymin = value - se, ymax = value + se), position = \"dodge\")" ], - "id": "bf220d6f-7777-4dec-a9df-dec3f206d09a" + "id": "97b382ee-0459-4e30-9c91-2ff67d71a01c" }, { "cell_type": "code", @@ -1941,7 +1941,7 @@ " geom_bar(stat = \"summary\", fun = mean, position = \"dodge\") +\n", " stat_summary(geom = \"errorbar\", fun.data = mean_se, position = \"dodge\")" ], - "id": "bb81eaa0-701e-4568-90b7-134549cf29da" + "id": "8d110e54-05ce-4778-993e-34b1d7faa33e" }, { "cell_type": "code", @@ -1958,7 +1958,7 @@ " formula = ~ Species + w_Sepal,\n", " data = my_df)" ], - "id": "4d23384d-b3bb-49a7-9ff0-bef7078e89e1" + "id": "99b444a3-e8d1-4682-a85a-757b4b2cc440" }, { "cell_type": "code", @@ -1970,7 +1970,7 @@ "vcd::mosaic(formula = ~w_Sepal + Species, data = my_df,\n", " labeling = labeling_values)" ], - "id": "66e809e9-140b-42aa-9038-b74380ba5461" + "id": "8212beb2-11fe-4917-871c-546effbd7af1" }, { "cell_type": "code", @@ -1980,7 +1980,7 @@ "source": [ "curve(x^3 - x, -2, 2)" ], - "id": "91858a9c-729d-4397-98e4-98e2abcd0ca3" + "id": "995e45f7-e9bc-4f81-84ed-a2d9dae2786f" }, { "cell_type": "code", @@ -1996,7 +1996,7 @@ " geom_histogram(breaks = tmp,\n", " closed = \"left\")" ], - "id": "e1329145-bc9b-464c-8f4e-f65135e713d9" + "id": "01a7186d-8453-45ca-810c-d88245377cdc" }, { "cell_type": "code", @@ -2009,7 +2009,7 @@ " y = Sepal.Width)) +\n", " geom_point()" ], - "id": "4ed9e4a8-fd2b-48cd-b648-9fc1cdbf12ac" + "id": "bb8dd24d-5c1f-4fa7-9cbc-dbd91e6de2cc" }, { "cell_type": "code", @@ -2026,7 +2026,7 @@ " geom_boxplot() +\n", " xlab(NULL)" ], - "id": "070970a5-b698-44c8-b735-6b2482b70bdc" + "id": "830d90c8-62a3-4821-8e78-a1c5a7b697ae" }, { "cell_type": "code", @@ -2043,7 +2043,7 @@ " geom_mosaic(\n", " aes(x = product(w_Sepal, Species)))" ], - "id": "5b75d112-63cc-426f-bd22-7b11aca1169b" + "id": "55da998c-7352-440e-9d88-a84e83e58104" }, { "cell_type": "code", @@ -2056,10 +2056,10 @@ " ggplot(aes(x = x)) +\n", " stat_function(fun = f)" ], - "id": "94234a70-48cf-49a2-9043-192c13f059cd" + "id": "a35d81f7-58b8-42cd-8575-4d678938bf97" }, { - "id": "cd6f7c7e", + "id": "0bb9f790", "cell_type": "markdown", "source": "## 4.3 \u4e71\u6570", "metadata": {} @@ -2075,7 +2075,7 @@ " replace = TRUE) # \u91cd\u8907\u3042\u308a\n", "hist(x, breaks = 0:6) # \u30d2\u30b9\u30c8\u30b0\u30e9\u30e0" ], - "id": "90f5392c-0c41-4f31-8803-ec3f7df0302e" + "id": "f7b618fc-71ca-4042-8bf4-c91a32f8a5ef" }, { "cell_type": "code", @@ -2088,7 +2088,7 @@ " n = 1000) # \u4e71\u6570\u306e\u6570\n", "hist(x)" ], - "id": "3d447f17-7086-466d-999f-c8edbd50c740" + "id": "79572b8c-8362-4aa1-befb-132ee1a5986c" }, { "cell_type": "code", @@ -2102,7 +2102,7 @@ " n = 1000)) # \u4e71\u6570\u306e\u6570\n", "hist(x, breaks = 0:6) # \u7d50\u679c\u306f\u5272\u611b" ], - "id": "860195b7-d7e1-460e-88e4-a1b8f79ea2e7" + "id": "e91fa1ba-388f-4165-a42b-98238441c479" }, { "cell_type": "code", @@ -2118,7 +2118,7 @@ " n = r) # \u4e71\u6570\u306e\u6570\n", "hist(x, breaks = max(x) - min(x))" ], - "id": "eaacb7d8-6132-4888-ab9f-5e8162c9184f" + "id": "dab47d8e-a90f-4449-ae15-baf598d195cc" }, { "cell_type": "code", @@ -2132,7 +2132,7 @@ " n = r) # \u4e71\u6570\u306e\u6570\n", "hist(x, breaks = 40)" ], - "id": "24f91153-202f-40b8-bfa5-6b7227c9ab63" + "id": "c6141dad-cc4b-4a27-b267-06ff5fb51d47" }, { "cell_type": "code", @@ -2150,7 +2150,7 @@ " se = sd(tmp) / sqrt(n)) # \u6a19\u6e96\u8aa4\u5dee\n", "}" ], - "id": "087a9c95-df14-4953-b583-fed0dadb4e4d" + "id": "f0037339-566c-466c-a61d-578887fb4e19" }, { "cell_type": "code", @@ -2161,7 +2161,7 @@ "g <- var\n", "c(10, 20, 30) %>% map_dfr(f)" ], - "id": "9b646f6f-fc9a-42a0-907f-6c33fced48c9" + "id": "54316139-062a-4547-b42b-feb443976ed0" }, { "cell_type": "code", @@ -2172,7 +2172,7 @@ "g <- sd\n", "c(5, 10, 15, 20) %>% map_dfr(f)" ], - "id": "2d449615-8ad3-4907-be48-7a0c10afdba8" + "id": "3c314402-bed9-430f-b3c6-ff6c3c1040c7" }, { "cell_type": "code", @@ -2189,10 +2189,10 @@ "}\n", "c(10, 20, 30) %>% map_dfr(f)" ], - "id": "496d2a16-558e-4d25-b2e3-3e3a99238ec8" + "id": "5f58d7ca-0378-45ce-876c-51b399395d41" }, { - "id": "3e775b39", + "id": "aabb17fc", "cell_type": "markdown", "source": "## 4.4 \u7d71\u8a08\u7684\u63a8\u6e2c", "metadata": {} @@ -2217,7 +2217,7 @@ " # \u5de6\u7247\u5074\u691c\u5b9a\u306a\u3089'less'\n", " # \u53f3\u7247\u5074\u691c\u5b9a\u306a\u3089'greater'\n" ], - "id": "9468c753-e1cc-4df9-9d75-89d260d8400e" + "id": "43294893-42c2-41d3-a13f-17633f58ef19" }, { "cell_type": "code", @@ -2241,7 +2241,7 @@ " geom_hline(yintercept = my_pr2) + # \u6c34\u5e73\u7dda\n", " theme(legend.position = \"none\") # \u51e1\u4f8b\u3092\u8868\u793a\u3057\u306a\u3044\uff0e" ], - "id": "ff10e55d-2ad2-4a03-b66e-231d13b5fc4b" + "id": "0dee0fcf-5b29-406b-9813-8e3903e0fd4a" }, { "cell_type": "code", @@ -2251,7 +2251,7 @@ "source": [ "# \u524d\u9805\u306e\u7d50\u679c\uff08\u518d\u63b2\uff09" ], - "id": "6c27a3d6-fbda-4016-813d-8f9b7e3054c1" + "id": "0e5de86e-58e1-48fd-aa6c-023aef7bcf00" }, { "cell_type": "code", @@ -2261,7 +2261,7 @@ "source": [ "# \u524d\u9805\u5192\u982d\u306e\u30b3\u30fc\u30c9" ], - "id": "596e49ff-2d2a-4676-85be-c8339add64c7" + "id": "aa85b71d-a4fe-439c-bb6a-59fbd1d12959" }, { "cell_type": "code", @@ -2281,7 +2281,7 @@ " # \u5de6\u7247\u5074\u691c\u5b9a\u306a\u3089'less'\n", " # \u53f3\u7247\u5074\u691c\u5b9a\u306a\u3089'greater'\n" ], - "id": "8a84fdf4-efb0-49a8-a450-a2958904a16d" + "id": "f6ffacaf-2585-4b13-ae67-2cc30bf771f9" }, { "cell_type": "code", @@ -2295,7 +2295,7 @@ " alternative = \"two.sided\",\n", " conf.level = 0.95)\n" ], - "id": "d0424632-e7e5-4227-bc57-1bbafcf65e8d" + "id": "bee03a85-3f86-430a-9a5c-1b923d8e9150" }, { "cell_type": "code", @@ -2307,7 +2307,7 @@ " \"/fromzero/master/data/smoker.csv\")\n", "my_data <- read_csv(my_url)" ], - "id": "dcd6f0bf-4852-45f1-b7a7-54e57987f841" + "id": "430bcdb1-7408-4cea-81fd-cea615777258" }, { "cell_type": "code", @@ -2317,7 +2317,7 @@ "source": [ "head(my_data)" ], - "id": "00fe9c8b-0d0b-4e1b-aae9-5609d85c2a5a" + "id": "ade4d3c1-f89e-4c78-b539-e30010948e13" }, { "cell_type": "code", @@ -2328,7 +2328,7 @@ "my_table <- table(my_data)\n", "my_table" ], - "id": "9d7f497a-03d0-4fda-91f2-caf5b2621f99" + "id": "c27dff41-c70e-417f-bdbb-c497158a63f2" }, { "cell_type": "code", @@ -2338,7 +2338,7 @@ "source": [ "chisq.test(my_table, correct = FALSE)\n" ], - "id": "c99b325f-9c09-4afd-9571-5c90601fb9cc" + "id": "5ebc2db4-c1ef-4ca0-8a7e-5ee04b8fe38d" }, { "cell_type": "code", @@ -2357,7 +2357,7 @@ "n <- 10^5\n", "result <- replicate(n, sum(sample(X, size = length(X), replace = TRUE))) # \u624b\u98064" ], - "id": "f246aa1d-abbe-4d8a-998d-344349ff57f8" + "id": "1368aa64-81e2-4283-a3b3-c3181a4983c8" }, { "cell_type": "code", @@ -2368,7 +2368,7 @@ "hist(x = result, breaks = 0:15,\n", " right = FALSE)" ], - "id": "f946f6db-7273-4b51-9ea8-4e5a98024ab3" + "id": "b9792825-bbc7-4bb4-8163-501bed8015f4" }, { "cell_type": "code", @@ -2378,10 +2378,10 @@ "source": [ "quantile(result, c(0.025, 0.975))" ], - "id": "de707b6d-a073-48f8-9f21-a848330f735b" + "id": "7c6d2f8b-0d69-449c-a12e-109d12d09d69" }, { - "id": "8af71634", + "id": "602a7989", "cell_type": "markdown", "source": "# 5 \u524d\u51e6\u7406", "metadata": {} @@ -2400,10 +2400,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "57c517e5-d595-480d-aa70-f5b5bb2aaa8d" + "id": "dd094285-faf6-459a-8a17-10a931921bf2" }, { - "id": "27512c9b", + "id": "61066208", "cell_type": "markdown", "source": "## 5.1 \u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f", "metadata": {} @@ -2418,7 +2418,7 @@ "system(str_c(\"wget https://raw.githubusercontent.com/taroyabuki\",\n", " \"/fromzero/master/data/exam.csv\"))" ], - "id": "0c21352d-af77-4ebc-888b-7d254f641e3a" + "id": "d4743cf4-dda7-4c5e-a268-5883b05d2046" }, { "cell_type": "code", @@ -2433,7 +2433,7 @@ "\n", "my_df" ], - "id": "7479aabe-019c-4673-b203-a3e2111b1399" + "id": "cdd5c8fe-8947-4d05-bb9d-bdaca04d76ed" }, { "cell_type": "code", @@ -2447,7 +2447,7 @@ "# \u3042\u308b\u3044\u306f\n", "my_df <- read.csv(my_url, stringsAsFactors = FALSE)" ], - "id": "a1265c17-e608-47b6-8f6a-414b03505ceb" + "id": "9baa8030-1a7a-4f57-9b4b-7ad6f8e5be31" }, { "cell_type": "code", @@ -2461,7 +2461,7 @@ " row.names = 1)\n", "my_df2" ], - "id": "bf3be186-7cc4-4bbd-94b7-fe4a887cc7e0" + "id": "cc288ce8-37d7-4b14-b4b1-af470ba27a81" }, { "cell_type": "code", @@ -2475,7 +2475,7 @@ " file = \"exam2.csv\",\n", " row.names = FALSE)" ], - "id": "91ef3745-8456-4ad9-bfee-bddb064f0ab1" + "id": "40af9853-22d9-4149-8e13-ba99e0b7ca0c" }, { "cell_type": "code", @@ -2485,7 +2485,7 @@ "source": [ "my_df2 %>% write.csv(\"exam3.csv\")" ], - "id": "3bc426d0-bb4c-472e-a613-089fdd632ac7" + "id": "515e01f5-c0b0-4815-bf01-6314fea34188" }, { "cell_type": "code", @@ -2500,7 +2500,7 @@ " stringsAsFactors = FALSE,\n", " fileEncoding = \"UTF-8\")" ], - "id": "642adf13-6047-4be4-a6e3-2d08aa6f8167" + "id": "e5257494-f937-4c51-9220-2a911a75554a" }, { "cell_type": "code", @@ -2513,7 +2513,7 @@ "my_df %>% write.csv(file = \"exam2.csv\", row.names = FALSE,\n", " fileEncoding = \"UTF-8\")" ], - "id": "e91bcb20-f253-4766-a703-286e883d5073" + "id": "79b5a5c7-22c6-49e5-96bb-1308fd5f5882" }, { "cell_type": "code", @@ -2524,7 +2524,7 @@ "my_url <- \"https://taroyabuki.github.io/fromzero/exam.html\"\n", "my_tables <- xml2::read_html(my_url) %>% rvest::html_table()" ], - "id": "c05be332-b6e1-42bf-870f-e8cca8916038" + "id": "e5126f61-f7bc-45e5-a245-e079d840765c" }, { "cell_type": "code", @@ -2534,7 +2534,7 @@ "source": [ "my_tables" ], - "id": "bf674453-7707-4bb8-9d82-cb519c90976d" + "id": "1189b21b-c48e-4eb9-9018-ecec489729aa" }, { "cell_type": "code", @@ -2545,7 +2545,7 @@ "tmp <- my_tables[[1]]\n", "tmp" ], - "id": "2793f4cd-5c73-4acf-a189-84ffac1fa968" + "id": "8bff8d06-64df-417f-a19c-5e720301c024" }, { "cell_type": "code", @@ -2560,7 +2560,7 @@ "my_data <- tmp[-1, -1]\n", "my_data" ], - "id": "4d8a467a-c00f-4a21-a6b9-fb33ceb4ba45" + "id": "115e5c02-6aae-46d7-81ba-61f2ebde2a20" }, { "cell_type": "code", @@ -2575,7 +2575,7 @@ "#my_data <- fromJSON(\"exam.json\") # \uff08\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u3046\u5834\u5408\uff09\n", "my_data" ], - "id": "b625f730-83a4-4b52-ac49-e5db481fda9e" + "id": "4cea1087-3681-4ab2-8c95-6fb5fe3d41f7" }, { "cell_type": "code", @@ -2590,7 +2590,7 @@ "#my_xml <- read_xml(\"exam.xml\") # \uff08\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u3046\u5834\u5408\uff09\n", "xml_ns(my_xml) # \u540d\u524d\u7a7a\u9593\u306e\u78ba\u8a8d\uff08d1\uff09" ], - "id": "624db771-38b4-41ad-ae63-eb6c2064996b" + "id": "82d78d62-0849-4f72-b27c-b9ca6b68cd75" }, { "cell_type": "code", @@ -2600,7 +2600,7 @@ "source": [ "my_records <- xml_find_all(my_xml, \".//d1:record\")" ], - "id": "31edc154-5a90-4bc0-91b3-b97edb014f03" + "id": "89c48d3e-74ab-486d-94d7-85214097b7c0" }, { "cell_type": "code", @@ -2616,7 +2616,7 @@ " tmp\n", "}" ], - "id": "00b2c561-4317-422c-af36-0f9787fb6047" + "id": "a6048b0e-89e9-4e26-b7eb-e9b106177b0b" }, { "cell_type": "code", @@ -2629,10 +2629,10 @@ "my_data$math <- as.numeric(my_data$math)\n", "my_data" ], - "id": "6bedcf39-dc85-4052-9bcf-d203166ec833" + "id": "1da50026-073f-4153-8673-39b3a9dd1747" }, { - "id": "a45b9ff2", + "id": "23841c33", "cell_type": "markdown", "source": "## 5.2 \u30c7\u30fc\u30bf\u306e\u5909\u63db", "metadata": {} @@ -2651,7 +2651,7 @@ "\n", "z1" ], - "id": "64adaa0d-7600-4c20-99c1-4390020964c5" + "id": "744710ea-75b5-47c5-add6-82067a60d3cb" }, { "cell_type": "code", @@ -2661,7 +2661,7 @@ "source": [ "c(mean(z1), sd(z1))" ], - "id": "4931bbc8-ba63-49e9-8bab-f7fc5479b789" + "id": "758d60a8-9cb0-47e2-a1e8-1db96c145dca" }, { "cell_type": "code", @@ -2671,7 +2671,7 @@ "source": [ "z1 * sd(x1) + mean(x1)" ], - "id": "212316f2-4356-448a-87d0-93e000d7971c" + "id": "f6499da0-080d-4009-acf0-ee499b422f12" }, { "cell_type": "code", @@ -2683,7 +2683,7 @@ "z2 <- (x2 - mean(x1)) / sd(x1)\n", "c(mean(z2), sd(z2))" ], - "id": "86748452-1b1c-4e20-b2d0-7ab7e85e2120" + "id": "f8b569ca-ae77-496e-8394-75b15cd8c28b" }, { "cell_type": "code", @@ -2704,7 +2704,7 @@ "\n", "my_enc %>% predict(my_df)" ], - "id": "0c6de366-83d0-48d7-9924-d58578c6390b" + "id": "ea6a9608-e3fd-43cf-b458-e0a99aa1c01f" }, { "cell_type": "code", @@ -2717,7 +2717,7 @@ " class = c(\"B\", \"C\", \"B\"))\n", "my_enc %>% predict(my_df2)" ], - "id": "c53985e1-263b-4da7-bd5c-b9d6925b3d4e" + "id": "41ec009c-6d88-4ded-afe0-198dd79ee151" }, { "cell_type": "code", @@ -2732,22 +2732,22 @@ "\n", "my_enc %>% predict(my_df2)" ], - "id": "ab27532f-5d97-4db0-bca1-b3fc09fd4630" + "id": "51127bdc-1f06-4b4a-a3f8-c773d1975893" }, { - "id": "2d6d9925", + "id": "2107dacd", "cell_type": "markdown", "source": "# 6 \u6a5f\u68b0\u5b66\u7fd2\u306e\u76ee\u7684\u30fb\u30c7\u30fc\u30bf\u30fb\u624b\u6cd5\n\n\n", "metadata": {} }, { - "id": "a440799a", + "id": "4d8aac8b", "cell_type": "markdown", "source": "## 6.1 \u6a5f\u68b0\u5b66\u7fd2\u306e\u76ee\u7684\uff08\u672c\u66f8\u306e\u5834\u5408\uff09\n\n\n", "metadata": {} }, { - "id": "69a21b62", + "id": "cd300d92", "cell_type": "markdown", "source": "## 6.2 \u6a5f\u68b0\u5b66\u7fd2\u306e\u305f\u3081\u306e\u30c7\u30fc\u30bf", "metadata": {} @@ -2761,16 +2761,16 @@ "iris\n", "# \u4ee5\u4e0b\u7701\u7565" ], - "id": "b773649f-0013-466d-aabe-0417f3e4740b" + "id": "a2be3226-8258-47d4-b236-6ead903be717" }, { - "id": "c84d5a27", + "id": "c0b32958", "cell_type": "markdown", "source": "## 6.3 \u6a5f\u68b0\u5b66\u7fd2\u306e\u305f\u3081\u306e\u624b\u6cd5\n\n\n", "metadata": {} }, { - "id": "1b085f2e", + "id": "477ba90d", "cell_type": "markdown", "source": "# 7 \u56de\u5e301\uff08\u5358\u56de\u5e30\uff09", "metadata": {} @@ -2789,16 +2789,16 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "1977d057-098d-4cf9-8ece-61816b83c718" + "id": "48efd7fa-ebe6-48b0-8ff2-5c744ca394fc" }, { - "id": "cd2602e0", + "id": "f8e544e4", "cell_type": "markdown", "source": "## 7.1 \u81ea\u52d5\u8eca\u306e\u505c\u6b62\u8ddd\u96e2\n\n\n", "metadata": {} }, { - "id": "f526114c", + "id": "a93390b1", "cell_type": "markdown", "source": "## 7.2 \u30c7\u30fc\u30bf\u306e\u78ba\u8a8d", "metadata": {} @@ -2813,7 +2813,7 @@ "library(tidyverse)\n", "my_data <- cars" ], - "id": "004c56ce-eaa3-4997-b295-04ea511ab264" + "id": "9b196191-b7d4-4fe2-93c8-d007b4f02f2a" }, { "cell_type": "code", @@ -2823,7 +2823,7 @@ "source": [ "dim(my_data)" ], - "id": "7f93f7aa-0bb7-454f-9747-c098ca85261c" + "id": "723dfa95-d712-402f-9624-559c8c25c236" }, { "cell_type": "code", @@ -2833,7 +2833,7 @@ "source": [ "head(my_data)" ], - "id": "2a6f84bf-4851-45c4-b033-41eaa133454f" + "id": "e4f9d8ea-3f80-44d8-bbdf-adc59e6aa254" }, { "cell_type": "code", @@ -2844,7 +2844,7 @@ "options(digits = 3)\n", "pastecs::stat.desc(my_data)" ], - "id": "80d9cc61-976a-4cca-906e-dc1ea9bbc13d" + "id": "984355cf-560b-4d36-b634-43b572bd7648" }, { "cell_type": "code", @@ -2856,10 +2856,10 @@ " ggplot(aes(x = speed, y = dist)) +\n", " geom_point()" ], - "id": "b25f3830-83a8-4671-9cee-aceb17e508bc" + "id": "54cff757-523e-4c6a-b6f2-6d421dcb2847" }, { - "id": "7fe59eab", + "id": "d9d5b808", "cell_type": "markdown", "source": "## 7.3 \u56de\u5e30\u5206\u6790", "metadata": {} @@ -2881,7 +2881,7 @@ " geom_pointrange(data = tmp, aes(ymin = -9, ymax = dist), linetype = \"dotted\") +\n", " geom_pointrange(data = tmp, aes(xmin = 0, xmax = speed), linetype = \"dotted\")" ], - "id": "12132f0d-8ada-4adb-88f7-f126690c19cc" + "id": "607b9529-e1f2-4d36-90fc-f368f188aab0" }, { "cell_type": "code", @@ -2893,7 +2893,7 @@ "library(tidyverse)\n", "my_data <- cars" ], - "id": "539012de-71bf-4390-8c34-34c56101bf84" + "id": "4641fe2a-fac2-48dc-8bdb-1f44fa4cca81" }, { "cell_type": "code", @@ -2905,7 +2905,7 @@ " data = my_data, # \u30c7\u30fc\u30bf\n", " method = \"lm\") # \u624b\u6cd5" ], - "id": "9d6e9cac-9421-44c5-ba92-f1930898143b" + "id": "a731a865-940e-4583-9b69-b374a8465adb" }, { "cell_type": "code", @@ -2915,7 +2915,7 @@ "source": [ "coef(my_model$finalModel)" ], - "id": "7dd6fce4-70f8-43a7-b37d-37aa30d9733a" + "id": "9fb4ebb8-3fae-4296-800d-ec4d5d1b33f7" }, { "cell_type": "code", @@ -2926,7 +2926,7 @@ "tmp <- data.frame(speed = 21.5)\n", "my_model %>% predict(tmp)" ], - "id": "f9c75163-9b00-451b-8666-c2059b3d3169" + "id": "ff4a2ea1-0c30-4d93-a924-5d3a0552de89" }, { "cell_type": "code", @@ -2936,7 +2936,7 @@ "source": [ "f <- function(x) { my_model %>% predict(data.frame(speed = x)) }" ], - "id": "b3be7081-c658-4d28-9f05-97e47abaf7df" + "id": "51e1cc39-7a37-459e-aae4-6e24d7becfda" }, { "cell_type": "code", @@ -2952,10 +2952,10 @@ " fun = f,\n", " mapping = aes(color = \"model\"))" ], - "id": "601cf5be-f2ec-4729-9e53-4e07cc5db57f" + "id": "e3038083-9763-4f35-a00c-95caa6046117" }, { - "id": "ed56acc2", + "id": "f63f7698", "cell_type": "markdown", "source": "## 7.4 \u5f53\u3066\u306f\u307e\u308a\u306e\u826f\u3055\u306e\u6307\u6a19", "metadata": {} @@ -2975,7 +2975,7 @@ "y_ <- my_model %>% predict(my_data)\n", "my_data$y_ <- y_" ], - "id": "6380af7d-ffeb-470e-be96-f15d1fa3e9c1" + "id": "2e75dd51-8cca-4be5-a368-99ad74df1882" }, { "cell_type": "code", @@ -2986,7 +2986,7 @@ "my_data$residual <- y - y_\n", "head(my_data)" ], - "id": "fb5ee7d9-9aab-45c7-8203-86ae35922729" + "id": "f8fb356e-4227-48c8-8c7c-202044595f01" }, { "cell_type": "code", @@ -3000,7 +3000,7 @@ " geom_line(aes(x = speed, y = y_)) +\n", " geom_linerange(mapping = aes(ymin = y_, ymax = dist), linetype = \"dotted\")" ], - "id": "c1fc6ee1-4bd7-48d7-9b2b-b3a7642a5940" + "id": "0cf87571-65df-4318-80a1-b48fb8439643" }, { "cell_type": "code", @@ -3012,7 +3012,7 @@ "# \u3042\u308b\u3044\u306f\n", "mean((my_data$residual^2))**0.5\n" ], - "id": "eae71bd7-1474-4649-b6e7-2221d66c8e61" + "id": "d4e51d53-9e1a-4655-83dc-eff101a27c3e" }, { "cell_type": "code", @@ -3023,7 +3023,7 @@ "R2(pred = y_, obs = y,\n", " form = \"traditional\")" ], - "id": "19c6f907-8a21-4bee-a5ca-c53680d31b0c" + "id": "8482915e-ede9-44c4-a06c-d3cfa408f1f9" }, { "cell_type": "code", @@ -3036,7 +3036,7 @@ "# \u3042\u308b\u3044\u306f\n", "summary(my_model$finalModel)$r.squared" ], - "id": "2aaba8c9-a71f-4e45-95c0-8c20bacbbe57" + "id": "d6aef545-431b-49a8-8a2c-19f2e9f365dc" }, { "cell_type": "code", @@ -3054,7 +3054,7 @@ "R2(pred = y_, obs = y,\n", " form = \"corr\")" ], - "id": "51a45fec-b0d1-46c6-abd5-f5c5a75469a4" + "id": "e94f09e4-16ad-46c6-99e6-d76e04b6aa81" }, { "cell_type": "code", @@ -3068,7 +3068,7 @@ "my_idx <- c(2, 11, 27, 34, 39, 44)\n", "my_sample <- my_data[my_idx, ]" ], - "id": "0d088c68-fdfc-4a9e-b036-f75f4d2b9a13" + "id": "b04fc193-8242-45be-a02c-282f5747ac95" }, { "cell_type": "code", @@ -3085,7 +3085,7 @@ "y <- my_sample$dist\n", "y_ <- my_model %>% predict(my_sample)" ], - "id": "f2b8adaa-f675-4c3d-abd8-2d8afdf5b0f8" + "id": "eddac552-073f-43c1-9f69-efa2c03c17c6" }, { "cell_type": "code", @@ -3101,7 +3101,7 @@ "R2(pred = y_, obs = y,\n", " form = \"corr\")" ], - "id": "2f7c4490-d525-485a-b8d7-e877de4711f1" + "id": "d48e8d85-693f-4c33-ae05-7c1b7e838ba4" }, { "cell_type": "code", @@ -3118,10 +3118,10 @@ " stat_function(fun = f, mapping = aes(color = \"model\")) +\n", " coord_cartesian(ylim = c(0, 120))" ], - "id": "60d9d8da-41e5-4267-a988-88ec9f1bc021" + "id": "f9e87ecc-d2f3-4025-a1f0-f5a4077535a3" }, { - "id": "4ca609c2", + "id": "86c5a214", "cell_type": "markdown", "source": "## 7.5 K\u6700\u8fd1\u508d\u6cd5", "metadata": {} @@ -3143,7 +3143,7 @@ "# \u53ef\u8996\u5316\u306e\u6e96\u5099\n", "f <- function(x) { my_model %>% predict(data.frame(speed = x))}" ], - "id": "ca73e603-c3b8-4049-b55d-fac2e4aed5b7" + "id": "3c0ae9cd-f649-4add-84c3-e14143d56e3e" }, { "cell_type": "code", @@ -3160,7 +3160,7 @@ " fun = f,\n", " mapping = aes(color = \"model\"))" ], - "id": "e93541fc-748d-4bfc-b36c-fda5243ff966" + "id": "74735d61-f9b7-4a8e-9e82-d90155075afd" }, { "cell_type": "code", @@ -3179,10 +3179,10 @@ "R2(pred = y_, obs = y,\n", " form = \"corr\")" ], - "id": "04aba1f1-1eec-41d8-aec7-333bf9f5ca0b" + "id": "7ab8fbe5-19fe-498f-b6c5-d5a6d0f6b937" }, { - "id": "5a2d0452", + "id": "95c29cd4", "cell_type": "markdown", "source": "## 7.6 \u691c\u8a3c", "metadata": {} @@ -3200,7 +3200,7 @@ "\n", "my_model$results" ], - "id": "aea8a0b0-88f0-4afe-a7f6-9cf0411754e8" + "id": "7126dd63-d822-40c7-8a83-d99551db203f" }, { "cell_type": "code", @@ -3212,7 +3212,7 @@ " trControl = trainControl(method = \"cv\", number = 5))\n", "my_model$results" ], - "id": "59db06fe-ea2b-4684-9339-6667ed0c0b26" + "id": "6b3386bb-193d-4f02-b9f2-757b6d06f05e" }, { "cell_type": "code", @@ -3224,7 +3224,7 @@ " trControl = trainControl(method = \"LOOCV\"))\n", "my_model$results" ], - "id": "9a4c3220-bc3d-459b-a4b8-521a727a91ad" + "id": "679eeba2-a963-4ab6-8909-b8b32d5080d7" }, { "cell_type": "code", @@ -3236,7 +3236,7 @@ "cl <- makeCluster(detectCores())\n", "registerDoParallel(cl)" ], - "id": "a6c01487-4b44-46bb-82b9-1e64b21efb17" + "id": "5e817ce5-2ba7-4a24-83b9-6f3e3421f789" }, { "cell_type": "code", @@ -3251,7 +3251,7 @@ "y <- my_data$dist\n", "y_ <- my_model %>% predict(my_data)" ], - "id": "e7f956c3-f191-4ba0-a618-25bd1a015eb7" + "id": "2ebe7790-88e0-4c9c-b3b6-413b45e1022a" }, { "cell_type": "code", @@ -3270,7 +3270,7 @@ "R2(pred = y_, obs = y,\n", " form = \"corr\")" ], - "id": "cd348cb9-16e0-4bd7-b2ee-56ad5e4a42fa" + "id": "015e893e-ac2a-4d35-813d-2ddb68550cb7" }, { "cell_type": "code", @@ -3280,7 +3280,7 @@ "source": [ "postResample(pred = y_, obs = y)" ], - "id": "7b0905d1-134c-46aa-b908-ce54ea2db26f" + "id": "f69bf55f-5428-43c5-abb3-710a76047c16" }, { "cell_type": "code", @@ -3292,7 +3292,7 @@ "my_model$results\n", "# \u5de6\u304b\u3089\uff0cRMSE\uff08\u691c\u8a3c\uff09\uff0c\u6c7a\u5b9a\u4fc2\u65706\uff08\u691c\u8a3c\uff09\uff0cMAE\uff08\u691c\u8a3c\uff09" ], - "id": "98914747-1c66-4b24-be4a-8780dc619bec" + "id": "7d65bf96-8602-4390-9594-4cb3352a47bd" }, { "cell_type": "code", @@ -3311,7 +3311,7 @@ "y_ <- my_model$pred$pred\n", "mean((y - y_)^2)**0.5" ], - "id": "4620f50d-ac59-4943-a044-64a68264e1cf" + "id": "9f863a74-2baf-4f5d-a93c-49edcd08cd55" }, { "cell_type": "code", @@ -3321,7 +3321,7 @@ "source": [ "mean(((y - y_)^2)**0.5)" ], - "id": "792b256f-b36a-4219-96bc-79add0c12d03" + "id": "f253bd69-2cb5-45cf-9fe7-ef65a8ee1f2b" }, { "cell_type": "code", @@ -3340,7 +3340,7 @@ " tuneGrid = data.frame(k = 5),\n", " trControl = trainControl(method = \"LOOCV\"))" ], - "id": "a9b38206-c6ff-45a1-bbc6-6d348ecbcdad" + "id": "e19a72fc-ecfa-41eb-8748-e6c60a452790" }, { "cell_type": "code", @@ -3352,7 +3352,7 @@ "\n", "my_knn_model$results$RMSE" ], - "id": "e7885f38-32ea-46f4-9833-11d3caf3adbf" + "id": "344e1667-0c18-4efe-bd58-a4e7f4cc4ab0" }, { "cell_type": "code", @@ -3370,7 +3370,7 @@ "\n", "head(my_df)" ], - "id": "38cc3b6a-c8c8-4c8c-9254-f43036dbbbd7" + "id": "22951462-27ff-40f2-b53b-0934a1d7ec7e" }, { "cell_type": "code", @@ -3380,7 +3380,7 @@ "source": [ "boxplot(my_df, ylab = \"r^2\")" ], - "id": "7e8862c9-bacc-40e0-9a42-4d33511af624" + "id": "807dd781-3492-4f0f-badf-98cafd2f1a66" }, { "cell_type": "code", @@ -3393,10 +3393,10 @@ " paired = TRUE,\n", " alternative = \"two.sided\")\n" ], - "id": "bac5cd9b-cfc6-4cb3-baa0-ef0dce876235" + "id": "62676836-cd23-43aa-8434-3a710f24b6b8" }, { - "id": "dfc7c100", + "id": "62250f0c", "cell_type": "markdown", "source": "## 7.7 \u30d1\u30e9\u30e1\u30fc\u30bf\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0", "metadata": {} @@ -3413,7 +3413,7 @@ "my_model <- train(form = dist ~ speed, data = my_data, method = \"knn\")\n", "my_model$results" ], - "id": "5c016d4d-c952-4396-998b-1a7201f59df5" + "id": "a024695b-0c7a-4d51-9470-afbba9e93008" }, { "cell_type": "code", @@ -3427,7 +3427,7 @@ " tuneGrid = my_params,\n", " trControl = trainControl(method = \"LOOCV\"))" ], - "id": "42d01ebe-c6dd-4c84-bc1f-eb1556547fa0" + "id": "afe48cdb-25da-4007-a83e-16d89da10cbc" }, { "cell_type": "code", @@ -3437,7 +3437,7 @@ "source": [ "head(my_model$results)" ], - "id": "f8099bf8-26a6-4684-ad21-c3499e3f2ed7" + "id": "fb927952-6673-4292-8e55-4b234f983de6" }, { "cell_type": "code", @@ -3447,7 +3447,7 @@ "source": [ "ggplot(my_model)" ], - "id": "34cc246b-5f80-4a17-b04a-296b0eed09f7" + "id": "87b75821-ece4-4804-8bf5-c8f2548fb040" }, { "cell_type": "code", @@ -3457,7 +3457,7 @@ "source": [ "my_model$bestTune" ], - "id": "6112735d-7dc3-4bc0-a8b1-a394d9406bab" + "id": "34474e33-477f-4965-8fcc-1ba44ca64b56" }, { "cell_type": "code", @@ -3468,7 +3468,7 @@ "my_model$results %>%\n", " filter(RMSE == min(RMSE))" ], - "id": "99c4e00a-55bd-4864-8e02-35e6d49f8448" + "id": "00dbe773-659d-48c3-b970-ef7fcdf146e6" }, { "cell_type": "code", @@ -3480,7 +3480,7 @@ "y_ <- my_model %>% predict(my_data)\n", "RMSE(y_, y)" ], - "id": "94ecc51d-5cf1-4730-bf1b-75e39cd10f96" + "id": "19f2d291-7d3d-4a20-9ab4-2a9fc65d9691" }, { "cell_type": "code", @@ -3505,7 +3505,7 @@ "\n", "my_results <- 1:15 %>% map_dfr(my_loocv)" ], - "id": "90680022-50ed-4e5f-9ecf-ee042b152100" + "id": "23e5b662-a152-45d0-8d43-924f83549afb" }, { "cell_type": "code", @@ -3522,7 +3522,7 @@ " theme(legend.position = c(1, 0),\n", " legend.justification = c(1, 0))" ], - "id": "c91a51f6-9d91-4993-9515-a791a4143075" + "id": "8aa74542-792d-43e5-8d4b-bf2778eb00ce" }, { "cell_type": "code", @@ -3534,10 +3534,10 @@ "stopCluster(cl)\n", "registerDoSEQ()" ], - "id": "14d5fe00-ef2b-4ad1-a489-981c557bae50" + "id": "ec6fd557-6dcb-4f18-a999-7c947576e7f7" }, { - "id": "58a32075", + "id": "9cc4a3c9", "cell_type": "markdown", "source": "# 8 \u56de\u5e302\uff08\u91cd\u56de\u5e30\uff09", "metadata": {} @@ -3556,10 +3556,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "ab44d5db-e794-45a4-b651-58aa1877ae0e" + "id": "646e31c5-9167-486f-9442-ae43fff6c4cf" }, { - "id": "ae3ae557", + "id": "9fd034f7", "cell_type": "markdown", "source": "## 8.1 \u30d6\u30c9\u30a6\u306e\u751f\u80b2\u6761\u4ef6\u3068\u30ef\u30a4\u30f3\u306e\u4fa1\u683c", "metadata": {} @@ -3579,7 +3579,7 @@ " nrows = 38) # \u8aad\u307f\u8fbc\u3080\u884c\u6570\n", "psych::describe(tmp)" ], - "id": "c8658880-3643-429d-a102-bdc4f9eedc5a" + "id": "e56f85eb-8189-4d8f-a4ee-d072687e404b" }, { "cell_type": "code", @@ -3590,7 +3590,7 @@ "my_data <- na.omit(tmp[, -c(1, 2)])\n", "head(my_data)" ], - "id": "19af6778-a338-4e54-a42d-e9f9b0fa6c10" + "id": "16bee85f-8a10-4c96-bc93-3cbfd86ed82d" }, { "cell_type": "code", @@ -3600,7 +3600,7 @@ "source": [ "dim(my_data)" ], - "id": "4f4262ba-785e-4606-8111-6d16b207734b" + "id": "b461e3ce-7942-4122-b212-a74511e4ea44" }, { "cell_type": "code", @@ -3610,7 +3610,7 @@ "source": [ "my_data %>% write_csv(\"wine.csv\")" ], - "id": "a191e12d-ad14-4a11-abea-8d643fb5295a" + "id": "77054ded-1255-469c-978a-814736ff10f2" }, { "cell_type": "code", @@ -3623,10 +3623,10 @@ " \"/fromzero/master/data/wine.csv\")\n", "my_data <- read_csv(my_url)" ], - "id": "db1783f0-240b-4dcf-8ab7-14583da3eb6b" + "id": "01f49778-181e-4623-aaeb-43574bf5a3fb" }, { - "id": "305e4d7c", + "id": "e283ed38", "cell_type": "markdown", "source": "## 8.2 \u91cd\u56de\u5e30\u5206\u6790", "metadata": {} @@ -3648,7 +3648,7 @@ " method = \"lm\",\n", " trControl = trainControl(method = \"LOOCV\"))" ], - "id": "134726e4-e6ae-4661-b5fa-582d8adb66fd" + "id": "2060cc9e-eaae-4f0a-a360-4dc700a2d22a" }, { "cell_type": "code", @@ -3659,7 +3659,7 @@ "coef(my_model$finalModel) %>%\n", " as.data.frame" ], - "id": "4fb841c6-dd72-4144-918e-55a39cd1a4e7" + "id": "8ef22205-0463-4006-9b5e-5a0cf72f1ef0" }, { "cell_type": "code", @@ -3672,7 +3672,7 @@ " HRAIN = 120, TIME_SV = 2)\n", "my_model %>% predict(my_test)" ], - "id": "d3e60664-f607-4e02-b861-d92b6e6d0af6" + "id": "a24bc4da-2f4e-4b91-8ed7-40eaba6a8fe9" }, { "cell_type": "code", @@ -3691,7 +3691,7 @@ "R2(pred = y_, obs = y,\n", " form = \"corr\")" ], - "id": "ca7fc625-6f6c-400e-a27c-2760ad655aac" + "id": "16f10e75-788f-4931-9840-0b3dc333d1b5" }, { "cell_type": "code", @@ -3701,7 +3701,7 @@ "source": [ "my_model$results" ], - "id": "47f361e5-f9e4-44e3-9cc5-e3d21eb63615" + "id": "5519aa26-d550-4093-b7c2-6287d657e3d4" }, { "cell_type": "code", @@ -3715,10 +3715,10 @@ "matrix(b,\n", " dimnames = list(colnames(M)))" ], - "id": "c2c1f380-a6ef-4534-87f5-a6fa93387f44" + "id": "587dd50b-df55-49ba-bdda-07a7f7bf1ff2" }, { - "id": "5c9b7433", + "id": "ca7bc62a", "cell_type": "markdown", "source": "## 8.3 \u6a19\u6e96\u5316", "metadata": {} @@ -3743,7 +3743,7 @@ " stat_summary(fun = mean, geom = \"point\", size = 3) +\n", " xlab(NULL)" ], - "id": "b5e6a50a-3c53-4388-9ca9-f6cb428508c0" + "id": "0833716e-555d-456a-b184-024304a9bb36" }, { "cell_type": "code", @@ -3757,7 +3757,7 @@ " method = \"lm\",\n", " preProcess = c(\"center\", \"scale\"))" ], - "id": "fce41dcb-83b9-4a99-a2b2-78a0352bdfac" + "id": "851f5702-3095-4915-9fe9-8e85b1d2d98d" }, { "cell_type": "code", @@ -3768,7 +3768,7 @@ "coef(my_model$finalModel) %>%\n", " as.data.frame" ], - "id": "ddad2d15-1ee8-4ca9-9a81-e1d22c19f454" + "id": "6086d010-4394-4b5f-b272-5a64a54f5b1b" }, { "cell_type": "code", @@ -3781,10 +3781,10 @@ " HRAIN = 120, TIME_SV = 2)\n", "my_model %>% predict(my_test)" ], - "id": "fea00c74-8c05-45fc-ac45-9b2e08c44c47" + "id": "b8f8c218-cc44-4517-b346-7465a638c3a1" }, { - "id": "7345a1de", + "id": "e22dc4c3", "cell_type": "markdown", "source": "## 8.4 \u5165\u529b\u5909\u6570\u306e\u6570\u3068\u30e2\u30c7\u30eb\u306e\u826f\u3055", "metadata": {} @@ -3806,7 +3806,7 @@ " v2 = 0:(n - 1) %% 3)\n", "head(my_data2)" ], - "id": "64e683d7-68d7-4287-9c72-037fb2c96c18" + "id": "fd4aefa2-e923-4731-95d9-e4f12f590741" }, { "cell_type": "code", @@ -3823,10 +3823,10 @@ "\n", "my_model2$results$RMSE" ], - "id": "73a22eb6-2a76-4ebc-8b9c-64c89a4a395f" + "id": "e3557258-1cc4-4361-8ca5-889fce7ff342" }, { - "id": "6455f201", + "id": "b53ed4a8", "cell_type": "markdown", "source": "## 8.5 \u5909\u6570\u9078\u629e", "metadata": {} @@ -3846,7 +3846,7 @@ "my_data2 <- my_data %>% mutate(v1 = 0:(n - 1) %% 2,\n", " v2 = 0:(n - 1) %% 3)" ], - "id": "5a3a58cc-14be-4a69-a26a-2387a362ddd0" + "id": "1b81aa4c-2d11-4657-ad2d-de6ac0d04a26" }, { "cell_type": "code", @@ -3861,10 +3861,10 @@ " tuneGrid = data.frame(nvmax = 1:6)) # \u9078\u629e\u3059\u308b\u5909\u6570\u306e\u4e0a\u9650\n", "summary(my_model$finalModel)$outmat" ], - "id": "d3e7c8e9-e535-4b7e-870e-9e0c8431cee6" + "id": "f6193301-49ad-40ec-aabd-6b3f0103254c" }, { - "id": "d6075cdb", + "id": "2d6eb607", "cell_type": "markdown", "source": "## 8.6 \u88dc\u8db3\uff1a\u6b63\u5247\u5316", "metadata": {} @@ -3881,7 +3881,7 @@ " \"/fromzero/master/data/wine.csv\")\n", "my_data <- read_csv(my_url)" ], - "id": "49fe243c-db60-457e-bc3e-32c68e43d052" + "id": "b7e89f58-865c-45d8-9a8b-752427ea004c" }, { "cell_type": "code", @@ -3901,7 +3901,7 @@ " lambda = A,\n", " alpha = B))" ], - "id": "1ea60dcc-4ba5-4c24-8754-83d868d6fdec" + "id": "7cada87d-97a9-4ea7-9c47-b308931d1f66" }, { "cell_type": "code", @@ -3911,7 +3911,7 @@ "source": [ "coef(my_model$finalModel, A)" ], - "id": "a85286eb-4715-4aa8-8a74-18ece7e66739" + "id": "0b21ed10-7c97-4751-bf72-6ba798a68024" }, { "cell_type": "code", @@ -3924,7 +3924,7 @@ " HRAIN = 120, TIME_SV = 2)\n", "my_model %>% predict(my_test)" ], - "id": "8efde4cc-860f-4a64-ad0f-2c5d08132f87" + "id": "dc8d12fb-1572-4c1e-ad92-a1db46ad07e5" }, { "cell_type": "code", @@ -3948,7 +3948,7 @@ " xlab(\"log A ( = log lambda)\") +\n", " theme(legend.position = c(0.15, 0.25))" ], - "id": "f5cf06f2-b050-4ad2-8af4-84b757b1c272" + "id": "aa40d4ff-1cd2-4840-84a8-adfb8441649f" }, { "cell_type": "code", @@ -3966,7 +3966,7 @@ "\n", "my_model$bestTune" ], - "id": "dfa667c5-b187-4955-8fe8-bec9708be180" + "id": "236a804a-7ffe-4cd6-94f2-c5b1ba8f14ef" }, { "cell_type": "code", @@ -3980,7 +3980,7 @@ " xlab(\"A ( = lambda)\") +\n", " guides(shape = guide_legend(tmp), color = guide_legend(tmp))" ], - "id": "2f20c1f3-d39b-4d34-9dd0-1a903b2bb2ef" + "id": "b5910514-d85d-4bd7-9403-25277fc03f09" }, { "cell_type": "code", @@ -3991,10 +3991,10 @@ "my_model$results %>%\n", " filter(RMSE == min(RMSE))" ], - "id": "704ec904-3285-4e3f-bbed-8cf1e7c5fed6" + "id": "31d21721-fff0-4887-b1cd-2740ea4a0d2c" }, { - "id": "bf76aab5", + "id": "8962cfb5", "cell_type": "markdown", "source": "## 8.7 \u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af", "metadata": {} @@ -4007,7 +4007,7 @@ "source": [ "curve(1 / (1 + exp(-x)), -6, 6)" ], - "id": "47068685-396f-40bf-a535-35b2a28d5845" + "id": "72c66cbc-542b-4f97-bb97-9b5ddc2e5bea" }, { "cell_type": "code", @@ -4021,7 +4021,7 @@ " \"/fromzero/master/data/wine.csv\")\n", "my_data <- read_csv(my_url)" ], - "id": "d3a4f85b-6fb4-4fa6-bb01-e1378572d374" + "id": "0e1566de-a41d-4367-8522-515ed8728aa5" }, { "cell_type": "code", @@ -4036,7 +4036,7 @@ " trControl = trainControl(method = \"LOOCV\"))\n", "plot(my_model$finalModel) # \u8a13\u7df4\u6e08\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u63cf\u753b" ], - "id": "efdbbae8-506b-4809-ae7b-f81b91e8edaa" + "id": "41bfd981-9bfa-499c-a78f-061cce60a15e" }, { "cell_type": "code", @@ -4046,7 +4046,7 @@ "source": [ "my_model$results" ], - "id": "2897ab77-f407-48e6-b767-61504903577c" + "id": "03e66b77-09cc-4387-ba42-f69779b70e6b" }, { "cell_type": "code", @@ -4064,7 +4064,7 @@ " layer2 = 0:2,\n", " layer3 = 0))" ], - "id": "09c39814-9ae2-4628-b97b-4a9b12cedf29" + "id": "860e22ea-6f69-4a65-bc53-2c0c62c6e57a" }, { "cell_type": "code", @@ -4075,10 +4075,10 @@ "my_model$results %>%\n", " filter(RMSE == min(RMSE))" ], - "id": "e2830421-db7e-4593-b875-2ee9e5a99070" + "id": "8ab3a05a-889f-47ae-9477-0e27d7aed87b" }, { - "id": "b930c7ac", + "id": "6bc828b8", "cell_type": "markdown", "source": "# 9 \u5206\u985e1\uff08\u591a\u5024\u5206\u985e\uff09", "metadata": {} @@ -4097,10 +4097,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "dc90985d-b745-4ecf-b7c9-5ce412a12ed3" + "id": "aed9a003-3fc0-4bf6-8a0c-4e92042bb2b8" }, { - "id": "941faef0", + "id": "06908ca2", "cell_type": "markdown", "source": "## 9.1 \u30a2\u30e4\u30e1\u306e\u30c7\u30fc\u30bf", "metadata": {} @@ -4114,7 +4114,7 @@ "my_data <- iris\n", "head(my_data)" ], - "id": "5cee660f-4615-4b8e-be07-8f93126c6428" + "id": "0717a9e0-fdb2-4169-98cf-17a93d358474" }, { "cell_type": "code", @@ -4124,10 +4124,10 @@ "source": [ "psych::describe(my_data)" ], - "id": "2ed1b6e4-60cc-48da-a1a0-17c5ad41ce6f" + "id": "3c19e60d-b724-4f35-b664-55e09174e214" }, { - "id": "860920df", + "id": "e29e40ce", "cell_type": "markdown", "source": "## 9.2 \u6728\u306b\u3088\u308b\u5206\u985e", "metadata": {} @@ -4143,7 +4143,7 @@ "my_data <- iris\n", "my_model <- train(form = Species ~ ., data = my_data, method = \"rpart\")" ], - "id": "11aa0c33-a9ce-4b72-9cd5-4259d28cb7b6" + "id": "823d3d39-42da-4393-bfaa-00f79ac34f56" }, { "cell_type": "code", @@ -4153,7 +4153,7 @@ "source": [ "rpart.plot::rpart.plot(my_model$finalModel, extra = 1)" ], - "id": "6df4ba4a-0dbf-446f-8427-1ec797763029" + "id": "4bb5c374-6da3-4d49-b78e-d082d992dfb2" }, { "cell_type": "code", @@ -4168,7 +4168,7 @@ "\n", "my_model %>% predict(my_test)" ], - "id": "a669c806-c7c5-4c8e-b8e7-deb9c8b8ecfa" + "id": "72c41a3f-edf5-4634-b27f-eeef603ad736" }, { "cell_type": "code", @@ -4179,10 +4179,10 @@ "my_model %>% predict(my_test,\n", " type = \"prob\")" ], - "id": "8f4e1ccc-0db2-4633-ba8a-68e18534b033" + "id": "6297228c-8e18-4b1b-8bdb-8e4816db0f99" }, { - "id": "cfe25574", + "id": "85fc4ffa", "cell_type": "markdown", "source": "## 9.3 \u6b63\u89e3\u7387", "metadata": {} @@ -4203,7 +4203,7 @@ "confusionMatrix(data = y_, reference = y)\n", "# \u4ee5\u4e0b\u306f\u5272\u611b" ], - "id": "f2f968ff-bbeb-4324-ab12-dfe1f2cca71a" + "id": "b088c3a4-cd75-4671-97f3-06c444f59bb0" }, { "cell_type": "code", @@ -4215,7 +4215,7 @@ "y_ <- my_model %>% predict(my_data)\n", "mean(y_ == y)" ], - "id": "2b546caa-70e9-4348-ab92-41db00b863e2" + "id": "bfe0c91b-dd36-4ce0-878f-ad2421b37526" }, { "cell_type": "code", @@ -4227,7 +4227,7 @@ " trControl = trainControl(method = \"LOOCV\"))\n", "my_model$results" ], - "id": "154398c0-41f7-4183-8da5-af0ca06feb64" + "id": "be743774-30d9-461f-9e51-dc73a787c147" }, { "cell_type": "code", @@ -4240,7 +4240,7 @@ " trControl = trainControl(method = \"LOOCV\"))\n", "my_model$results %>% filter(Accuracy == max(Accuracy))" ], - "id": "84b18b3e-9d16-4e2c-b38f-21026dd7a053" + "id": "12e172c7-88ff-43e1-8be9-9480fe811d9c" }, { "cell_type": "code", @@ -4262,7 +4262,7 @@ " Accuracy = my_model$results$Accuracy)\n", "}" ], - "id": "feb4bbfb-759b-4abb-a7db-229e8e83189b" + "id": "3439870e-8614-4c13-aed3-c4a8e493671a" }, { "cell_type": "code", @@ -4282,7 +4282,7 @@ "\n", "my_results %>% filter(Accuracy == max(Accuracy)) # \u6b63\u89e3\u7387\uff08\u691c\u8a3c\uff09\u306e\u6700\u5927\u5024" ], - "id": "14ce9699-0efa-41a9-ac60-72f192075ef6" + "id": "ce8e40f1-16ee-445b-883b-ef7b22d2d167" }, { "cell_type": "code", @@ -4297,7 +4297,7 @@ " minbucket = 5,\n", " minsplit = 2))" ], - "id": "bfe9169f-e2ea-4805-8912-62645f655786" + "id": "05e4c3e4-fe0c-4d89-9d68-7a238bffc236" }, { "cell_type": "code", @@ -4308,10 +4308,10 @@ "rpart.plot::rpart.plot(\n", " my_model$finalModel, extra = 1)" ], - "id": "3e1197bb-75e6-4964-9264-882b15a2a63e" + "id": "c3c9f9e4-e434-4cb3-85db-0827e71cbdf4" }, { - "id": "d7cf2bb7", + "id": "7cdd29f5", "cell_type": "markdown", "source": "## 9.4 \u8907\u6570\u306e\u6728\u3092\u4f7f\u3046\u65b9\u6cd5", "metadata": {} @@ -4331,7 +4331,7 @@ " trControl = trainControl(method = \"LOOCV\"))\n", "my_model$results" ], - "id": "68e43e07-fc9b-41b1-a543-1e59eed8fe12" + "id": "e5ae4082-a32b-42e3-a9a5-c731414ad2be" }, { "cell_type": "code", @@ -4352,7 +4352,7 @@ " trControl = trainControl(method = \"cv\", number = 5)) # 5\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\n", "my_model$results %>% filter(Accuracy == max(Accuracy)) %>% head(5) %>% t" ], - "id": "7bbf9054-6c9b-48bf-932e-c8ff2bf42be9" + "id": "97e6d661-5595-4e9e-b65c-d2a4925711a7" }, { "cell_type": "code", @@ -4363,10 +4363,10 @@ "my_model <- train(form = Species ~ ., data = my_data, method = \"rf\")\n", "ggplot(varImp(my_model))" ], - "id": "d68ca929-f2f1-4c4c-8b81-dea765fec4c9" + "id": "ee512fc4-ab25-43e0-8736-1e21ab6b9e19" }, { - "id": "3387f16e", + "id": "b59935ea", "cell_type": "markdown", "source": "## 9.5 \u6b20\u640d\u306e\u3042\u308b\u30c7\u30fc\u30bf\u3067\u306e\u5b66\u7fd2", "metadata": {} @@ -4387,7 +4387,7 @@ "\n", "psych::describe(my_data) # n\u306e\u5024\u304c135\u306e\u5909\u6570\u306b\uff0c150 - 135 = 15\u500b\u306e\u6b20\u640d\u304c\u3042\u308b\uff0e" ], - "id": "f65fd8b9-23ad-4900-a64e-9d4c1ea38eff" + "id": "c96dca58-ab1e-4195-bcc1-601559dfbc2e" }, { "cell_type": "code", @@ -4405,7 +4405,7 @@ " minbucket = 1)) # \u7d42\u7aef\u30ce\u30fc\u30c9\u306e\u6761\u4ef6\n", "max(my_model$results$Accuracy)" ], - "id": "ac8c27f6-9f9e-4663-a397-50649ee35284" + "id": "e4305260-8dfd-4726-bf64-e8cbdb74d0b4" }, { "cell_type": "code", @@ -4418,10 +4418,10 @@ " trControl = trainControl(method = \"cv\", number = 5))\n", "max(my_model$results$Accuracy)" ], - "id": "a1025ac5-f389-41a1-a7c2-ca5bbb89dd9a" + "id": "39465e90-5a5d-4091-a3af-5f2b5a90fc54" }, { - "id": "953d6ff5", + "id": "ae3e38f1", "cell_type": "markdown", "source": "## 9.6 \u4ed6\u306e\u5206\u985e\u624b\u6cd5", "metadata": {} @@ -4440,7 +4440,7 @@ " trControl = trainControl(method = \"LOOCV\"))\n", "my_model$results %>% filter(Accuracy == max(Accuracy))" ], - "id": "799c6039-c647-4ddc-9b4d-892b9d7896c6" + "id": "889f4226-c1fa-48b5-ad55-d77f8d3fe117" }, { "cell_type": "code", @@ -4458,10 +4458,10 @@ " trace = FALSE) # \u9014\u4e2d\u7d4c\u904e\u3092\u8868\u793a\u3057\u306a\u3044\n", "my_model$results %>% filter(Accuracy == max(Accuracy))" ], - "id": "45f16d41-67cf-4026-a06c-26e9572865e8" + "id": "45790805-3116-4e08-a64d-ede1a19857ba" }, { - "id": "fef38a85", + "id": "97bdb95f", "cell_type": "markdown", "source": "# 10 \u5206\u985e2\uff082\u5024\u5206\u985e\uff09", "metadata": {} @@ -4480,10 +4480,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "09eb2798-004a-4c1e-9b1b-7bfb5a73022f" + "id": "6e71f902-8be2-442a-880b-28f7f102dfac" }, { - "id": "682f6bf6", + "id": "2103b4e4", "cell_type": "markdown", "source": "## 10.1 2\u5024\u5206\u985e\u306e\u6027\u80fd\u6307\u6a19", "metadata": {} @@ -4497,7 +4497,7 @@ "y <- c( 0, 1, 1, 0, 1, 0, 1, 0, 0, 1)\n", "y_score <- c(0.7, 0.8, 0.3, 0.4, 0.9, 0.6, 0.99, 0.1, 0.2, 0.5)" ], - "id": "b21410a7-b60a-4afd-8c12-906fc3322d31" + "id": "cd9dbcc1-b8ce-4ca3-9cc4-7e86cc49b9da" }, { "cell_type": "code", @@ -4508,7 +4508,7 @@ "y_ <- ifelse(0.5 <= y_score, 1, 0)\n", "y_" ], - "id": "e30fc6a1-7656-4b88-ba99-ffae59d9e0ba" + "id": "e6a84b94-d1bf-4513-89ac-5906ad9582d5" }, { "cell_type": "code", @@ -4522,10 +4522,10 @@ " positive = \"1\", # \u300c1\u300d\u3092\u967d\u6027\u3068\u3059\u308b\uff0e\n", " mode = \"everything\") # \u5168\u3066\u306e\u6307\u6a19\u3092\u6c42\u3081\u308b\uff0e" ], - "id": "5d749fc5-4375-400c-954f-76c86e3f9104" + "id": "515aa260-60fc-4b86-a511-18800bc1484b" }, { - "id": "0a02cdc6", + "id": "4747e755", "cell_type": "markdown", "source": "## 10.2 \u30c8\u30ec\u30fc\u30c9\u30aa\u30d5", "metadata": {} @@ -4546,7 +4546,7 @@ "c(sum((y == 0) & (y_ == 1)) / sum(y == 0), # FPR\n", " sum((y == 1) & (y_ == 1)) / sum(y == 1)) # TPR" ], - "id": "a131da76-91c2-4dae-b7d4-3a5da79160ee" + "id": "36f0d2af-6f14-4de5-9db3-a27e4f12cef6" }, { "cell_type": "code", @@ -4561,7 +4561,7 @@ " ylab = \"True Positive Rate\",\n", " legend = FALSE)" ], - "id": "4e25cc8a-0411-46dd-b014-6a4107ffb11b" + "id": "d50d44a6-3118-47fa-8583-ca1c16acbd4c" }, { "cell_type": "code", @@ -4571,7 +4571,7 @@ "source": [ "my_roc$auc" ], - "id": "54a1d65d-f31f-4f8f-9000-5c49b49215e0" + "id": "2a3a576a-baaa-4c05-bec3-50ed263cc9f3" }, { "cell_type": "code", @@ -4582,7 +4582,7 @@ "c(sum((y == 1) & (y_ == 1)) / sum(y == 1), # Recall == TPR\n", " sum((y == 1) & (y_ == 1)) / sum(y_ == 1)) # Precision" ], - "id": "6102001a-7ab6-4cfc-94b6-6408a7e20d16" + "id": "ac0b4d37-daee-4fbf-9379-3189dc6e50a3" }, { "cell_type": "code", @@ -4597,7 +4597,7 @@ " ylab = \"Precision\",\n", " legend = FALSE)" ], - "id": "2e0b99ca-58e7-4242-9d6c-a00b01af2a23" + "id": "e78152b5-2132-492d-9c52-9aad7766bea3" }, { "cell_type": "code", @@ -4607,10 +4607,10 @@ "source": [ "my_pr$auc.integral" ], - "id": "878d0d13-7b75-4339-8c81-03616be91c4f" + "id": "06732dc1-f012-4fdd-9707-d83ebdf2cf33" }, { - "id": "58106868", + "id": "a09d8f36", "cell_type": "markdown", "source": "## 10.3 \u30bf\u30a4\u30bf\u30cb\u30c3\u30af", "metadata": {} @@ -4629,7 +4629,7 @@ " \"/fromzero/master/data/titanic.csv\")\n", "my_data <- read_csv(my_url)" ], - "id": "58a53e70-0f47-4884-9df6-ae8b187299f8" + "id": "0adb3430-761b-4bf0-8ffb-922e311055bb" }, { "cell_type": "code", @@ -4639,7 +4639,7 @@ "source": [ "head(my_data)" ], - "id": "960b519f-eb9e-4b8f-8a54-b2028dad9368" + "id": "9cd9a27b-1903-42ea-9139-e7053313f93e" }, { "cell_type": "code", @@ -4651,7 +4651,7 @@ " tuneGrid = data.frame(maxdepth = 2),\n", " trControl = trainControl(method = \"LOOCV\"))" ], - "id": "47295ae7-3f30-4eb7-9533-e8b69bd236d8" + "id": "9ced2bfe-58cf-4ef8-a0c3-b3a8a73811da" }, { "cell_type": "code", @@ -4661,7 +4661,7 @@ "source": [ "rpart.plot::rpart.plot(my_model$finalModel, extra = 1)" ], - "id": "fb51312a-0db3-4d67-b843-13b3000f0ea0" + "id": "fec659cd-6a69-48bb-82ac-16220ba2b7fd" }, { "cell_type": "code", @@ -4671,7 +4671,7 @@ "source": [ "my_model$results" ], - "id": "cd565729-99f7-433a-9993-0e2d5bea7560" + "id": "b19bd5b2-5036-44e9-9d12-cd966f4b88dc" }, { "cell_type": "code", @@ -4692,7 +4692,7 @@ " ylab = \"True Positive Rate\",\n", " legend = FALSE)" ], - "id": "fe4bafb6-7048-4640-907f-0a3e117923d0" + "id": "e0f2468a-75eb-4bc9-90aa-49e01ab4efd1" }, { "cell_type": "code", @@ -4712,7 +4712,7 @@ "rpart.plot::rpart.plot(my_model1$finalModel, extra = 1)\n", "my_model1$results" ], - "id": "13beb905-40c4-4086-80b8-ede823e40fcb" + "id": "353f0d53-3c03-4f8f-882f-d6e48b6f72a5" }, { "cell_type": "code", @@ -4732,7 +4732,7 @@ "rpart.plot::rpart.plot(my_model2$finalModel, extra = 1)\n", "my_model2$results" ], - "id": "d71e75b8-8ab2-4ac9-b4b0-7208d5129cb9" + "id": "126778d7-16cf-4c06-87a7-708f9fe37694" }, { "cell_type": "code", @@ -4746,10 +4746,10 @@ "rpart.plot::rpart.plot(my_model3$finalModel, extra = 1)\n", "my_model3$results" ], - "id": "742f3f9e-1da8-4562-9870-b9f98ead9e2e" + "id": "03dd616e-b3dd-42de-876b-706b1b8994f0" }, { - "id": "b3c54387", + "id": "34512698", "cell_type": "markdown", "source": "## 10.4 \u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30", "metadata": {} @@ -4762,7 +4762,7 @@ "source": [ "curve(1 / (1 + exp(-x)), -6, 6)" ], - "id": "7dad910c-4916-4dbb-8349-9c190d446839" + "id": "e7c64a3e-04ad-4f53-bbde-c13014682892" }, { "cell_type": "code", @@ -4781,7 +4781,7 @@ "my_model <- train(form = Survived ~ ., data = my_data, method = \"glm\",\n", " trControl = trainControl(method = \"LOOCV\"))" ], - "id": "9d9f4fc1-a018-417f-bd1a-95f0588be50b" + "id": "32b9c246-54f9-462a-b217-f9a6af8c9b3f" }, { "cell_type": "code", @@ -4792,7 +4792,7 @@ "coef(my_model$finalModel) %>%\n", " as.data.frame" ], - "id": "1dace64b-2d7a-4337-85de-2da951181c9c" + "id": "a3706f49-7fc7-4cd1-ac19-6c991ce7c00a" }, { "cell_type": "code", @@ -4802,10 +4802,10 @@ "source": [ "my_model$results" ], - "id": "91ec36cf-3aad-4fe4-95d9-cc41e1ea6c3d" + "id": "5f4532d2-f2a8-4bc9-9628-e58d58597f82" }, { - "id": "c9fcf907", + "id": "214f11f6", "cell_type": "markdown", "source": "# 11 \u6df1\u5c64\u5b66\u7fd2\u3068AutoML", "metadata": {} @@ -4824,10 +4824,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "f678442c-3855-450d-9c5c-e7d4756e963f" + "id": "6f818bfe-817e-44c3-9144-a0d5d172f855" }, { - "id": "2c666acc", + "id": "ccddbcb8", "cell_type": "markdown", "source": "## 11.1 Keras\u306b\u3088\u308b\u56de\u5e30", "metadata": {} @@ -4848,7 +4848,7 @@ " \"/fromzero/master/data/wine.csv\")\n", "tmp <- read_csv(my_url)" ], - "id": "2773f1a7-2e38-4d4d-bd97-6675042dd0ae" + "id": "dfda32bf-1dac-4411-95a8-03ab0e89e74a" }, { "cell_type": "code", @@ -4858,7 +4858,7 @@ "source": [ "my_data <- tmp[sample(nrow(tmp)), ]" ], - "id": "99ac7920-101b-4a48-bc17-4f91adfa7fa0" + "id": "4adb81b1-ea6b-4c52-b117-da671ffed6d2" }, { "cell_type": "code", @@ -4870,7 +4870,7 @@ " select(-LPRICE2) %>% scale\n", "y <- my_data$LPRICE2" ], - "id": "7c4f4976-0058-4f94-8ef9-f2cd85a4fcd1" + "id": "ef22a97d-0adf-494e-adff-bb92759b5252" }, { "cell_type": "code", @@ -4880,7 +4880,7 @@ "source": [ "curve(activation_relu(x), -3, 3)" ], - "id": "facab6c9-79ae-4c81-8733-59e3793b0f2b" + "id": "f2da3268-5755-4b6d-bd54-fac1a3810541" }, { "cell_type": "code", @@ -4895,7 +4895,7 @@ "summary(my_model) # \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u6982\u8981\n", "# \u5272\u611b\uff08Python\u306e\u7d50\u679c\u3092\u53c2\u7167\uff09" ], - "id": "2060e1df-7007-4e18-9624-f0169e5cd429" + "id": "72cd2cfb-2958-42e3-ae34-635f574464bb" }, { "cell_type": "code", @@ -4907,7 +4907,7 @@ " loss = \"mse\",\n", " optimizer = \"rmsprop\")" ], - "id": "32ba6c38-87ec-4a57-a984-639961aab55e" + "id": "622b7ba3-a871-4997-9586-85036eea2309" }, { "cell_type": "code", @@ -4919,7 +4919,7 @@ " patience = 20,\n", " restore_best_weights = TRUE)" ], - "id": "fb185134-39d9-4888-9527-1dbc0206fb6b" + "id": "f83317f7-c685-4655-8a2e-e6611646ce86" }, { "cell_type": "code", @@ -4936,7 +4936,7 @@ " callbacks = list(my_cb),\n", " verbose = 0)" ], - "id": "49c07678-7686-437b-b086-c05d5ba9c1d1" + "id": "452a8626-84a8-49e2-a7ef-b7bd421ad2c7" }, { "cell_type": "code", @@ -4946,7 +4946,7 @@ "source": [ "plot(my_history)" ], - "id": "e3cf0a10-653e-46ba-bf06-668eec2b2b16" + "id": "f15d19b9-59cc-4757-bd90-54de80e99ebc" }, { "cell_type": "code", @@ -4956,7 +4956,7 @@ "source": [ "my_history" ], - "id": "fd1acbe3-b281-4d17-8d67-1ec26040c2bb" + "id": "6448eece-39a2-451f-a340-679e04c688f3" }, { "cell_type": "code", @@ -4967,10 +4967,10 @@ "y_ <- my_model %>% predict(X)\n", "mean((y_ - y)^2)**0.5" ], - "id": "32449d49-1dca-4faf-b6f2-34b08031012f" + "id": "2d850414-261c-4cfb-a622-a7276f531286" }, { - "id": "b1f36a9a", + "id": "636fe9d0", "cell_type": "markdown", "source": "## 11.2 Keras\u306b\u3088\u308b\u5206\u985e", "metadata": {} @@ -4989,7 +4989,7 @@ "library(tidyverse)\n", "my_data <- iris[sample(nrow(iris)), ]" ], - "id": "88ac4e7c-5dce-4d81-be4d-7b9c7e6eef1e" + "id": "81f5b906-c1c6-47c1-a90e-faa4ca25635e" }, { "cell_type": "code", @@ -5001,7 +5001,7 @@ " select(-Species) %>% scale\n", "y <- as.integer(my_data$Species) - 1" ], - "id": "ef61954c-d426-4b4e-9d87-ed0fcf548ee8" + "id": "5c771f9d-684e-418f-8cd6-6bc03938f0e8" }, { "cell_type": "code", @@ -5013,7 +5013,7 @@ " layer_dense(units = 3, activation = \"relu\", input_shape = c(4)) %>%\n", " layer_dense(units = 3, activation = \"softmax\")" ], - "id": "f4d8e0cb-2d6d-4349-b046-d6cde8d2a2ff" + "id": "85811335-0d20-4537-845f-75ceab9d63ad" }, { "cell_type": "code", @@ -5025,7 +5025,7 @@ " optimizer = \"rmsprop\",\n", " metrics = c(\"accuracy\"))" ], - "id": "59badf29-d120-4c21-b542-fa707f4a1a23" + "id": "5139693b-b061-4ff2-b5fe-e8069040a149" }, { "cell_type": "code", @@ -5048,7 +5048,7 @@ "\n", "plot(my_history)" ], - "id": "10d63ae0-e693-49a2-bcb5-d6139c335fdc" + "id": "5a07a2b2-daec-4544-b89d-6420c413503d" }, { "cell_type": "code", @@ -5058,7 +5058,7 @@ "source": [ "my_history" ], - "id": "9f1d99ba-55d9-4d04-82db-293c80417462" + "id": "5a36fbbf-8987-48cf-a303-82c73c47d13c" }, { "cell_type": "code", @@ -5070,7 +5070,7 @@ "y_ <- apply(tmp, 1, which.max) - 1\n", "mean(y_ == y)" ], - "id": "b14f52c9-b3b3-4016-bc10-ba88500ae741" + "id": "30fe2aac-d6f6-4d57-a708-ac29c5f97e2b" }, { "cell_type": "code", @@ -5082,7 +5082,7 @@ "\n", "-mean(log(c(0.7, 0.6, 0.2, 0.7)))" ], - "id": "d0c9e576-1486-4ab9-95bd-e81cecb37abf" + "id": "c8675cf3-62ab-4509-b9ce-2c330840e3d1" }, { "cell_type": "code", @@ -5100,7 +5100,7 @@ " c(0.2, 0.5, 0.3),\n", " c(0.2, 0.7, 0.1))" ], - "id": "80d5ae21-c5be-4109-9611-87438e44904b" + "id": "53ad4534-464b-4116-92af-7a2074ed14d1" }, { "cell_type": "code", @@ -5111,10 +5111,10 @@ "c(mean(as.array(loss_sparse_categorical_crossentropy(y_true = y, y_pred = y_1))),\n", " mean(as.array(loss_sparse_categorical_crossentropy(y_true = y, y_pred = y_2))))" ], - "id": "a16fbe3a-35ed-47d1-a202-07a8d7b9b5db" + "id": "9b6ad90a-9842-46da-8f3a-afb82aaad3ba" }, { - "id": "c99ab724", + "id": "dde974a8", "cell_type": "markdown", "source": "## 11.3 MNIST\uff1a\u624b\u66f8\u304d\u6570\u5b57\u306e\u5206\u985e", "metadata": {} @@ -5130,11 +5130,10 @@ "} else {\n", " library(keras)\n", "}\n", - "library(zeallot)\n", - "c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()\n", - "library(tidyverse)" + "library(tidyverse)\n", + "c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()" ], - "id": "3bf86898-7681-44e6-bac1-0a1326bc40e3" + "id": "89ab519f-f1d4-4031-aa8d-5ceb644d2d2b" }, { "cell_type": "code", @@ -5144,7 +5143,7 @@ "source": [ "dim(x_train)" ], - "id": "6c941a6d-f994-4798-8e52-e2db91ad0c06" + "id": "922f8f54-b3c6-4d8b-84d3-6393af500af4" }, { "cell_type": "code", @@ -5154,7 +5153,7 @@ "source": [ "x_train[5, , ]" ], - "id": "13765022-8174-4093-bba4-305e819f82d8" + "id": "e0878b26-11dd-4a38-b3af-a86dc15da918" }, { "cell_type": "code", @@ -5165,7 +5164,7 @@ "plot(as.raster(x = x_train[5, , ],\n", " max = max(x_train)))" ], - "id": "42af254d-f5e8-4109-a0ab-2bc1065737e9" + "id": "beb08eed-34c0-43d2-9207-237059397062" }, { "cell_type": "code", @@ -5175,7 +5174,7 @@ "source": [ "head(y_train)" ], - "id": "264d59e9-f6c0-458a-82a9-301640ab975e" + "id": "f4f3ff31-82f8-4c1a-8fcd-104bfb205a2d" }, { "cell_type": "code", @@ -5185,7 +5184,7 @@ "source": [ "c(min(x_train), max(x_train))" ], - "id": "a6bdc67e-2c66-4585-a80b-8b825f8369ad" + "id": "ddaa36f1-3af4-407d-b704-3c47e62425e5" }, { "cell_type": "code", @@ -5196,7 +5195,7 @@ "x_train <- x_train / 255\n", "x_test <- x_test / 255" ], - "id": "a0a5a411-cf80-4961-b5f1-08bbb948fc6e" + "id": "388cdf4b-1b1c-4043-b781-ab85e392171e" }, { "cell_type": "code", @@ -5208,7 +5207,7 @@ "x_train <- x_train[my_index, , ]\n", "y_train <- y_train[my_index]" ], - "id": "7674fcd4-54b6-440a-86ca-6ada71df1752" + "id": "e8f1f0b2-6b7b-4df3-a914-dadd2bc37624" }, { "cell_type": "code", @@ -5230,7 +5229,7 @@ "my_cb <- callback_early_stopping(patience = 5,\n", " restore_best_weights = TRUE)" ], - "id": "0259ba69-126f-43c3-9ca4-cb539bb099c3" + "id": "a1ebe4d5-1c58-4ff5-a4fa-c71f1199acb6" }, { "cell_type": "code", @@ -5249,7 +5248,7 @@ "\n", "plot(my_history)" ], - "id": "f73cd91d-a5fc-4e52-8616-cda9a7e3027a" + "id": "9fdb87df-1e68-48ac-ab07-4aaa4d9ab00b" }, { "cell_type": "code", @@ -5261,7 +5260,7 @@ "y_ <- apply(tmp, 1, which.max) - 1\n", "table(y_, y_test)" ], - "id": "b2b34f2f-faf7-4978-b50a-7da53b834f7a" + "id": "132f656a-1073-458e-84df-64a6f02b5f06" }, { "cell_type": "code", @@ -5269,7 +5268,7 @@ "metadata": {}, "outputs": [], "source": [], - "id": "000f2a96-1ea4-48f7-812e-71e7f45fecde" + "id": "abe93534-30d0-4e28-a57d-3b09dd959251" }, { "cell_type": "code", @@ -5279,7 +5278,7 @@ "source": [ "mean(y_ == y_test)" ], - "id": "d7e188e1-f6b3-4cba-956c-4f7d842ce9e3" + "id": "ae75042b-b3d9-47b7-9b62-9dfeb63cc965" }, { "cell_type": "code", @@ -5290,7 +5289,7 @@ "my_model %>%\n", " evaluate(x = x_test, y = y_test)" ], - "id": "deeb626e-4eec-4e2a-834c-26485ef2226f" + "id": "4549dd35-898e-4259-a9b3-e3a405293be5" }, { "cell_type": "code", @@ -5301,7 +5300,7 @@ "x_train2d <- x_train %>% array_reshape(c(-1, 28, 28, 1))\n", "x_test2d <- x_test %>% array_reshape(c(-1, 28, 28, 1))" ], - "id": "f6c37eb8-22d4-4d03-8ae7-e60b1dd380ac" + "id": "ce72a21c-090a-45be-a007-56f6c5823cec" }, { "cell_type": "code", @@ -5328,7 +5327,7 @@ "my_cb <- callback_early_stopping(patience = 5,\n", " restore_best_weights = TRUE)" ], - "id": "e22175ad-6465-4cc4-8aa3-aaf898ecebeb" + "id": "a56b0e6b-64cd-47a0-a10a-686a75717b75" }, { "cell_type": "code", @@ -5347,7 +5346,7 @@ "\n", "plot(my_history)" ], - "id": "6e13aa40-b8a8-4e61-ac6d-66f59168680c" + "id": "a2dc5dbf-1555-4d80-966f-bb8b483552ea" }, { "cell_type": "code", @@ -5358,7 +5357,7 @@ "my_model %>%\n", " evaluate(x = x_test2d, y = y_test)" ], - "id": "d621a236-fbf9-4bbf-9c84-61b3dcfdfdf4" + "id": "cea324eb-6676-48f4-873c-01842a612258" }, { "cell_type": "code", @@ -5386,7 +5385,7 @@ "my_cb <- callback_early_stopping(patience = 5,\n", " restore_best_weights = TRUE)" ], - "id": "b0400684-d1cc-4e36-9ce5-9ffdaee24e5e" + "id": "61beec17-8ee2-4d4a-9555-d0294e10c79d" }, { "cell_type": "code", @@ -5405,7 +5404,7 @@ "\n", "plot(my_history)" ], - "id": "c6f33fc0-0d54-4d78-83aa-f75dcaab906c" + "id": "e2842581-fcda-48c8-b500-740ecec489eb" }, { "cell_type": "code", @@ -5416,7 +5415,7 @@ "my_model %>%\n", " evaluate(x = x_test2d, y = y_test)" ], - "id": "f8fdd258-ab55-4346-8040-5313aa274a4b" + "id": "34e5e114-e03c-4096-8e34-7b3fc3fe553c" }, { "cell_type": "code", @@ -5434,7 +5433,7 @@ " filter(y_ != y) %>% # \u4e88\u6e2c\u304c\u306f\u305a\u308c\u305f\u3082\u306e\u3092\u6b8b\u3059\n", " arrange(desc(y_prob)) # \u78ba\u7387\u306e\u5927\u304d\u3044\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b" ], - "id": "235647ca-f30b-4bb6-b30d-9b1a926a250d" + "id": "a1b64129-1b4f-4330-9076-efbbbfccf7c0" }, { "cell_type": "code", @@ -5444,7 +5443,7 @@ "source": [ "head(my_result)" ], - "id": "f92b062d-7cdc-438d-b044-baf74dff2f5d" + "id": "95b3e861-f5c3-4130-9aff-d49f4a85e2ff" }, { "cell_type": "code", @@ -5470,10 +5469,10 @@ " theme(legend.position = \"none\") +\n", " facet_grid(. ~ label)" ], - "id": "fac7ba4d-0b26-404c-af26-ab59b120b625" + "id": "6024feea-7ee2-44c9-aa70-2817f6eea133" }, { - "id": "158b92d4", + "id": "8dddef7b", "cell_type": "markdown", "source": "## 11.4 AutoML", "metadata": {} @@ -5496,7 +5495,7 @@ "h2o.no_progress()\n", "# h2o.shutdown(prompt = FALSE) # \u505c\u6b62" ], - "id": "91d07317-144e-46ea-a12a-23a76e24a95c" + "id": "15559443-5ef4-4fdf-bdfc-8e614666f495" }, { "cell_type": "code", @@ -5511,7 +5510,7 @@ "# \u3042\u308b\u3044\u306f\n", "my_frame <- h2o.importFile(my_url, header = TRUE) # \u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\uff0e" ], - "id": "9ac68685-6dff-4524-8cba-a23a84700fc9" + "id": "a575cee8-8c66-48a4-b41b-76d66067d525" }, { "cell_type": "code", @@ -5525,7 +5524,7 @@ "my_frame %>% as.data.frame %>% head\n", "# \u7d50\u679c\u306f\u5272\u611b\uff08\u898b\u305f\u76ee\u306f\u540c\u3058\uff09" ], - "id": "65d05d1b-5805-4778-bb87-adeac53786db" + "id": "ba2aa12e-4398-4e09-ad16-5e1e7a5a752c" }, { "cell_type": "code", @@ -5538,7 +5537,7 @@ " training_frame = my_frame,\n", " max_runtime_secs = 60)" ], - "id": "2abf6835-31a5-4503-b1cf-8e77c5f0ca15" + "id": "78ba63a7-84d9-4532-aa8e-44d5864321fa" }, { "cell_type": "code", @@ -5548,7 +5547,7 @@ "source": [ "min(my_model@leaderboard$rmse)" ], - "id": "855dc660-b41b-45c5-aa8c-c9293e8feaf2" + "id": "e2033b89-9df3-4cae-ba64-6bc5f6ecd55e" }, { "cell_type": "code", @@ -5564,7 +5563,7 @@ "\n", "plot(y, y_)" ], - "id": "f0b26a0c-95d7-4ce1-bea7-0e488b3fa909" + "id": "1746da09-4ccf-402e-a8be-dd7a9c7a831b" }, { "cell_type": "code", @@ -5572,13 +5571,12 @@ "metadata": {}, "outputs": [], "source": [ - "library(zeallot)\n", "c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist()\n", "my_index <- sample(1:60000, 6000)\n", "x_train <- x_train[my_index, , ]\n", "y_train <- y_train[my_index]" ], - "id": "a0386856-e4ed-4df3-b240-b48b1d6ec22f" + "id": "9bd4ca7c-e98f-41d7-a52b-7979c260ced2" }, { "cell_type": "code", @@ -5597,7 +5595,7 @@ " as.data.frame\n", "my_test <- as.h2o(tmp)" ], - "id": "c8cd8128-9420-4012-9801-0042c24058ee" + "id": "e2d5b58c-672e-4ea0-936c-8a2946488d0f" }, { "cell_type": "code", @@ -5610,7 +5608,7 @@ " training_frame = my_train,\n", " max_runtime_secs = 120)" ], - "id": "0bef3a09-8958-4c29-9440-1ce4e32b8bba" + "id": "954bd63a-074f-4ec8-afca-dcf1f90bf520" }, { "cell_type": "code", @@ -5621,7 +5619,7 @@ "min(my_model@leaderboard$\n", " mean_per_class_error)" ], - "id": "8e85f72c-2eac-405c-a9c2-d31a24ecdc3c" + "id": "dc59347a-9c2d-46e9-b063-d0c697fa8ac5" }, { "cell_type": "code", @@ -5635,10 +5633,10 @@ "\n", "mean(y_ == y_test)" ], - "id": "00b6f5c4-b86d-44c2-8578-d1421655aa4f" + "id": "1e10a537-b15d-4ef7-9a90-bea67baa6d82" }, { - "id": "67598b6f", + "id": "068db036", "cell_type": "markdown", "source": "# 12 \u6642\u7cfb\u5217\u4e88\u6e2c", "metadata": {} @@ -5658,10 +5656,10 @@ " install.packages(c(\"ggplot2\"))\n", "}" ], - "id": "853ba6b2-c133-4cb6-ae05-0988cf3f17b2" + "id": "54837683-a705-4e4e-8979-141d3be7849f" }, { - "id": "9901f9db", + "id": "e008c70e", "cell_type": "markdown", "source": "## 12.1 \u65e5\u6642\u3068\u65e5\u6642\u306e\u5217", "metadata": {} @@ -5674,7 +5672,7 @@ "source": [ "as.POSIXct(\"2021-01-01\")" ], - "id": "910ad38e-5615-4274-afe9-c5e4e47daf20" + "id": "ad9f3844-56e5-4048-936f-e5f7e8a1fbe7" }, { "cell_type": "code", @@ -5693,10 +5691,10 @@ "seq(from = as.POSIXct(\"2021-01-01 00:00:00\"),\n", " to = as.POSIXct(\"2021-01-01 03:00:00\"), by = \"2 hour\")" ], - "id": "790bb7c9-485c-4c2c-958b-a0ff2c4948b1" + "id": "ff3f39e6-75b9-40a8-ace7-fdcd01c35a7f" }, { - "id": "9294dbbe", + "id": "d7f4ac91", "cell_type": "markdown", "source": "## 12.2 \u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u4e88\u6e2c", "metadata": {} @@ -5709,7 +5707,7 @@ "source": [ "my_data <- as.vector(AirPassengers)" ], - "id": "f54e4213-962e-47dc-8644-2df73170f16e" + "id": "27e492cf-294d-48a2-be39-a1be70d9042a" }, { "cell_type": "code", @@ -5720,7 +5718,7 @@ "n <- length(my_data) # \u30c7\u30fc\u30bf\u6570\uff08144\uff09\n", "k <- 108 # \u8a13\u7df4\u30c7\u30fc\u30bf\u6570" ], - "id": "adab121c-05f5-43fe-ab47-b350b4cc0103" + "id": "861b0c12-c582-47e5-8648-fa9eda4c9149" }, { "cell_type": "code", @@ -5747,7 +5745,7 @@ "\n", "head(my_df)" ], - "id": "8e84a338-8acc-43c6-9219-d1330fc9026c" + "id": "d9df9740-913f-41b5-9486-6c25b62af78f" }, { "cell_type": "code", @@ -5759,7 +5757,7 @@ "my_test <- my_df[-(1:k), ]\n", "y <- my_test$y" ], - "id": "5dddaedf-7878-4082-bc36-2e762a685099" + "id": "4c37533e-54b3-4797-bc08-9117a04cb749" }, { "cell_type": "code", @@ -5774,7 +5772,7 @@ " geom_line()\n", "my_plot" ], - "id": "caf16826-7900-4f7e-aa9b-ca3f17f21715" + "id": "5c6e2c9a-f6fb-45e1-9418-7afcfdb0940f" }, { "cell_type": "code", @@ -5787,7 +5785,7 @@ "y_ <- my_lm_model %>% predict(my_test)\n", "caret::RMSE(y, y_) # RMSE\uff08\u30c6\u30b9\u30c8\uff09" ], - "id": "a6d69ae2-4479-425d-b782-d424897862bd" + "id": "4e679949-5317-44dc-9582-25862f766c9f" }, { "cell_type": "code", @@ -5800,7 +5798,7 @@ " mutate(y = y_, label = \"model\")\n", "my_plot + geom_line(data = tmp)" ], - "id": "720fd2ba-7ec0-465f-9e89-fd12322ee8d3" + "id": "bfdeef72-f5a5-4553-83bf-ffff5ec30560" }, { "cell_type": "code", @@ -5812,7 +5810,7 @@ "my_arima_model <- my_train %>% model(ARIMA(y))\n", "my_arima_model" ], - "id": "a1c7ea7a-8654-47fb-aaa7-362d0cda3643" + "id": "0794790e-c3cb-4482-b59b-e87fde83f762" }, { "cell_type": "code", @@ -5823,7 +5821,7 @@ "tmp <- my_arima_model %>% forecast(h = \"3 years\")\n", "head(tmp)" ], - "id": "1363691b-8a29-4b46-af57-a77841551cc1" + "id": "d5d1163f-dd1e-497d-b65f-95194fcf3a09" }, { "cell_type": "code", @@ -5834,7 +5832,7 @@ "y_ <- tmp$.mean\n", "caret::RMSE(y_, y)" ], - "id": "46b40e77-ffaf-4e18-ab24-006b6c972d1d" + "id": "56045aac-fec7-45ae-ac80-b4a1bb21927d" }, { "cell_type": "code", @@ -5851,7 +5849,7 @@ " y = y,\n", " color = label))" ], - "id": "1fc2825f-3d20-4b24-a9c3-d7a5e3f81d44" + "id": "1a58982c-eda6-418f-b758-b53ef946ffa2" }, { "cell_type": "code", @@ -5863,7 +5861,7 @@ "my_prophet_model <- my_train %>%\n", " prophet(seasonality.mode = \"multiplicative\")" ], - "id": "9a5bf7fd-2554-4c8d-b486-f1858ca5cac9" + "id": "d12ca9ee-0e50-42d1-bcfb-feb7572d153d" }, { "cell_type": "code", @@ -5874,7 +5872,7 @@ "tmp <- my_prophet_model %>% predict(my_test)\n", "head(tmp[, c(\"ds\", \"yhat\", \"yhat_lower\", \"yhat_upper\")])" ], - "id": "7e0de4a9-5aa6-419d-8e5c-6f93efda2203" + "id": "f60d6e11-5c43-4d7c-9ea1-b21b1714c14c" }, { "cell_type": "code", @@ -5885,7 +5883,7 @@ "y_ <- tmp$yhat\n", "caret::RMSE(y_, y)" ], - "id": "9ca64028-dfdd-44f1-af6a-94dbd640d435" + "id": "7d8f60d2-2d87-4647-ae12-054226c49ac1" }, { "cell_type": "code", @@ -5899,10 +5897,10 @@ " geom_line(data = my_train, aes(x = as.POSIXct(ds))) +\n", " geom_line(data = my_test, aes(x = as.POSIXct(ds)), color = \"red\")" ], - "id": "f0673ab5-6b48-499a-8e8a-8db0cb67f376" + "id": "fabd0ff5-0b66-4041-83ed-dd7a7c91e289" }, { - "id": "16bccfcb", + "id": "e0932d28", "cell_type": "markdown", "source": "# 13 \u6559\u5e2b\u306a\u3057\u5b66\u7fd2", "metadata": {} @@ -5921,10 +5919,10 @@ " install.packages(setdiff(packages_to_install, installed_packages))\n", "}" ], - "id": "de14280b-a90a-46a9-8a5c-3d706f6bd2ac" + "id": "4020e718-150f-4a08-9244-6145a7c8e877" }, { - "id": "94030028", + "id": "b7d4b5b5", "cell_type": "markdown", "source": "## 13.1 \u4e3b\u6210\u5206\u5206\u6790", "metadata": {} @@ -5946,7 +5944,7 @@ " row.names = c(\"A\", \"B\", \"C\", \"D\", \"E\", \"F\"))\n", "my_result <- my_data %>% prcomp # \u4e3b\u6210\u5206\u5206\u6790\u306e\u5b9f\u884c" ], - "id": "f96d364a-6a4f-48b9-80bc-c4553eb739cb" + "id": "1b1f2cd2-09f2-423f-9412-a10530dacfb0" }, { "cell_type": "code", @@ -5956,7 +5954,7 @@ "source": [ "my_result$x # \u4e3b\u6210\u5206\u30b9\u30b3\u30a2" ], - "id": "e98f2025-9116-4d74-a41f-c98bfbbc99ac" + "id": "c0572ffa-5b7a-41ed-8404-a094d12cadc4" }, { "cell_type": "code", @@ -5968,7 +5966,7 @@ " labels = row.names(my_data),\n", " scale = 0)" ], - "id": "dcf1b9ba-633b-4616-a9ca-072518874b4a" + "id": "917f1f11-26c2-417a-80d5-6bcdf1e89d2f" }, { "cell_type": "code", @@ -5978,7 +5976,7 @@ "source": [ "my_result$rotation %>% t" ], - "id": "6d9e2b30-a8a7-42a0-ba79-4a91325c462a" + "id": "a30b76c1-8b65-4fd8-b16e-05517e27ead6" }, { "cell_type": "code", @@ -5988,7 +5986,7 @@ "source": [ "summary(my_result)" ], - "id": "1d4a725a-9e97-410e-ab78-1bf9bf2661ba" + "id": "6623042c-7014-46c3-8fd0-27aebc9c8ac9" }, { "cell_type": "code", @@ -6005,7 +6003,7 @@ "\n", "my_result$x # \u4e3b\u6210\u5206\u30b9\u30b3\u30a2" ], - "id": "6b669dbd-f854-40b9-81d3-03251689ea58" + "id": "695fd567-3535-49e4-b247-35e1de63e114" }, { "cell_type": "code", @@ -6023,7 +6021,7 @@ "Z %*% tmp$vectors # \u4e3b\u6210\u5206\u30b9\u30b3\u30a2\uff08\u7d50\u679c\u306f\u5272\u611b\uff09\n", "cumsum(tmp$values) / sum(tmp$values) # \u7d2f\u7a4d\u5bc4\u4e0e\u7387" ], - "id": "4b896cd8-14c4-43a0-b12a-f3e01d9a6824" + "id": "a9ce5e66-e3a5-431a-9240-6e2de900acce" }, { "cell_type": "code", @@ -6046,10 +6044,10 @@ "e <- d^2 / (n - 1) # \u5206\u6563\u5171\u5206\u6563\u884c\u5217\u306e\u56fa\u6709\u5024\n", "cumsum(e) / sum(e) # \u7d2f\u7a4d\u5bc4\u4e0e\u7387" ], - "id": "d2d239c7-71d7-4def-bd4b-9a80de77c269" + "id": "1dd46ed1-9e20-434a-8b8f-98a708aaa56a" }, { - "id": "8be3e8ef", + "id": "ac0acb3d", "cell_type": "markdown", "source": "## 13.2 \u30af\u30e9\u30b9\u30bf\u5206\u6790", "metadata": {} @@ -6071,7 +6069,7 @@ " dist(\"euclidian\") %>% # dist\u3060\u3051\u3067\u3082\u53ef\n", " hclust(\"complete\") # hclust\u3060\u3051\u3067\u3082\u53ef" ], - "id": "c7770976-5ee8-44b9-b368-cfd690f7b281" + "id": "692ff442-e3dd-4138-a2a3-0b004de2a720" }, { "cell_type": "code", @@ -6083,7 +6081,7 @@ " k = 3, # \u30af\u30e9\u30b9\u30bf\u6570\n", " rect = TRUE, rect_fill = TRUE)" ], - "id": "280bef50-9285-4869-93d0-55793242a47b" + "id": "f7ea8927-f600-4d54-a584-8da84a31fa17" }, { "cell_type": "code", @@ -6096,7 +6094,7 @@ " rect = TRUE, rect_fill = TRUE,\n", " type = \"phylogenic\")" ], - "id": "1bb1bcb7-fac9-421c-84ce-01c0a61d10d3" + "id": "8f7abe2c-c29f-4ccd-b7ba-5ea1f6d214b3" }, { "cell_type": "code", @@ -6106,7 +6104,7 @@ "source": [ "my_result %>% cutree(3)" ], - "id": "ba8c8124-f260-4b53-801f-fc892dbd2b54" + "id": "153436e1-ce1e-4fa2-b7e9-1f9310d50675" }, { "cell_type": "code", @@ -6129,7 +6127,7 @@ " gplots::heatmap.2(cexRow = 1, cexCol = 1), # \u30e9\u30d9\u30eb\u306e\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3057\u3066\u63cf\u753b\u3059\u308b\uff0e\n", " silent = TRUE)" ], - "id": "39f0bd7c-df4f-4973-83b4-80726b69cc34" + "id": "92c90661-0686-4815-99bf-5f123efd8b6e" }, { "cell_type": "code", @@ -6146,7 +6144,7 @@ "\n", "my_result <- my_data %>% kmeans(3)" ], - "id": "3732d760-d2b9-4365-85ee-6463601b5351" + "id": "c07e549e-b30f-44ee-b9b9-9c72ab3b05bf" }, { "cell_type": "code", @@ -6156,7 +6154,7 @@ "source": [ "my_result$cluster" ], - "id": "3b8423e7-f87d-4364-8c60-014e0a5cfb70" + "id": "81777fcc-053b-4e3a-b80f-e99fe6589435" }, { "cell_type": "code", @@ -6176,7 +6174,7 @@ "})\n", "gridExtra::grid.arrange(f[[1]], f[[2]], f[[3]], f[[4]], ncol = 2)" ], - "id": "b0e407a8-97b9-48f7-9747-bc870c2a848b" + "id": "1fe1ecc7-7022-4f92-bb6c-9a3a7be221b2" }, { "cell_type": "code", @@ -6186,7 +6184,7 @@ "source": [ "fviz_nbclust(my_data, kmeans, method = \"wss\")" ], - "id": "3d90cda9-ad66-4b0b-9fa7-2a5ba5a7824d" + "id": "a972e379-5102-4b81-a2c9-bc1c5d986f4c" }, { "cell_type": "code", @@ -6210,7 +6208,7 @@ " geom_point(shape = iris$Species) + # \u5f62\u3067\u54c1\u7a2e\u3092\u8868\u73fe\u3059\u308b\uff0e\n", " theme(legend.position = \"none\")" ], - "id": "548b041e-88df-4c16-93ac-86fb4cdeb25f" + "id": "def687bc-5952-4bf1-9506-956639957af1" } ], "nbformat": 4,