Newer
Older
{
"cells": [
{
"cell_type": "code",
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
"\n",
" @import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
"\n",
" @import url('http://fonts.googleapis.com/css?family=Kameron');\n",
" @import url('http://fonts.googleapis.com/css?family=Crimson+Text');\n",
"\n",
" @import url('http://fonts.googleapis.com/css?family=Lato');\n",
" @import url('http://fonts.googleapis.com/css?family=Source+Sans+Pro');\n",
"\n",
" @import url('http://fonts.googleapis.com/css?family=Lora');\n",
"\n",
"\n",
" body {\n",
" font-family: 'Lora', Consolas, sans-serif;\n",
"\n",
" -webkit-print-color-adjust: exact important !;\n",
"\n",
"\n",
"\n",
" }\n",
"\n",
" .alert-block {\n",
" width: 95%;\n",
" margin: auto;\n",
" }\n",
"\n",
" .rendered_html code\n",
" {\n",
" color: black;\n",
" background: #eaf0ff;\n",
" background: #f5f5f5;\n",
" padding: 1pt;\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
" }\n",
"\n",
" p {\n",
" line-height: 140%;\n",
" }\n",
"\n",
" strong code {\n",
" background: red;\n",
" }\n",
"\n",
" .rendered_html strong code\n",
" {\n",
" background: #f5f5f5;\n",
" }\n",
"\n",
" .CodeMirror pre {\n",
" font-family: 'Source Code Pro', monocco, Consolas, monocco, monospace;\n",
" }\n",
"\n",
" .cm-s-ipython span.cm-keyword {\n",
" font-weight: normal;\n",
" }\n",
"\n",
" strong {\n",
" background: #f5f5f5;\n",
" margin-top: 4pt;\n",
" margin-bottom: 4pt;\n",
" padding: 2pt;\n",
" border: 0.5px solid #a0a0a0;\n",
" font-weight: bold;\n",
" color: darkred;\n",
" }\n",
"\n",
"\n",
" div #notebook {\n",
" # font-size: 10pt;\n",
" line-height: 145%;\n",
" }\n",
"\n",
" li {\n",
" line-height: 145%;\n",
" }\n",
"\n",
" div.output_area pre {\n",
" background: #fff9d8 !important;\n",
" padding: 5pt;\n",
"\n",
" -webkit-print-color-adjust: exact;\n",
"\n",
" }\n",
"\n",
"\n",
"\n",
" h1, h2, h3, h4 {\n",
" font-family: Kameron, arial;\n",
"\n",
" }\n",
"\n",
" div#maintoolbar {display: none !important;}\n",
" /*\n",
"\n",
" div#site {\n",
" border-top: 20px solid #1F407A;\n",
" border-right: 20px solid #1F407A;\n",
" margin-bottom: 0;\n",
" padding-bottom: 0;\n",
" }\n",
" div#toc-wrapper {\n",
" border-left: 20px solid #1F407A;\n",
" border-top: 20px solid #1F407A;\n",
"\n",
" }\n",
"\n",
" body {\n",
" margin-botton:10px;\n",
" }\n",
" */\n",
"\n",
"</style>\n",
" <script>\n",
"IPython.OutputArea.prototype._should_scroll = function(lines) {\n",
" return false;\n",
"}\n",
" </script>\n",
"\n",
"\n",
"<footer id=\"attribution\" style=\"float:left; color:#1F407A; background:#fff; font-family: helvetica;\">\n",
" Copyright (C) 2019-2021 Scientific IT Services of ETH Zurich,\n",
" <p>\n",
" Contributing Authors:\n",
" Dr. Tarun Chadha,\n",
" Dr. Franziska Oschmann,\n",
" Dr. Mikolaj Rybinski,\n",
" Dr. Uwe Schmitt.\n",
" </p<\n",
"</footer>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# IGNORE THIS CELL WHICH CUSTOMIZES LAYOUT AND STYLING OF THE NOTEBOOK !\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"warnings.filterwarnings(\"ignore\", category=FutureWarning)\n",
"warnings.filterwarnings = lambda *a, **kw: None\n",
"from IPython.core.display import HTML\n",
"\n",
"HTML(open(\"custom.html\", \"r\").read())"
},
{
"cell_type": "markdown",
"source": [
"# Chapter 6: An overview of classifiers, Part 1\n",
"\n",
"<span style=\"font-size: 150%;\">Nearest Neighbors and linear-based methods</span>"
},
{
"cell_type": "markdown",
"source": [
"This script gives a quick hands-on overview of **how different types of classifiers work, their advantages and their disadvantages**. This should give you an idea of a concept behind each classifier type as well as when and which classifier type to use.\n",
"\n",
"For the sake of visualisation we continue with 2 dimensional data examples. For different classifiers we'll be looking at their decision surfaces. Let's start with some helper functions for that:"
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"def samples_color(ilabels, colors=[\"steelblue\", \"chocolate\"]):\n",
" \"\"\"Return colors list from labels list given as indices.\"\"\"\n",
" return [colors[int(i)] for i in ilabels]\n",
"\n",
Loading
Loading full blame...