├── .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 | 18 | 20 | 43 | 52 | 53 | 55 | 56 | 58 | image/svg+xml 59 | 61 | 62 | 63 | 64 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 122 | 134 | 139 | 144 | 149 | 154 | 159 | 164 | 176 | 't' 187 | 'e' 198 | 'n' 209 | 's' 220 | 'o' 231 | 'r' 242 | 3 253 | 1 264 | 4 275 | 1 286 | 5 297 | 9 309 | 2 320 | 6 331 | 5 342 | 3 353 | 365 | 5 376 | 8 387 | 9 398 | 7 409 | 9 420 | 3 431 | 2 442 | 3 453 | 8 464 | 4 475 | 6 486 | 2 497 | 6 508 | 4 519 | 531 | tensor of dimensions [6](vector of dimension 6) 546 | tensor of dimensions [6,4](matrix 6 by 4) 561 | tensor of dimensions [4,4,2] 572 | 577 | 580 | 585 | 590 | 595 | 600 | 605 | 610 | 615 | 618 | 622 | 623 | 626 | 630 | 631 | 634 | 638 | 639 | 642 | 646 | 647 | 650 | 654 | 655 | 658 | 662 | 663 | 666 | 670 | 671 | 674 | 678 | 679 | 682 | 686 | 687 | 690 | 694 | 695 | 698 | 702 | 703 | 706 | 710 | 711 | 714 | 718 | 719 | 722 | 726 | 727 | 730 | 734 | 735 | 738 | 742 | 743 | 744 | 749 | 753 | 758 | 761 | 766 | 767 | 770 | 775 | 776 | 779 | 784 | 785 | 788 | 793 | 794 | 797 | 802 | 803 | 806 | 811 | 812 | 815 | 820 | 821 | 824 | 829 | 830 | 833 | 838 | 839 | 842 | 847 | 848 | 851 | 856 | 857 | 860 | 865 | 866 | 869 | 874 | 875 | 878 | 883 | 884 | 887 | 892 | 893 | 896 | 901 | 902 | 903 | 908 | 913 | 918 | 923 | 928 | 933 | 938 | 943 | 948 | 953 | 958 | 963 | 968 | 973 | 978 | 983 | 988 | 993 | 998 | 1003 | 1008 | 1013 | 1018 | 1023 | 1028 | 1033 | 1038 | 1043 | 1048 | 1053 | 1058 | 1063 | 1068 | 1069 | 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 | "\"Open" 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 | "\n", 123 | "\n", 124 | "\n", 125 | "\n", 126 | "\n", 127 | "\n", 128 | "\n", 129 | "\n", 130 | "\n", 131 | "\n", 132 | "\n", 133 | "\n", 134 | "\n", 135 | "\n", 136 | "\n", 137 | "\n", 138 | "\n", 139 | "\n", 140 | "\n", 141 | "\n", 142 | "\n", 143 | "\n", 144 | "\n", 145 | "\n", 146 | "\n", 147 | "\n", 148 | "\n", 149 | "\n", 150 | "\n", 151 | "\n", 152 | "\n", 153 | "\n", 154 | "\n", 155 | "\n", 156 | "\n", 157 | "\n", 158 | "\n", 159 | "\n", 160 | "\n", 161 | "\n", 162 | "\n", 163 | "\n", 164 | "\n", 165 | "\n", 166 | "\n", 167 | "\n", 168 | "\n", 169 | "\n", 170 | "\n", 171 | "\n", 172 | "\n", 173 | "\n", 174 | "\n", 175 | "\n", 176 | "\n", 177 | "\n", 178 | "\n", 179 | "\n", 180 | "\n", 181 | "\n", 182 | "\n", 183 | "\n", 184 | "\n", 185 | "\n", 186 | "\n", 187 | "\n", 188 | "\n", 189 | "\n", 190 | "\n", 191 | "\n", 192 | "\n", 193 | "\n", 194 | "\n", 195 | "\n", 196 | "\n", 197 | "\n", 198 | "\n", 199 | "\n", 200 | "\n", 201 | "\n", 202 | "\n", 203 | "\n", 204 | "\n", 205 | "\n", 206 | "\n", 207 | "\n", 208 | "\n", 209 | "\n", 210 | "\n", 211 | "\n", 212 | "\n", 213 | "\n", 214 | "\n", 215 | "\n", 216 | "\n", 217 | "\n", 218 | "\n", 219 | "\n", 220 | "\n", 221 | "\n", 222 | "\n", 223 | "\n", 224 | "\n", 225 | "\n", 226 | "\n", 227 | "\n", 228 | "\n", 229 | "\n", 230 | "\n", 231 | "\n", 232 | "\n", 233 | "\n", 234 | "\n", 235 | "\n", 236 | "\n", 237 | "\n", 238 | "\n", 239 | "\n", 240 | "\n", 241 | "\n", 242 | "\n", 243 | "\n", 244 | "\n", 245 | "\n", 246 | "\n", 247 | "\n", 248 | "\n", 249 | "\n", 250 | "\n", 251 | "\n", 252 | "\n", 253 | "\n", 254 | "\n", 255 | "\n", 256 | "\n", 257 | "\n", 258 | "\n", 259 | "\n", 260 | "\n", 261 | "\n", 262 | "\n", 263 | "\n", 264 | "\n", 265 | "\n", 266 | "\n", 267 | "\n", 268 | "\n", 269 | "\n", 270 | "\n", 271 | "\n", 272 | "\n", 273 | "\n", 274 | "\n", 275 | "\n", 276 | "\n", 277 | "\n", 278 | "\n", 279 | "\n", 280 | "\n", 281 | "\n", 282 | "\n", 283 | "\n", 284 | "\n", 285 | "\n", 286 | "\n", 287 | "\n", 288 | "\n", 289 | "\n", 290 | "\n", 291 | "\n", 292 | "\n", 293 | "\n", 294 | "\n", 295 | "\n", 296 | "\n", 297 | "\n", 298 | "\n", 299 | "\n", 300 | "\n", 301 | "\n", 302 | "\n", 303 | "\n", 304 | "\n", 305 | "\n", 306 | "\n", 307 | "\n", 308 | "\n", 309 | "\n", 310 | "\n", 311 | "\n", 312 | "\n", 313 | "\n", 314 | "\n", 315 | "\n", 316 | "\n", 317 | "\n", 318 | "\n", 319 | "\n", 320 | "\n", 321 | "\n", 322 | "\n", 323 | "\n", 324 | "\n", 325 | "\n", 326 | "\n", 327 | "\n", 328 | "\n", 329 | "\n", 330 | "\n", 331 | "\n", 332 | "\n", 333 | "\n", 334 | "\n", 335 | "\n", 336 | "\n", 337 | "\n", 338 | "\n", 339 | "\n", 340 | "\n", 341 | "\n", 342 | "\n", 343 | "\n", 344 | "\n", 345 | "\n", 346 | "\n", 347 | "\n", 348 | "\n", 349 | "\n", 350 | "\n", 351 | "\n", 352 | "\n", 353 | "\n", 354 | "\n", 355 | "\n", 356 | "\n", 357 | "\n", 358 | "\n", 359 | "\n", 360 | "\n", 361 | "\n", 362 | "\n", 363 | "\n", 364 | "\n", 365 | "\n", 366 | "\n", 367 | "\n", 368 | "\n", 369 | "\n", 370 | "\n", 371 | "\n", 372 | "\n", 373 | "\n", 374 | "\n", 375 | "\n", 376 | "\n", 377 | "\n", 378 | "\n", 379 | "\n", 380 | "\n", 381 | "\n", 382 | "\n", 383 | "\n", 384 | "\n", 385 | "\n", 386 | "\n", 387 | "\n", 388 | "\n", 389 | "\n", 390 | "\n", 391 | "\n", 392 | "\n", 393 | "\n", 394 | "\n", 395 | "\n", 396 | "\n", 397 | "\n", 398 | "\n", 399 | "\n", 400 | "\n", 401 | "\n", 402 | "\n", 403 | "\n", 404 | "\n", 405 | "\n", 406 | "\n", 407 | "\n", 408 | "\n", 409 | "\n", 410 | "\n", 411 | "\n", 412 | "\n", 413 | "\n", 414 | "\n", 415 | "\n", 416 | "\n", 417 | "\n", 418 | "\n", 419 | "\n", 420 | "\n", 421 | "\n", 422 | "\n", 423 | "\n", 424 | "\n", 425 | "\n", 426 | "\n", 427 | "\n", 428 | "\n", 429 | "\n", 430 | "\n", 431 | "\n", 432 | "\n", 433 | "\n", 434 | "\n", 435 | "\n", 436 | "\n", 437 | "\n", 438 | "\n", 439 | "\n", 440 | "\n", 441 | "\n", 442 | "\n", 443 | "\n", 444 | "\n", 445 | "\n", 446 | "\n", 447 | "\n", 448 | "\n", 449 | "\n", 450 | "\n", 451 | "\n", 452 | "\n", 453 | "\n", 454 | "\n", 455 | "\n", 456 | "\n", 457 | "\n", 458 | "\n", 459 | "\n", 460 | "\n", 461 | "\n", 462 | "\n", 463 | "\n", 464 | "\n", 465 | "\n", 466 | "\n", 467 | "\n", 468 | "\n", 469 | "\n", 470 | "\n", 471 | "\n", 472 | "\n", 473 | "\n", 474 | "\n", 475 | "\n", 476 | "\n", 477 | "\n", 478 | "\n", 479 | "\n", 480 | "\n", 481 | "\n", 482 | "\n", 483 | "\n", 484 | "\n", 485 | "\n", 486 | "\n", 487 | "\n", 488 | "\n", 489 | "\n", 490 | "\n", 491 | "\n", 492 | "\n", 493 | "\n", 494 | "\n", 495 | "\n", 496 | "\n", 497 | "\n", 498 | "\n", 499 | "\n", 500 | "\n", 501 | "\n", 502 | "\n", 503 | "\n", 504 | "\n", 505 | "\n", 506 | "\n", 507 | "\n", 508 | "\n", 509 | "\n", 510 | "\n", 511 | "\n", 512 | "\n", 513 | "\n", 514 | "\n", 515 | "\n", 516 | "\n", 517 | "\n", 518 | "\n", 519 | "\n", 520 | "\n", 521 | "\n", 522 | "\n", 523 | "\n", 524 | "\n", 525 | "\n", 526 | "\n", 527 | "\n", 528 | "\n", 529 | "\n", 530 | "\n", 531 | "\n", 532 | "\n", 533 | "\n", 534 | "\n", 535 | "\n", 536 | "\n", 537 | "\n", 538 | "\n", 539 | "\n", 540 | "\n", 541 | "\n", 542 | "\n", 543 | "\n", 544 | "\n", 545 | "\n", 546 | "\n", 547 | "\n", 548 | "\n", 549 | "\n", 550 | "\n", 551 | "\n", 552 | "\n", 553 | "\n", 554 | "
DatasetTipo dos dadosTarefa padrãoVariável targetNº de instânciasNº de atributos
anomalyMultivariateAnomaly DetectionNone100010
franceMultivariateAssociation Rule MiningInvoiceNo, Description85578
germanyMultivariateAssociation Rule MiningInvoiceNo, Description94958
bankMultivariateClassification (Binary)deposit4521117
bloodMultivariateClassification (Binary)Class7485
cancerMultivariateClassification (Binary)Class68310
creditMultivariateClassification (Binary)default2400024
diabetesMultivariateClassification (Binary)Class variable7689
electrical_gridMultivariateClassification (Binary)stabf1000014
employeeMultivariateClassification (Binary)left1499910
heartMultivariateClassification (Binary)DEATH20016
heart_diseaseMultivariateClassification (Binary)Disease27014
hepatitisMultivariateClassification (Binary)Class15432
incomeMultivariateClassification (Binary)income >50K3256114
juiceMultivariateClassification (Binary)Purchase107015
nbaMultivariateClassification (Binary)TARGET_5Yrs134021
wineMultivariateClassification (Binary)type649813
telescopeMultivariateClassification (Binary)Class1902011
glassMultivariateClassification (Multiclass)Type21410
irisMultivariateClassification (Multiclass)species1505
pokerMultivariateClassification (Multiclass)CLASS10000011
questionsMultivariateClassification (Multiclass)Next_Question4994
satelliteMultivariateClassification (Multiclass)Class643537
asia_gdpMultivariateClusteringNone4011
electionsMultivariateClusteringNone319554
facebookMultivariateClusteringNone705012
iplMultivariateClusteringNone15325
jewelleryMultivariateClusteringNone5054
miceMultivariateClusteringNone108082
migrationMultivariateClusteringNone23312
perfumeMultivariateClusteringNone2029
pokemonMultivariateClusteringNone80013
populationMultivariateClusteringNone25556
public_healthMultivariateClusteringNone22421
seedsMultivariateClusteringNone2107
wholesaleMultivariateClusteringNone4408
tweetsTextNLPtweet85942
amazonTextNLP / ClassificationreviewText200002
kivaTextNLP / Classificationen68187
spxTextNLP / Regressiontext8744
wikipediaTextNLP / ClassificationText5003
automobileMultivariateRegressionprice20226
bikeMultivariateRegressioncnt1737915
bostonMultivariateRegressionmedv50614
concreteMultivariateRegressionstrength10309
diamondMultivariateRegressionPrice60008
energyMultivariateRegressionHeating Load / Cooling Load76810
forestMultivariateRegressionarea51713
goldMultivariateRegressionGold_T+222558121
houseMultivariateRegressionSalePrice146181
insuranceMultivariateRegressioncharges13387
parkinsonsMultivariateRegressionPPE587522
trafficMultivariateRegressiontraffic_volume482048
" 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 | " \n", 657 | " \n", 658 | " \n", 659 | " \n", 660 | " \n", 661 | " \n", 662 | " \n", 663 | " \n", 664 | " \n", 665 | " \n", 666 | " \n", 667 | " \n", 668 | " \n", 669 | " \n", 670 | " \n", 671 | " \n", 672 | " \n", 673 | " \n", 674 | " \n", 675 | " \n", 676 | " \n", 677 | " \n", 678 | " \n", 679 | " \n", 680 | " \n", 681 | " \n", 682 | " \n", 683 | " \n", 684 | " \n", 685 | " \n", 686 | " \n", 687 | " \n", 688 | "
VariávelDescrição
VmagVisual Apparent Magnitude of the Star
PlxDistance Between the Star and the Earth
e_PlxStandard Error of Plx (Drop the Row if you find the e_Plx is too high!)
B-VB-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.
SpTypeSpectral type
AmagAbsolute Magnitude of the Star
TargetClassWhether the Star is Dwarf (0) or Giant (1)
" 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 | " \n", 751 | " \n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | "
MóduloComo importar
Classificaçãofrom pycaret.classification import *
Regressãofrom pycaret.regression import *
Clusterizaçãofrom pycaret.clustering import *
Detecção de Anomaliasfrom pycaret.anomaly import *
Processamento de Linguagem Naturalfrom pycaret.nlp import *
Association Rule Miningfrom pycaret.arules import *
" 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 | "![](https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/main/Machine%20Learning/images/dwight.gif?token=AMZBEI24W2A2G74MN3RTST3AYU5X2)\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 | "![](https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/main/Machine%20Learning/images/done.gif?token=AMZBEI3Z6P65XO2BZZMR6ADAYU52C)\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 | " \n", 1103 | " \n", 1104 | " \n", 1105 | " \n", 1106 | " \n", 1107 | " \n", 1108 | " \n", 1109 | " \n", 1110 | " \n", 1111 | " \n", 1112 | " \n", 1113 | " \n", 1114 | " \n", 1115 | " \n", 1116 | " \n", 1117 | " \n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | " \n", 1150 | " \n", 1151 | " \n", 1152 | " \n", 1153 | " \n", 1154 | " \n", 1155 | " \n", 1156 | " \n", 1157 | " \n", 1158 | " \n", 1159 | " \n", 1160 | " \n", 1161 | " \n", 1162 | " \n", 1163 | " \n", 1164 | " \n", 1165 | " \n", 1166 | "
GráficoNome
‘auc’Area Under the Curve
‘threshold’Discrimination Threshold
‘pr’Precision Recall Curve
‘confusion_matrix’Confusion Matrix
‘error’Class Prediction Error
‘class_report’Classification Report
‘boundary’Decision Boundary
‘rfe’Recursive Feature Selection
‘learning’Learning Curve
‘manifold’Manifold Learning
‘calibration’Calibration Curve
‘vc’Validation Curve
‘dimension’Dimension Learning
‘feature’Feature Importance
‘parameter’Model Hyperparameter
" 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 | "" 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 | "![](https://raw.githubusercontent.com/ItamarRocha/AI-Introduction/main/Machine%20Learning/images/missioncomplete.gif?token=AMZBEIZ3R5RTSKSU2JRHULDAYU6XW)\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 | [![author](https://img.shields.io/badge/author-ItamarRocha-black.svg)](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 | [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org) 91 | 92 | - **[MIT license](http://opensource.org/licenses/mit-license.php)** 93 | --------------------------------------------------------------------------------