├── .gitignore
├── Deep Learning
├── Deep Learning com Pytorch.ipynb
└── images
│ ├── gradient_descent.jpg
│ ├── network_used.png
│ ├── perceptron.png
│ ├── pytorch.png
│ └── tensor_examples.svg
├── LICENSE
├── Machine Learning
├── Machine Learning com Pycaret.ipynb
├── README.md
├── data
│ └── Star3642_balanced.csv
└── images
│ ├── PyCaret.png
│ ├── done.gif
│ ├── dwight.gif
│ └── missioncomplete.gif
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
--------------------------------------------------------------------------------
/Deep Learning/images/gradient_descent.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Deep Learning/images/gradient_descent.jpg
--------------------------------------------------------------------------------
/Deep Learning/images/network_used.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Deep Learning/images/network_used.png
--------------------------------------------------------------------------------
/Deep Learning/images/perceptron.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Deep Learning/images/perceptron.png
--------------------------------------------------------------------------------
/Deep Learning/images/pytorch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Deep Learning/images/pytorch.png
--------------------------------------------------------------------------------
/Deep Learning/images/tensor_examples.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
1070 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Itamar Rocha
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Machine Learning/Machine Learning com Pycaret.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "#
Introdução ao Aprendizado de Máquina
\n",
8 | "\n",
9 | "
\n",
10 | "\n",
11 | "\n",
12 | "\n",
13 | "\n",
14 | "* Neste Jupyter-Notebook farei uma introdução ao Aprendizado de Máquina (Machine Learning). Utilizaremos a biblioteca de AutoML Pycaret para entendermos como rodar de forma simples algoritmos preditivos sobre um dataset. O notebook pode ser rodado através do colab pelo link abaixo.\n",
15 | "\n",
16 | "
"
17 | ]
18 | },
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {},
22 | "source": [
23 | "## 1. O que é PyCaret?"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {},
29 | "source": [
30 | "\n",
31 | "
\n",
32 | "
"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {},
38 | "source": [
39 | "[PyCaret](https://pycaret.org) é uma biblioteca open source que tem por objetivo **reduzir o trabalho** que as pessoas têm para realizar certas tarefas no universo da Aprendizagem de Máquina. Por exemplo, PyCaret possibilita um ambiente de teste muito mais simples para os que já tem certa experiência e é mais simples e de fácil entendimento para os que não tem tanta experiência com programação ou Aprendizagem de Máquina.\n",
40 | "\n",
41 | "Com poucas linhas de código você consegue executar mais de 10 algoritmos sobre seus dados e comparar eles. O trabalho fica muito mais simples."
42 | ]
43 | },
44 | {
45 | "cell_type": "markdown",
46 | "metadata": {},
47 | "source": [
48 | "## 2. Instalando o PyCaret e outras bibliotecas"
49 | ]
50 | },
51 | {
52 | "cell_type": "markdown",
53 | "metadata": {},
54 | "source": [
55 | "Para instalar o PyCaret, é necessário apenas rodar o código abaixo dentro de seu Jupyter Notebook (local ou Colab)"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": null,
61 | "metadata": {},
62 | "outputs": [],
63 | "source": [
64 | "!pip install PyCaret\n",
65 | "!pip install shap"
66 | ]
67 | },
68 | {
69 | "cell_type": "markdown",
70 | "metadata": {},
71 | "source": [
72 | "O PyCaret precisa de python 3.6 ou mais atualizado."
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "### 2.1 Usuários de Colab\n",
80 | "Se você estiver usando Google Colab, você precisará rodar o próximo código no seu notebook para poder ver os gráficos interativos:"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": null,
86 | "metadata": {},
87 | "outputs": [],
88 | "source": [
89 | "from pycaret.utils import enable_colab\n",
90 | "enable_colab()"
91 | ]
92 | },
93 | {
94 | "cell_type": "markdown",
95 | "metadata": {},
96 | "source": [
97 | "## 3. Lendo os dados"
98 | ]
99 | },
100 | {
101 | "cell_type": "markdown",
102 | "metadata": {},
103 | "source": [
104 | "Com o Pycaret, podemos usar dados de duas formas:\n",
105 | "* Usando pandas\n",
106 | "```python\n",
107 | "import pandas as pd\n",
108 | "data = pd.read_csv(\"data.csv\")\n",
109 | "```\n",
110 | "* Usando os datasets open source disponibilizados pelo Pycaret\n",
111 | "```python\n",
112 | "from pycaret.datasets import get_data\n",
113 | "data = get_data('dataset_name')\n",
114 | "```\n",
115 | "\n",
116 | "Abaixo estão listados os datasets disponibilizados\n",
117 | "\n",
118 | "
\n",
119 | "\n",
120 | "\n",
121 | "\n",
122 | "Dataset | \n",
123 | "Tipo dos dados | \n",
124 | "Tarefa padrão | \n",
125 | "Variável target | \n",
126 | "Nº de instâncias | \n",
127 | "Nº de atributos | \n",
128 | "
\n",
129 | "\n",
130 | "anomaly | \n",
131 | "Multivariate | \n",
132 | "Anomaly Detection | \n",
133 | "None | \n",
134 | "1000 | \n",
135 | "10 | \n",
136 | "
\n",
137 | "\n",
138 | "france | \n",
139 | "Multivariate | \n",
140 | "Association Rule Mining | \n",
141 | "InvoiceNo, Description | \n",
142 | "8557 | \n",
143 | "8 | \n",
144 | "
\n",
145 | "\n",
146 | "germany | \n",
147 | "Multivariate | \n",
148 | "Association Rule Mining | \n",
149 | "InvoiceNo, Description | \n",
150 | "9495 | \n",
151 | "8 | \n",
152 | "
\n",
153 | "\n",
154 | "bank | \n",
155 | "Multivariate | \n",
156 | "Classification (Binary) | \n",
157 | "deposit | \n",
158 | "45211 | \n",
159 | "17 | \n",
160 | "
\n",
161 | "\n",
162 | "blood | \n",
163 | "Multivariate | \n",
164 | "Classification (Binary) | \n",
165 | "Class | \n",
166 | "748 | \n",
167 | "5 | \n",
168 | "
\n",
169 | "\n",
170 | "cancer | \n",
171 | "Multivariate | \n",
172 | "Classification (Binary) | \n",
173 | "Class | \n",
174 | "683 | \n",
175 | "10 | \n",
176 | "
\n",
177 | "\n",
178 | "credit | \n",
179 | "Multivariate | \n",
180 | "Classification (Binary) | \n",
181 | "default | \n",
182 | "24000 | \n",
183 | "24 | \n",
184 | "
\n",
185 | "\n",
186 | "diabetes | \n",
187 | "Multivariate | \n",
188 | "Classification (Binary) | \n",
189 | "Class variable | \n",
190 | "768 | \n",
191 | "9 | \n",
192 | "
\n",
193 | "\n",
194 | "electrical_grid | \n",
195 | "Multivariate | \n",
196 | "Classification (Binary) | \n",
197 | "stabf | \n",
198 | "10000 | \n",
199 | "14 | \n",
200 | "
\n",
201 | "\n",
202 | "employee | \n",
203 | "Multivariate | \n",
204 | "Classification (Binary) | \n",
205 | "left | \n",
206 | "14999 | \n",
207 | "10 | \n",
208 | "
\n",
209 | "\n",
210 | "heart | \n",
211 | "Multivariate | \n",
212 | "Classification (Binary) | \n",
213 | "DEATH | \n",
214 | "200 | \n",
215 | "16 | \n",
216 | "
\n",
217 | "\n",
218 | "heart_disease | \n",
219 | "Multivariate | \n",
220 | "Classification (Binary) | \n",
221 | "Disease | \n",
222 | "270 | \n",
223 | "14 | \n",
224 | "
\n",
225 | "\n",
226 | "hepatitis | \n",
227 | "Multivariate | \n",
228 | "Classification (Binary) | \n",
229 | "Class | \n",
230 | "154 | \n",
231 | "32 | \n",
232 | "
\n",
233 | "\n",
234 | "income | \n",
235 | "Multivariate | \n",
236 | "Classification (Binary) | \n",
237 | "income >50K | \n",
238 | "32561 | \n",
239 | "14 | \n",
240 | "
\n",
241 | "\n",
242 | "juice | \n",
243 | "Multivariate | \n",
244 | "Classification (Binary) | \n",
245 | "Purchase | \n",
246 | "1070 | \n",
247 | "15 | \n",
248 | "
\n",
249 | "\n",
250 | "nba | \n",
251 | "Multivariate | \n",
252 | "Classification (Binary) | \n",
253 | "TARGET_5Yrs | \n",
254 | "1340 | \n",
255 | "21 | \n",
256 | "
\n",
257 | "\n",
258 | "wine | \n",
259 | "Multivariate | \n",
260 | "Classification (Binary) | \n",
261 | "type | \n",
262 | "6498 | \n",
263 | "13 | \n",
264 | "
\n",
265 | "\n",
266 | "telescope | \n",
267 | "Multivariate | \n",
268 | "Classification (Binary) | \n",
269 | "Class | \n",
270 | "19020 | \n",
271 | "11 | \n",
272 | "
\n",
273 | "\n",
274 | "glass | \n",
275 | "Multivariate | \n",
276 | "Classification (Multiclass) | \n",
277 | "Type | \n",
278 | "214 | \n",
279 | "10 | \n",
280 | "
\n",
281 | "\n",
282 | "iris | \n",
283 | "Multivariate | \n",
284 | "Classification (Multiclass) | \n",
285 | "species | \n",
286 | "150 | \n",
287 | "5 | \n",
288 | "
\n",
289 | "\n",
290 | "poker | \n",
291 | "Multivariate | \n",
292 | "Classification (Multiclass) | \n",
293 | "CLASS | \n",
294 | "100000 | \n",
295 | "11 | \n",
296 | "
\n",
297 | "\n",
298 | "questions | \n",
299 | "Multivariate | \n",
300 | "Classification (Multiclass) | \n",
301 | "Next_Question | \n",
302 | "499 | \n",
303 | "4 | \n",
304 | "
\n",
305 | "\n",
306 | "satellite | \n",
307 | "Multivariate | \n",
308 | "Classification (Multiclass) | \n",
309 | "Class | \n",
310 | "6435 | \n",
311 | "37 | \n",
312 | "
\n",
313 | "\n",
314 | "asia_gdp | \n",
315 | "Multivariate | \n",
316 | "Clustering | \n",
317 | "None | \n",
318 | "40 | \n",
319 | "11 | \n",
320 | "
\n",
321 | "\n",
322 | "elections | \n",
323 | "Multivariate | \n",
324 | "Clustering | \n",
325 | "None | \n",
326 | "3195 | \n",
327 | "54 | \n",
328 | "
\n",
329 | "\n",
330 | "facebook | \n",
331 | "Multivariate | \n",
332 | "Clustering | \n",
333 | "None | \n",
334 | "7050 | \n",
335 | "12 | \n",
336 | "
\n",
337 | "\n",
338 | "ipl | \n",
339 | "Multivariate | \n",
340 | "Clustering | \n",
341 | "None | \n",
342 | "153 | \n",
343 | "25 | \n",
344 | "
\n",
345 | "\n",
346 | "jewellery | \n",
347 | "Multivariate | \n",
348 | "Clustering | \n",
349 | "None | \n",
350 | "505 | \n",
351 | "4 | \n",
352 | "
\n",
353 | "\n",
354 | "mice | \n",
355 | "Multivariate | \n",
356 | "Clustering | \n",
357 | "None | \n",
358 | "1080 | \n",
359 | "82 | \n",
360 | "
\n",
361 | "\n",
362 | "migration | \n",
363 | "Multivariate | \n",
364 | "Clustering | \n",
365 | "None | \n",
366 | "233 | \n",
367 | "12 | \n",
368 | "
\n",
369 | "\n",
370 | "perfume | \n",
371 | "Multivariate | \n",
372 | "Clustering | \n",
373 | "None | \n",
374 | "20 | \n",
375 | "29 | \n",
376 | "
\n",
377 | "\n",
378 | "pokemon | \n",
379 | "Multivariate | \n",
380 | "Clustering | \n",
381 | "None | \n",
382 | "800 | \n",
383 | "13 | \n",
384 | "
\n",
385 | "\n",
386 | "population | \n",
387 | "Multivariate | \n",
388 | "Clustering | \n",
389 | "None | \n",
390 | "255 | \n",
391 | "56 | \n",
392 | "
\n",
393 | "\n",
394 | "public_health | \n",
395 | "Multivariate | \n",
396 | "Clustering | \n",
397 | "None | \n",
398 | "224 | \n",
399 | "21 | \n",
400 | "
\n",
401 | "\n",
402 | "seeds | \n",
403 | "Multivariate | \n",
404 | "Clustering | \n",
405 | "None | \n",
406 | "210 | \n",
407 | "7 | \n",
408 | "
\n",
409 | "\n",
410 | "wholesale | \n",
411 | "Multivariate | \n",
412 | "Clustering | \n",
413 | "None | \n",
414 | "440 | \n",
415 | "8 | \n",
416 | "
\n",
417 | "\n",
418 | "tweets | \n",
419 | "Text | \n",
420 | "NLP | \n",
421 | "tweet | \n",
422 | "8594 | \n",
423 | "2 | \n",
424 | "
\n",
425 | "\n",
426 | "amazon | \n",
427 | "Text | \n",
428 | "NLP / Classification | \n",
429 | "reviewText | \n",
430 | "20000 | \n",
431 | "2 | \n",
432 | "
\n",
433 | "\n",
434 | "kiva | \n",
435 | "Text | \n",
436 | "NLP / Classification | \n",
437 | "en | \n",
438 | "6818 | \n",
439 | "7 | \n",
440 | "
\n",
441 | "\n",
442 | "spx | \n",
443 | "Text | \n",
444 | "NLP / Regression | \n",
445 | "text | \n",
446 | "874 | \n",
447 | "4 | \n",
448 | "
\n",
449 | "\n",
450 | "wikipedia | \n",
451 | "Text | \n",
452 | "NLP / Classification | \n",
453 | "Text | \n",
454 | "500 | \n",
455 | "3 | \n",
456 | "
\n",
457 | "\n",
458 | "automobile | \n",
459 | "Multivariate | \n",
460 | "Regression | \n",
461 | "price | \n",
462 | "202 | \n",
463 | "26 | \n",
464 | "
\n",
465 | "\n",
466 | "bike | \n",
467 | "Multivariate | \n",
468 | "Regression | \n",
469 | "cnt | \n",
470 | "17379 | \n",
471 | "15 | \n",
472 | "
\n",
473 | "\n",
474 | "boston | \n",
475 | "Multivariate | \n",
476 | "Regression | \n",
477 | "medv | \n",
478 | "506 | \n",
479 | "14 | \n",
480 | "
\n",
481 | "\n",
482 | "concrete | \n",
483 | "Multivariate | \n",
484 | "Regression | \n",
485 | "strength | \n",
486 | "1030 | \n",
487 | "9 | \n",
488 | "
\n",
489 | "\n",
490 | "diamond | \n",
491 | "Multivariate | \n",
492 | "Regression | \n",
493 | "Price | \n",
494 | "6000 | \n",
495 | "8 | \n",
496 | "
\n",
497 | "\n",
498 | "energy | \n",
499 | "Multivariate | \n",
500 | "Regression | \n",
501 | "Heating Load / Cooling Load | \n",
502 | "768 | \n",
503 | "10 | \n",
504 | "
\n",
505 | "\n",
506 | "forest | \n",
507 | "Multivariate | \n",
508 | "Regression | \n",
509 | "area | \n",
510 | "517 | \n",
511 | "13 | \n",
512 | "
\n",
513 | "\n",
514 | "gold | \n",
515 | "Multivariate | \n",
516 | "Regression | \n",
517 | "Gold_T+22 | \n",
518 | "2558 | \n",
519 | "121 | \n",
520 | "
\n",
521 | "\n",
522 | "house | \n",
523 | "Multivariate | \n",
524 | "Regression | \n",
525 | "SalePrice | \n",
526 | "1461 | \n",
527 | "81 | \n",
528 | "
\n",
529 | "\n",
530 | "insurance | \n",
531 | "Multivariate | \n",
532 | "Regression | \n",
533 | "charges | \n",
534 | "1338 | \n",
535 | "7 | \n",
536 | "
\n",
537 | "\n",
538 | "parkinsons | \n",
539 | "Multivariate | \n",
540 | "Regression | \n",
541 | "PPE | \n",
542 | "5875 | \n",
543 | "22 | \n",
544 | "
\n",
545 | "\n",
546 | "traffic | \n",
547 | "Multivariate | \n",
548 | "Regression | \n",
549 | "traffic_volume | \n",
550 | "48204 | \n",
551 | "8 | \n",
552 | "
\n",
553 | "\n",
554 | "
"
555 | ]
556 | },
557 | {
558 | "cell_type": "markdown",
559 | "metadata": {},
560 | "source": [
561 | "#### 4.2.1 Lendo um dataset com Pandas\n",
562 | "\n",
563 | "Vamos ler o [Star Dataset](https://www.kaggle.com/vinesmsuic/star-categorization-giants-and-dwarfs), disponível no Kaggle. No qual nossa tarefa será categorizar as instâncias entre estrelas anãs e gigantes. O dataset pode ser baixado no kaggle ou acessado no repositório dessa aula."
564 | ]
565 | },
566 | {
567 | "cell_type": "code",
568 | "execution_count": null,
569 | "metadata": {},
570 | "outputs": [],
571 | "source": [
572 | "data_url = \"https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/main/Machine%20Learning/data/Star3642_balanced.csv?token=AMZBEI5WN5MR65336J2XW3LAYU5QW\""
573 | ]
574 | },
575 | {
576 | "cell_type": "code",
577 | "execution_count": null,
578 | "metadata": {},
579 | "outputs": [],
580 | "source": [
581 | "import pandas as pd\n",
582 | "\n",
583 | "data_star = pd.read_csv(data_url)\n",
584 | "print(\"Tamanho do dataset : \", data_star.shape)"
585 | ]
586 | },
587 | {
588 | "cell_type": "markdown",
589 | "metadata": {},
590 | "source": [
591 | "#### 4.2.2 Lendo um dataset padrão do Pycaret\n",
592 | "\n",
593 | "Nesse ponto vamos ler um dataset de brinquedo presente no repositório do próprio PyCaret, **satellite**."
594 | ]
595 | },
596 | {
597 | "cell_type": "code",
598 | "execution_count": null,
599 | "metadata": {
600 | "scrolled": true
601 | },
602 | "outputs": [],
603 | "source": [
604 | "from pycaret.datasets import get_data\n",
605 | "\n",
606 | "data_satellite = get_data(\"satellite\")\n",
607 | "print(\"Tamanho do dataset : \", data_satellite.shape)"
608 | ]
609 | },
610 | {
611 | "cell_type": "markdown",
612 | "metadata": {},
613 | "source": [
614 | "Nesse dataset, nosso objetivo é performar **uma classificação multiclasse na variável Class**."
615 | ]
616 | },
617 | {
618 | "cell_type": "markdown",
619 | "metadata": {},
620 | "source": [
621 | "## 4. Analisando os dados\n",
622 | "\n",
623 | "Nesse notebook utilizaremos o star dataset que foi lido com a biblioteca pandas. Vamos fazer uma breve analise nele."
624 | ]
625 | },
626 | {
627 | "cell_type": "code",
628 | "execution_count": null,
629 | "metadata": {},
630 | "outputs": [],
631 | "source": [
632 | "data_star.head()"
633 | ]
634 | },
635 | {
636 | "cell_type": "markdown",
637 | "metadata": {},
638 | "source": [
639 | "Sempre que formos fazer uma previsão precisamos entender nossos dados, o que cada um representa e o que estamos tentando prever."
640 | ]
641 | },
642 | {
643 | "cell_type": "markdown",
644 | "metadata": {},
645 | "source": [
646 | "### 4.1 Significado de cada variável"
647 | ]
648 | },
649 | {
650 | "cell_type": "markdown",
651 | "metadata": {},
652 | "source": [
653 | "\n",
654 | " \n",
655 | " \n",
656 | " Variável | \n",
657 | " Descrição | \n",
658 | "
\n",
659 | " \n",
660 | " Vmag | \n",
661 | " Visual Apparent Magnitude of the Star | \n",
662 | "
\n",
663 | " \n",
664 | " Plx | \n",
665 | " Distance Between the Star and the Earth | \n",
666 | "
\n",
667 | " \n",
668 | " e_Plx | \n",
669 | " Standard Error of Plx (Drop the Row if you find the e_Plx is too high!) | \n",
670 | "
\n",
671 | " \n",
672 | " B-V | \n",
673 | " B-V color index. (A hot star has a B-V color index close to 0 or negative, while a cool star has a B-V color index close to 2.0. | \n",
674 | "
\n",
675 | " \n",
676 | " SpType | \n",
677 | " Spectral type | \n",
678 | "
\n",
679 | " \n",
680 | " Amag | \n",
681 | " Absolute Magnitude of the Star | \n",
682 | "
\n",
683 | " \n",
684 | " TargetClass | \n",
685 | " Whether the Star is Dwarf (0) or Giant (1) | \n",
686 | "
\n",
687 | " \n",
688 | "
"
689 | ]
690 | },
691 | {
692 | "cell_type": "markdown",
693 | "metadata": {},
694 | "source": [
695 | "### 4.2 Tipo de cada variável"
696 | ]
697 | },
698 | {
699 | "cell_type": "code",
700 | "execution_count": null,
701 | "metadata": {},
702 | "outputs": [],
703 | "source": [
704 | "data_star.dtypes"
705 | ]
706 | },
707 | {
708 | "cell_type": "markdown",
709 | "metadata": {},
710 | "source": [
711 | "### 4.3 Outras análises"
712 | ]
713 | },
714 | {
715 | "cell_type": "code",
716 | "execution_count": null,
717 | "metadata": {},
718 | "outputs": [],
719 | "source": [
720 | "data_star.info()"
721 | ]
722 | },
723 | {
724 | "cell_type": "code",
725 | "execution_count": null,
726 | "metadata": {},
727 | "outputs": [],
728 | "source": [
729 | "data_star.describe()"
730 | ]
731 | },
732 | {
733 | "cell_type": "markdown",
734 | "metadata": {},
735 | "source": [
736 | "## 5. Organizando o ambiente\n",
737 | "Antes de executarmos qualquer algoritmo, temos que importar os módulos necessários para não termos nenhum problem."
738 | ]
739 | },
740 | {
741 | "cell_type": "markdown",
742 | "metadata": {},
743 | "source": [
744 | "### 5.1 Importando os Módulos\n",
745 | "O PyCaret é dividido basicamente em 6 módulos que separam os diferentes modelos que podem ser utilizados para determinados problemas.\n",
746 | "\n",
747 | "\n",
748 | " \n",
749 | " \n",
750 | " Módulo | \n",
751 | " Como importar | \n",
752 | "
\n",
753 | " \n",
754 | " Classificação | \n",
755 | " from pycaret.classification import * | \n",
756 | "
\n",
757 | " \n",
758 | " Regressão | \n",
759 | " from pycaret.regression import * | \n",
760 | "
\n",
761 | " \n",
762 | " Clusterização | \n",
763 | " from pycaret.clustering import * | \n",
764 | "
\n",
765 | " \n",
766 | " Detecção de Anomalias | \n",
767 | " from pycaret.anomaly import * | \n",
768 | "
\n",
769 | " \n",
770 | " Processamento de Linguagem Natural | \n",
771 | " from pycaret.nlp import * | \n",
772 | "
\n",
773 | " \n",
774 | " Association Rule Mining | \n",
775 | " from pycaret.arules import * | \n",
776 | "
\n",
777 | " \n",
778 | "
"
779 | ]
780 | },
781 | {
782 | "cell_type": "markdown",
783 | "metadata": {},
784 | "source": [
785 | "Exemplo:\n",
786 | "\n",
787 | "```python\n",
788 | "from pycaret.classification import *\n",
789 | "```"
790 | ]
791 | },
792 | {
793 | "cell_type": "code",
794 | "execution_count": null,
795 | "metadata": {},
796 | "outputs": [],
797 | "source": [
798 | "from pycaret.classification import *"
799 | ]
800 | },
801 | {
802 | "cell_type": "markdown",
803 | "metadata": {},
804 | "source": [
805 | "### 5.2 Construindo o ambiente"
806 | ]
807 | },
808 | {
809 | "cell_type": "markdown",
810 | "metadata": {},
811 | "source": [
812 | "Após a importação das funções presentes no módulo desejado, deve-se fazer o setup do ambiente (antes de rodar qualquer função que não a de ler os dados). Vamos executar um pequeno exemplo com o que vimos até então:"
813 | ]
814 | },
815 | {
816 | "cell_type": "markdown",
817 | "metadata": {},
818 | "source": [
819 | "#### 5.2.1 Olhando nossos dados"
820 | ]
821 | },
822 | {
823 | "cell_type": "code",
824 | "execution_count": null,
825 | "metadata": {},
826 | "outputs": [],
827 | "source": [
828 | "# Relembrando as colunas do nosso dataset\n",
829 | "data_star.columns"
830 | ]
831 | },
832 | {
833 | "cell_type": "code",
834 | "execution_count": null,
835 | "metadata": {
836 | "scrolled": true
837 | },
838 | "outputs": [],
839 | "source": [
840 | "data_star.head()"
841 | ]
842 | },
843 | {
844 | "cell_type": "markdown",
845 | "metadata": {},
846 | "source": [
847 | "Como podemos ver, temos 7 colunas e a variável que queremos prever é a **TargetClass**"
848 | ]
849 | },
850 | {
851 | "cell_type": "code",
852 | "execution_count": null,
853 | "metadata": {},
854 | "outputs": [],
855 | "source": [
856 | "data_star.TargetClass.value_counts()"
857 | ]
858 | },
859 | {
860 | "cell_type": "markdown",
861 | "metadata": {},
862 | "source": [
863 | "Nosso dataset já está balanceado e tratado e, portanto, não temos que nos preocupar tanto com essa etapa nesse tutorial."
864 | ]
865 | },
866 | {
867 | "cell_type": "markdown",
868 | "metadata": {},
869 | "source": [
870 | "\n",
871 | "\n",
872 | "\n",
873 | "**ISSO NÃO VAI ACONTECER NUNCA NO MUNDO REAL, PREPROCESSAMENTO DE DADOS É UMA PARTE ESSENCIAL EM QUALQUER TRABALHO DE ANÁLISE OU PREVISÃO DE DADOS**"
874 | ]
875 | },
876 | {
877 | "cell_type": "markdown",
878 | "metadata": {},
879 | "source": [
880 | "#### 5.2.2 Função setup\n",
881 | "\n",
882 | "A função setup, como dito anteriormente, é essencial para execução dos modelos. Como parâmetros obrigatórios, ela tem **data**, que corresponde ao dataset utilizado, e **target**, que corresponde a variável a ser prevista. Afora esses, ela também possui diversos parâmetros opcionais (você pode ler mais sobre na [**documentação**](https://pycaret.readthedocs.io/en/latest/api/classification.html))"
883 | ]
884 | },
885 | {
886 | "cell_type": "markdown",
887 | "metadata": {},
888 | "source": [
889 | "* Ao rodarmos a célula abaixo, a função setup identificará os tipos de cada variável e nos retornará um prompt para darmos enter caso esteja correto ou digitarmos **quit**, caso queiramos fazer alguma modificação, se eventualmente houver alguma incoerência com os dados. Para modificar alguma coluna que foi detectada incorretamente, devemos especificar-la nos parâmetros. Se tudo estiver ok, ele printará uma descrição sobre o dataset e o preprocessamento será feito."
890 | ]
891 | },
892 | {
893 | "cell_type": "code",
894 | "execution_count": null,
895 | "metadata": {},
896 | "outputs": [],
897 | "source": [
898 | "classificador = setup(data=data_star, target=\"TargetClass\", train_size=0.8)"
899 | ]
900 | },
901 | {
902 | "cell_type": "markdown",
903 | "metadata": {},
904 | "source": [
905 | "* A função setup também faz a limpeza dos dados. Por padrão, a média é usada para imputação dos dados numéricos (preenchimento dos dados faltantes) e a moda para dados categóricos. Essas configurações podem ser alteradas nos parâmetros da função."
906 | ]
907 | },
908 | {
909 | "cell_type": "markdown",
910 | "metadata": {},
911 | "source": [
912 | "* Por fim, a função setup também faz a divisão do dataset em treino e teste usando estratificação para exemplos categóricos como o caso acima. O valor padrão de split é 70 treino - 30 teste. Caso deseje mudar é necessário apenas passar o parâmetro adequado na função setup, como fizemos anteriormente."
913 | ]
914 | },
915 | {
916 | "cell_type": "markdown",
917 | "metadata": {},
918 | "source": [
919 | "## 6. Comparando modelos"
920 | ]
921 | },
922 | {
923 | "cell_type": "markdown",
924 | "metadata": {},
925 | "source": [
926 | "Nesta secção já vamos começar a rodar nossos **algoritmos de Machine Learning**. Como foi visto, a estrutura do PyCaret é bem simples e, com quase 5 linhas de código, você verá que seremos capazes de rodar 16 algoritmos. :P\n",
927 | "\n",
928 | "Vamos agora ver um pouco como fazer isso. Na função **compare_models()**, todos os algoritmos que podem ser utilizados para resolver o seu problema serão rodados e a função disponibilizará uma tabela com os resultados das métricas e o tempo que levou em segundos. A partir disso o sistema vai fazer o output do modelo que teve o melhor desempenho."
929 | ]
930 | },
931 | {
932 | "cell_type": "code",
933 | "execution_count": null,
934 | "metadata": {
935 | "scrolled": false
936 | },
937 | "outputs": [],
938 | "source": [
939 | "best_model = compare_models(fold=10, round=3, sort=\"Accuracy\")"
940 | ]
941 | },
942 | {
943 | "cell_type": "code",
944 | "execution_count": null,
945 | "metadata": {},
946 | "outputs": [],
947 | "source": [
948 | "best_model"
949 | ]
950 | },
951 | {
952 | "cell_type": "markdown",
953 | "metadata": {},
954 | "source": [
955 | "É importante ressaltar que você pode mudar a métrica de importância (no parâmetro **sort**). Assim, o modelo retornará o modelo com a melhor peformance nessa métrica. Também é possível retornar mais de um modelo através do parâmetro **n_select**, retirar modelos da lista padrão com **blacklist** e comparar apenas os modelos que você tem interesse com **whitelist**. Além disso, se tempo for uma variável preciosa no trabalho, pode-se setar o parâmetro **turbo=True** para que o compare_models() não execute os algoritmos que demorariam mais tempo."
956 | ]
957 | },
958 | {
959 | "cell_type": "markdown",
960 | "metadata": {},
961 | "source": [
962 | "## 7. Criando o modelo"
963 | ]
964 | },
965 | {
966 | "cell_type": "markdown",
967 | "metadata": {},
968 | "source": [
969 | "Vamos criar nosso modelo com a função **create_model()**. Antes disso, vamos observar os modelos que temos disponível através da função **models()**."
970 | ]
971 | },
972 | {
973 | "cell_type": "code",
974 | "execution_count": null,
975 | "metadata": {},
976 | "outputs": [],
977 | "source": [
978 | "models()"
979 | ]
980 | },
981 | {
982 | "cell_type": "code",
983 | "execution_count": null,
984 | "metadata": {
985 | "scrolled": true
986 | },
987 | "outputs": [],
988 | "source": [
989 | "rc = create_model(\"ridge\")"
990 | ]
991 | },
992 | {
993 | "cell_type": "code",
994 | "execution_count": null,
995 | "metadata": {},
996 | "outputs": [],
997 | "source": [
998 | "rf = create_model(\"rf\")"
999 | ]
1000 | },
1001 | {
1002 | "cell_type": "markdown",
1003 | "metadata": {},
1004 | "source": [
1005 | "\n",
1006 | "\n",
1007 | "Voilá, temos nossos modelos criados :D!!!\n",
1008 | "\n",
1009 | "Mas será que ele já está bom o suficiente? Vamos dar uma olhada em mais uma etapa que talvez possa nos ajudar a melhorar a performance do nosso modelo."
1010 | ]
1011 | },
1012 | {
1013 | "cell_type": "markdown",
1014 | "metadata": {},
1015 | "source": [
1016 | "## 8. Tunando o modelo"
1017 | ]
1018 | },
1019 | {
1020 | "cell_type": "markdown",
1021 | "metadata": {},
1022 | "source": [
1023 | "Essa etapa é responsável por melhorar nosso modelo escolhido. Aqui passamos parâmetros como:\n",
1024 | "* Qual métrica queremos melhorar\n",
1025 | "* Quais parâmetros queremos mexer para melhorar essa métrica\n",
1026 | "* Número de folds\n",
1027 | "\n",
1028 | "O PyCaret tem por padrão um grid de parâmetros que ele utiliza para melhorar cada algoritmo. Caso queira fazer o seu próprio, é só elaborar um pequeno dicionário com os parâmetros a serem testados.\n",
1029 | "Ex:\n",
1030 | "```python\n",
1031 | "params = {\"n_estimators\": np.random.randint(1, 300, 20),\n",
1032 | " \"gamma\": [0.1, 0.001, 0.0001],\n",
1033 | " \"max_depth\": [2,3,4,5,6,10,12]\n",
1034 | " }\n",
1035 | "```\n",
1036 | "É claro que para isso é necessário um estudo maior dos hyperparâmetros do algoritmo utilizado."
1037 | ]
1038 | },
1039 | {
1040 | "cell_type": "code",
1041 | "execution_count": null,
1042 | "metadata": {},
1043 | "outputs": [],
1044 | "source": [
1045 | "params = {\n",
1046 | " \"n_estimators\": np.random.randint(80,300,10)\n",
1047 | " }"
1048 | ]
1049 | },
1050 | {
1051 | "cell_type": "code",
1052 | "execution_count": null,
1053 | "metadata": {},
1054 | "outputs": [],
1055 | "source": [
1056 | "params"
1057 | ]
1058 | },
1059 | {
1060 | "cell_type": "code",
1061 | "execution_count": null,
1062 | "metadata": {
1063 | "scrolled": true
1064 | },
1065 | "outputs": [],
1066 | "source": [
1067 | "tuned_rf = tune_model(rf, fold=5, optimize=\"Accuracy\", custom_grid=params) #vamos usar o default"
1068 | ]
1069 | },
1070 | {
1071 | "cell_type": "code",
1072 | "execution_count": null,
1073 | "metadata": {},
1074 | "outputs": [],
1075 | "source": [
1076 | "tuned_rf"
1077 | ]
1078 | },
1079 | {
1080 | "cell_type": "markdown",
1081 | "metadata": {},
1082 | "source": [
1083 | "Tivemos um aumento de performance? Caso não, teríamos que mexer um pouco mais em nosso grid de parâmetros para melhorar."
1084 | ]
1085 | },
1086 | {
1087 | "cell_type": "markdown",
1088 | "metadata": {},
1089 | "source": [
1090 | "## 9. Fazendo os plots do nosso modelo"
1091 | ]
1092 | },
1093 | {
1094 | "cell_type": "markdown",
1095 | "metadata": {},
1096 | "source": [
1097 | "Com o **plot_model()** podemos plotar os mais diversos gráficos para analisar o desempenho de nosso modelo. A seguir estão mostradas todas as possibilidades.\n",
1098 | "\n",
1099 | "\n",
1100 | " \n",
1101 | " \n",
1102 | " Gráfico | \n",
1103 | " Nome | \n",
1104 | "
\n",
1105 | " \n",
1106 | " ‘auc’ | \n",
1107 | " Area Under the Curve | \n",
1108 | "
\n",
1109 | " \n",
1110 | " ‘threshold’ | \n",
1111 | " Discrimination Threshold | \n",
1112 | "
\n",
1113 | " \n",
1114 | " ‘pr’ | \n",
1115 | " Precision Recall Curve | \n",
1116 | "
\n",
1117 | " \n",
1118 | " ‘confusion_matrix’ | \n",
1119 | " Confusion Matrix | \n",
1120 | "
\n",
1121 | " \n",
1122 | " ‘error’ | \n",
1123 | " Class Prediction Error | \n",
1124 | "
\n",
1125 | " \n",
1126 | " ‘class_report’ | \n",
1127 | " Classification Report | \n",
1128 | "
\n",
1129 | " \n",
1130 | " ‘boundary’ | \n",
1131 | " Decision Boundary | \n",
1132 | "
\n",
1133 | " \n",
1134 | " ‘rfe’ | \n",
1135 | " Recursive Feature Selection | \n",
1136 | "
\n",
1137 | " \n",
1138 | " ‘learning’ | \n",
1139 | " Learning Curve | \n",
1140 | "
\n",
1141 | " \n",
1142 | " ‘manifold’ | \n",
1143 | " Manifold Learning | \n",
1144 | "
\n",
1145 | " \n",
1146 | " ‘calibration’ | \n",
1147 | " Calibration Curve | \n",
1148 | "
\n",
1149 | " \n",
1150 | " ‘vc’ | \n",
1151 | " Validation Curve | \n",
1152 | "
\n",
1153 | " \n",
1154 | " ‘dimension’ | \n",
1155 | " Dimension Learning | \n",
1156 | "
\n",
1157 | " \n",
1158 | " ‘feature’ | \n",
1159 | " Feature Importance | \n",
1160 | "
\n",
1161 | " \n",
1162 | " ‘parameter’ | \n",
1163 | " Model Hyperparameter | \n",
1164 | "
\n",
1165 | " \n",
1166 | "
"
1167 | ]
1168 | },
1169 | {
1170 | "cell_type": "code",
1171 | "execution_count": null,
1172 | "metadata": {
1173 | "scrolled": false
1174 | },
1175 | "outputs": [],
1176 | "source": [
1177 | "plot_model(rc, plot=\"confusion_matrix\")"
1178 | ]
1179 | },
1180 | {
1181 | "cell_type": "code",
1182 | "execution_count": null,
1183 | "metadata": {},
1184 | "outputs": [],
1185 | "source": [
1186 | "plot_model(rf, plot=\"learning\")"
1187 | ]
1188 | },
1189 | {
1190 | "cell_type": "markdown",
1191 | "metadata": {},
1192 | "source": [
1193 | "Embora seja bem fácil plotar algum gráfico específico com o PyCaret, é possível plotar todos os gráficos de uma vez e apenas observar de um por um através da interface produzida pelo PyCaret com a função **evaluate_model()**."
1194 | ]
1195 | },
1196 | {
1197 | "cell_type": "code",
1198 | "execution_count": null,
1199 | "metadata": {
1200 | "scrolled": false
1201 | },
1202 | "outputs": [],
1203 | "source": [
1204 | "evaluate_model(tuned_rf)"
1205 | ]
1206 | },
1207 | {
1208 | "cell_type": "markdown",
1209 | "metadata": {},
1210 | "source": [
1211 | "## 10. Acessando as variáveis"
1212 | ]
1213 | },
1214 | {
1215 | "cell_type": "markdown",
1216 | "metadata": {},
1217 | "source": [
1218 | "O PyCaret, como pudemos observar até então, é a verdadeira definição de caixa preta haha. Contudo, podemos ter acesso às variáveis com a função **get_config(Variable)**. Essa função retornará um objeto diferente de acordo com a string que você passar. A seguir são os possíveis objetos que podemos ter acesso:\n",
1219 | "\n",
1220 | "\n",
1221 | " - X: Transformed dataset (X)
\n",
1222 | " - y: Transformed dataset (y)
\n",
1223 | " - X_train: Transformed train dataset (X)
\n",
1224 | " - X_test: Transformed test/holdout dataset (X)
\n",
1225 | " - y_train: Transformed train dataset (y)
\n",
1226 | " - y_test: Transformed test/holdout dataset (y)
\n",
1227 | " - seed: random state set through session_id
\n",
1228 | " - prep_pipe: Transformation pipeline configured through setup
\n",
1229 | " - folds_shuffle_param: shuffle parameter used in Kfolds
\n",
1230 | " - n_jobs_param: n_jobs parameter used in model training
\n",
1231 | " - html_param: html_param configured through setup
\n",
1232 | " - create_model_container: results grid storage container
\n",
1233 | " - master_model_container: model storage container
\n",
1234 | " - display_container: results display container
\n",
1235 | " - exp_name_log: Name of experiment set through setup
\n",
1236 | " - logging_param: log_experiment param set through setup
\n",
1237 | " - log_plots_param: log_plots param set through setup
\n",
1238 | " - USI: Unique session ID parameter set through setup
\n",
1239 | " - fix_imbalance_param: fix_imbalance param set through setup
\n",
1240 | " - fix_imbalance_method_param: fix_imbalance_method param set through setup
\n",
1241 | "
"
1242 | ]
1243 | },
1244 | {
1245 | "cell_type": "markdown",
1246 | "metadata": {},
1247 | "source": [
1248 | "**Ex:**"
1249 | ]
1250 | },
1251 | {
1252 | "cell_type": "code",
1253 | "execution_count": null,
1254 | "metadata": {},
1255 | "outputs": [],
1256 | "source": [
1257 | "X_test = get_config(\"X_test\")\n",
1258 | "X_test.head()"
1259 | ]
1260 | },
1261 | {
1262 | "cell_type": "markdown",
1263 | "metadata": {},
1264 | "source": [
1265 | "## 11. Prevendo com nosso modelo"
1266 | ]
1267 | },
1268 | {
1269 | "cell_type": "code",
1270 | "execution_count": null,
1271 | "metadata": {
1272 | "scrolled": false
1273 | },
1274 | "outputs": [],
1275 | "source": [
1276 | "predict_model(rc)"
1277 | ]
1278 | },
1279 | {
1280 | "cell_type": "markdown",
1281 | "metadata": {},
1282 | "source": [
1283 | "Como vemos acima, a função predict_model nos retorna as métricas correspondentes à previsão, além de retornar junto ao DataFrame original uma coluna **Label**, que equivale ao que o modelo preveu."
1284 | ]
1285 | },
1286 | {
1287 | "cell_type": "markdown",
1288 | "metadata": {},
1289 | "source": [
1290 | "Também é possível prever um novo conjunto passando como parâmetro da seguinte forma:\n",
1291 | "```python\n",
1292 | "predict_model(model, data = novos_dados)\n",
1293 | "```"
1294 | ]
1295 | },
1296 | {
1297 | "cell_type": "markdown",
1298 | "metadata": {},
1299 | "source": [
1300 | "## 12. Finalizando o modelo"
1301 | ]
1302 | },
1303 | {
1304 | "cell_type": "markdown",
1305 | "metadata": {},
1306 | "source": [
1307 | "Por finalizar o modelo, temos como objetivo juntar os dados de teste aos de treinamento e fazer um modelo baseado em todos os dados para ir para produção."
1308 | ]
1309 | },
1310 | {
1311 | "cell_type": "code",
1312 | "execution_count": null,
1313 | "metadata": {},
1314 | "outputs": [],
1315 | "source": [
1316 | "finalize_model(rc)"
1317 | ]
1318 | },
1319 | {
1320 | "cell_type": "markdown",
1321 | "metadata": {},
1322 | "source": [
1323 | "## 13. Salvando e carregando o modelo"
1324 | ]
1325 | },
1326 | {
1327 | "cell_type": "code",
1328 | "execution_count": null,
1329 | "metadata": {},
1330 | "outputs": [],
1331 | "source": [
1332 | "save_model(rc, \"rc_model\")"
1333 | ]
1334 | },
1335 | {
1336 | "cell_type": "markdown",
1337 | "metadata": {},
1338 | "source": [
1339 | "A função **save_model()** salva não apenas o modelo, mas o pipeline de preprocessamento que foi construído na função **setup()**"
1340 | ]
1341 | },
1342 | {
1343 | "cell_type": "code",
1344 | "execution_count": null,
1345 | "metadata": {},
1346 | "outputs": [],
1347 | "source": [
1348 | "model = load_model(\"rc_model\")"
1349 | ]
1350 | },
1351 | {
1352 | "cell_type": "markdown",
1353 | "metadata": {},
1354 | "source": [
1355 | "## 14. Prevendo um único evento"
1356 | ]
1357 | },
1358 | {
1359 | "cell_type": "code",
1360 | "execution_count": null,
1361 | "metadata": {},
1362 | "outputs": [],
1363 | "source": [
1364 | "data_star.loc[0]"
1365 | ]
1366 | },
1367 | {
1368 | "cell_type": "code",
1369 | "execution_count": null,
1370 | "metadata": {},
1371 | "outputs": [],
1372 | "source": [
1373 | "test_on = pd.DataFrame({\"Vmag\":{\"0\":5.99},\n",
1374 | " \"Plx\":{\"0\":13.73},\n",
1375 | " \"e_Plx\":{\"0\":0.58},\n",
1376 | " \"B-V\":{\"0\":1.318},\n",
1377 | " \"SpType\":{\"0\":\"K5III\"},\n",
1378 | " \"Amag\":{\"0\":16.678352}})\n",
1379 | "\n",
1380 | "test_on"
1381 | ]
1382 | },
1383 | {
1384 | "cell_type": "code",
1385 | "execution_count": null,
1386 | "metadata": {},
1387 | "outputs": [],
1388 | "source": [
1389 | "model.predict(test_on) #Dwarf 0 Giant 1"
1390 | ]
1391 | },
1392 | {
1393 | "cell_type": "markdown",
1394 | "metadata": {},
1395 | "source": [
1396 | "\n"
1397 | ]
1398 | },
1399 | {
1400 | "cell_type": "markdown",
1401 | "metadata": {},
1402 | "source": [
1403 | "## 15. Tarefa\n",
1404 | "\n",
1405 | "Gostou do que viu hoje? Como tarefa tenta fazer algo parecido usando o outro dataset que a gente abordou aqui :). Praticar é a melhor forma de fixar!"
1406 | ]
1407 | },
1408 | {
1409 | "cell_type": "markdown",
1410 | "metadata": {},
1411 | "source": [
1412 | "**Referências**:\n",
1413 | "* https://pycaret.org/classification/\n",
1414 | "* https://pycaret.org/preprocessing/\n",
1415 | "* https://pycaret.readthedocs.io/en/latest/index.html\n",
1416 | "* https://pycaret.org/compare-models/\n",
1417 | "* https://github.com/pycaret/pycaret/tree/master/tutorials"
1418 | ]
1419 | }
1420 | ],
1421 | "metadata": {
1422 | "kernelspec": {
1423 | "display_name": "Python 3",
1424 | "language": "python",
1425 | "name": "python3"
1426 | },
1427 | "language_info": {
1428 | "codemirror_mode": {
1429 | "name": "ipython",
1430 | "version": 3
1431 | },
1432 | "file_extension": ".py",
1433 | "mimetype": "text/x-python",
1434 | "name": "python",
1435 | "nbconvert_exporter": "python",
1436 | "pygments_lexer": "ipython3",
1437 | "version": "3.6.13"
1438 | }
1439 | },
1440 | "nbformat": 4,
1441 | "nbformat_minor": 2
1442 | }
1443 |
--------------------------------------------------------------------------------
/Machine Learning/README.md:
--------------------------------------------------------------------------------
1 | # Machine Learning com Pycaret
2 |
3 | Neste notebook abordaremos o uso da biblioteca PyCaret, uma biblioteca de AutoML inovadora que proporciona um bom pontapé inicial na área.
--------------------------------------------------------------------------------
/Machine Learning/images/PyCaret.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Machine Learning/images/PyCaret.png
--------------------------------------------------------------------------------
/Machine Learning/images/done.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Machine Learning/images/done.gif
--------------------------------------------------------------------------------
/Machine Learning/images/dwight.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Machine Learning/images/dwight.gif
--------------------------------------------------------------------------------
/Machine Learning/images/missioncomplete.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/597581c756daf7479d36c5ea9c49123f16355c43/Machine Learning/images/missioncomplete.gif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/ItamarRocha)
2 |
3 | # AI-Introduction
4 |
5 | Este repositório contém códigos e recursos para introdução à inteligência artificial. Caso tenha alguma sugestão de material para ser adicionado ou tenha interesse em contribuir com o repositório, será bem-vindo.
6 |
7 | Os slides podem ser acessados nesse [link](https://docs.google.com/presentation/d/1rGfIksTIR3l4tIhTRnaDrceq6DL7yeviLwoGArWeLF8/edit?usp=sharing).
8 |
9 | ## Contents
10 | - [Setup](#Setup)
11 | - [Iniciando](#Iniciando)
12 | - [Introdução ao Machine Learning](#Machine-Learning)
13 | - [Introdução ao Deep Learning](#Deep-Learning)
14 | - [Materiais](#Materiais)
15 | - [License](#License)
16 |
17 | ## Setup
18 |
19 | Para rodar os notebooks fornecidos não é necessário a instalação prévia de nenhuma biblioteca adicional. Todas as bibliotecas necessárias já estão disponíveis no começo dos notebooks.
20 |
21 | ## Iniciando
22 |
23 | Para rodar os notebooks é só clicar no botão do colab disponível em cada um deles.
24 |
25 | ## Machine Learning
26 |
27 | O notebook pode ser acessado nesse [link](https://github.com/ItamarRocha/AI-Introduction/blob/main/Machine%20Learning/Machine%20Learning%20com%20Pycaret.ipynb).
28 |
29 | ## Deep Learning
30 |
31 | O notebook pode ser acessado nesse [link](https://github.com/ItamarRocha/AI-Introduction/blob/main/Deep%20Learning/Deep%20Learning%20com%20Pytorch.ipynb).
32 |
33 | ## Materiais
34 |
35 | Nessa seção estarão dispostos materiais de estudo e aprofundamento na área, dividos em:
36 |
37 | * Livros
38 | * Cursos
39 | * Filmes
40 | * RoadMap (minha indicação e opinião pessoal)
41 |
42 | Os 🔥 indicam o nível de dificuldade/aprofundamento dos materiais.
43 |
44 | 🔥 - Top pra começar
45 | 🔥🔥 - Tranquilo
46 | 🔥🔥🔥 - Intermediário
47 | 🔥🔥🔥🔥 - Precisa já ter uma noção boa
48 | 🔥🔥🔥🔥🔥 - Bom já ter um aprofundamento na área
49 |
50 | ### Livros
51 |
52 | Seguem alguns bons livros nas áreas de Machine Learning e Deep Learning:
53 |
54 | * Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition by Aurélien Géron 🔥
55 | * Deep Learning with Python - Francois Chollet 🔥🔥🔥
56 | * Deep Learning with PyTorch - Eli Stevens and Thomas Viehmann 🔥🔥🔥
57 | * Mathematics for Machine Learning - Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong 🔥🔥🔥
58 |
59 | ### Cursos
60 |
61 | * [Machine Learning - Andrew Ng](https://www.coursera.org/learn/machine-learning) 🔥
62 | * [Machine Learning - Udemy](https://www.udemy.com/course/machinelearning) 🔥
63 | * [Deep Learning Specialization](https://www.coursera.org/specializations/deep-learning) 🔥🔥🔥🔥
64 | * [Manual Prático do Deep Learning - Redes Neurais Profundas](https://www.udemy.com/course/redes-neurais/) 🔥🔥
65 | * [Tensorflow Developer Professional Certificate](https://www.coursera.org/professional-certificates/tensorflow-in-practice) 🔥🔥
66 | * [Intro to Deep Learning with Pytorch](https://www.udacity.com/course/deep-learning-pytorch--ud188) 🔥🔥
67 | * [Intro to tensorflow for Deep Learning](https://www.udacity.com/course/intro-to-tensorflow-for-deep-learning--ud187) 🔥🔥
68 | * [Introduction to Deep Learning & Neural Networks](https://www.educative.io/courses/intro-deep-learning) 🔥🔥
69 |
70 | ### Filmes
71 |
72 | * [Alpha Go](https://www.youtube.com/watch?v=WXuK6gekU1Y&t=1s)
73 | * Coded Bias - Netflix
74 |
75 |
76 | ### RoadMap
77 |
78 | Aqui vou deixar minha sugestão de como e por onde começar.
79 |
80 | 1. [Machine Learning - Andrew Ng](https://www.coursera.org/learn/machine-learning) 🔥 e Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition by Aurélien Géron 🔥
81 | 2. [Deep Learning Specialization](https://www.coursera.org/specializations/deep-learning) 🔥🔥🔥🔥
82 | 3. Deep Learning with Python or Pytorch
83 | 4. [Tensorflow Developer Professional Certificate](https://www.coursera.org/professional-certificates/tensorflow-in-practice) 🔥🔥
84 | 5. Mathematics for Machine Learning - Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong 🔥🔥🔥
85 |
86 | E o principal, praticar bastante. Só aprende quem coda :P.
87 |
88 | ## License
89 |
90 | [](http://badges.mit-license.org)
91 |
92 | - **[MIT license](http://opensource.org/licenses/mit-license.php)**
93 |
--------------------------------------------------------------------------------