├── Boosting_Adaboost.pdf ├── Decision_Tree.pdf ├── Ensemble_Bagging.pdf ├── GBDT.pdf ├── Knn_theory.pdf ├── Linear Reg.zip ├── Logistic Regression - Jupyter Notebook.pdf ├── Numpy.zip ├── Pandas.zip ├── Polymorphism.ipynb ├── Python.zip ├── Recursion.ipynb ├── SVM.pdf ├── Statistics.zip ├── String formating.ipynb ├── Visualization.zip ├── mytree.png ├── tree_pt.png └── weights.csv /Boosting_Adaboost.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Boosting_Adaboost.pdf -------------------------------------------------------------------------------- /Decision_Tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Decision_Tree.pdf -------------------------------------------------------------------------------- /Ensemble_Bagging.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Ensemble_Bagging.pdf -------------------------------------------------------------------------------- /GBDT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/GBDT.pdf -------------------------------------------------------------------------------- /Knn_theory.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Knn_theory.pdf -------------------------------------------------------------------------------- /Linear Reg.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Linear Reg.zip -------------------------------------------------------------------------------- /Logistic Regression - Jupyter Notebook.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Logistic Regression - Jupyter Notebook.pdf -------------------------------------------------------------------------------- /Numpy.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Numpy.zip -------------------------------------------------------------------------------- /Pandas.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Pandas.zip -------------------------------------------------------------------------------- /Polymorphism.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4b00fc2a", 6 | "metadata": {}, 7 | "source": [ 8 | "# OOPS" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "b7d7d94a", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "60d7758c", 22 | "metadata": {}, 23 | "source": [ 24 | "- In Python, **polymorphism** is a fundamental concept in object-oriented programming (OOP) that allows objects of different classes to be treated as objects of a common superclass. \n", 25 | "- It enables you to use a single interface to represent different types of objects, and it's a key feature that promotes code flexibility, reusability, and abstraction" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "id": "4849d076", 31 | "metadata": {}, 32 | "source": [ 33 | "### Method Overriding" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "id": "ae385d1a", 39 | "metadata": {}, 40 | "source": [ 41 | "- Method overriding allows a subclass to provide a specific implementation for a method that is already defined in its superclass.\n", 42 | "- When a method is called on an object of the subclass, the overridden method in the subclass is executed instead of the method in the superclass. \n", 43 | "- This allows different classes to have their unique behavior for the same method name." 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 1, 49 | "id": "18893fe5", 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Meow\n", 57 | "Woof\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "class Animal:\n", 63 | " def make_sound(self):\n", 64 | " print(\"Generic animal sound\")\n", 65 | "\n", 66 | "class Cat(Animal):\n", 67 | " def make_sound(self):\n", 68 | " print(\"Meow\")\n", 69 | "\n", 70 | "class Dog(Animal):\n", 71 | " def make_sound(self):\n", 72 | " print(\"Woof\")\n", 73 | "\n", 74 | "cat = Cat()\n", 75 | "dog = Dog()\n", 76 | "\n", 77 | "cat.make_sound() \n", 78 | "dog.make_sound() \n" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 7, 84 | "id": "0cb732a5", 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "import math\n", 89 | "\n", 90 | "class Shape:\n", 91 | " def area(self):\n", 92 | " return \"area cannot be calculated\"\n", 93 | "\n", 94 | "class Circle(Shape):\n", 95 | " def __init__(self, radius):\n", 96 | " self.radius = radius\n", 97 | "\n", 98 | " def area(self):\n", 99 | " return math.pi * self.radius ** 2\n", 100 | "\n", 101 | "class Rectangle(Shape):\n", 102 | " def __init__(self, width, height):\n", 103 | " self.width = width\n", 104 | " self.height = height\n", 105 | "\n", 106 | " def area(self):\n", 107 | " return self.width * self.height\n", 108 | "\n", 109 | "class Triangle(Shape):\n", 110 | " def __init__(self, base, height):\n", 111 | " self.base = base\n", 112 | " self.height = height\n", 113 | "\n", 114 | " def area(self):\n", 115 | " return 0.5 * self.base * self.height" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 8, 121 | "id": "b248a130", 122 | "metadata": {}, 123 | "outputs": [ 124 | { 125 | "data": { 126 | "text/plain": [ 127 | "28.274333882308138" 128 | ] 129 | }, 130 | "execution_count": 8, 131 | "metadata": {}, 132 | "output_type": "execute_result" 133 | } 134 | ], 135 | "source": [ 136 | "c1 = Circle(3)\n", 137 | "c1.area()" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 6, 143 | "id": "3396f547", 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": [ 149 | "28.274333882308138" 150 | ] 151 | }, 152 | "execution_count": 6, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "math.pi*3*3" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "id": "92d2f0ab", 165 | "metadata": {}, 166 | "outputs": [], 167 | "source": [] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "id": "c62610cb", 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "id": "248a57f5", 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": null, 188 | "id": "228bc90a", 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "id": "4dfde0b0", 197 | "metadata": {}, 198 | "outputs": [], 199 | "source": [] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 2, 204 | "id": "ef6bf551", 205 | "metadata": {}, 206 | "outputs": [ 207 | { 208 | "name": "stdout", 209 | "output_type": "stream", 210 | "text": [ 211 | "Area: 28.274333882308138\n", 212 | "Area: 20\n", 213 | "Area: 6.0\n" 214 | ] 215 | } 216 | ], 217 | "source": [ 218 | "shapes = [Circle(3), Rectangle(4, 5), Triangle(6, 2)]\n", 219 | "\n", 220 | "for shape in shapes:\n", 221 | " print(f\"Area: {shape.area()}\")" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "id": "7c4910b9", 227 | "metadata": {}, 228 | "source": [ 229 | "## Method Overloading" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "id": "b129eb4f", 235 | "metadata": {}, 236 | "source": [ 237 | "- Method overloading allows a single method name to be used for multiple methods that differ in the number or types of their parameters. \n", 238 | "- Python does not support traditional method overloading like some other languages, but it can be simulated using default parameter values and/or variable-length arguments." 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 9, 244 | "id": "c798d344", 245 | "metadata": {}, 246 | "outputs": [], 247 | "source": [ 248 | "class MathOperations:\n", 249 | " def add(self, a, b):\n", 250 | " return a + b\n", 251 | "\n", 252 | " def add(self, a, b, c):\n", 253 | " return a + b + c" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 10, 259 | "id": "af829c50", 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [ 263 | "math_ops = MathOperations()" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 11, 269 | "id": "c0987bed", 270 | "metadata": {}, 271 | "outputs": [ 272 | { 273 | "data": { 274 | "text/plain": [ 275 | "<__main__.MathOperations at 0x10f021c40>" 276 | ] 277 | }, 278 | "execution_count": 11, 279 | "metadata": {}, 280 | "output_type": "execute_result" 281 | } 282 | ], 283 | "source": [ 284 | "math_ops" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 12, 290 | "id": "d562aa46", 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "ename": "TypeError", 295 | "evalue": "add() missing 1 required positional argument: 'c'", 296 | "output_type": "error", 297 | "traceback": [ 298 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 299 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 300 | "Cell \u001b[0;32mIn[12], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mmath_ops\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m)\n", 301 | "\u001b[0;31mTypeError\u001b[0m: add() missing 1 required positional argument: 'c'" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "print(math_ops.add(2, 3)) " 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 13, 312 | "id": "fd864ef5", 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "10\n" 320 | ] 321 | } 322 | ], 323 | "source": [ 324 | "print(math_ops.add(2, 3, 5))" 325 | ] 326 | }, 327 | { 328 | "cell_type": "markdown", 329 | "id": "75251465", 330 | "metadata": {}, 331 | "source": [ 332 | "## Polymorphism with inbuilt functions" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": 15, 338 | "id": "048b1673", 339 | "metadata": {}, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "5\n", 346 | "3\n", 347 | "2\n" 348 | ] 349 | } 350 | ], 351 | "source": [ 352 | "# len() function\n", 353 | "print(len(\"hello\")) # Output: 5\n", 354 | "print(len([1, 2, 3])) # Output: 3\n", 355 | "print(len({\"a\": 1, \"b\": 2})) # Output: 2" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 16, 361 | "id": "bc84e7a9", 362 | "metadata": {}, 363 | "outputs": [ 364 | { 365 | "data": { 366 | "text/plain": [ 367 | "'10'" 368 | ] 369 | }, 370 | "execution_count": 16, 371 | "metadata": {}, 372 | "output_type": "execute_result" 373 | } 374 | ], 375 | "source": [ 376 | "# str() function\n", 377 | "str(10) # Output: \"10\"" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 18, 383 | "id": "fe0713ab", 384 | "metadata": {}, 385 | "outputs": [ 386 | { 387 | "data": { 388 | "text/plain": [ 389 | "'[1, 2, 3]'" 390 | ] 391 | }, 392 | "execution_count": 18, 393 | "metadata": {}, 394 | "output_type": "execute_result" 395 | } 396 | ], 397 | "source": [ 398 | "str([1, 2, 3]) # Output: \"[1, 2, 3]\"" 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "execution_count": 20, 404 | "id": "b456aa6c", 405 | "metadata": {}, 406 | "outputs": [ 407 | { 408 | "data": { 409 | "text/plain": [ 410 | "\"{'a': 1, 'b': 2}\"" 411 | ] 412 | }, 413 | "execution_count": 20, 414 | "metadata": {}, 415 | "output_type": "execute_result" 416 | } 417 | ], 418 | "source": [ 419 | "str({\"a\": 1, \"b\": 2}) # Output: \"{'a': 1, 'b': 2}\"" 420 | ] 421 | }, 422 | { 423 | "cell_type": "markdown", 424 | "id": "ef8bdc4d", 425 | "metadata": {}, 426 | "source": [ 427 | "# Polymorphism in Data Science" 428 | ] 429 | }, 430 | { 431 | "cell_type": "markdown", 432 | "id": "dd4ff8af", 433 | "metadata": {}, 434 | "source": [ 435 | "- In data science, polymorphism may not be as commonly used as in object-oriented programming, but some aspects of polymorphism can be observed in certain contexts.\n", 436 | "- Data analysis often involves working with various data types and structures, and the ability to apply operations or functions uniformly across different data formats can be considered a form of polymorphism." 437 | ] 438 | }, 439 | { 440 | "cell_type": "markdown", 441 | "id": "8ce842f6", 442 | "metadata": {}, 443 | "source": [ 444 | "**Operations on Different Data Types:**\n", 445 | "- In data science, you may perform operations on different data types like numbers, strings, lists, arrays, or DataFrames.\n", 446 | "- Functions or operations that can handle multiple data types and provide consistent results regardless of the input type can be seen as polymorphic." 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": 21, 452 | "id": "0905efcc", 453 | "metadata": {}, 454 | "outputs": [], 455 | "source": [ 456 | "# Polymorphic behavior with addition operation\n", 457 | "result1 = 2 + 3 # (integers)\n", 458 | "result2 = \"Hello, \" + \"world!\" # (strings)\n", 459 | "result3 = [1, 2, 3] + [4, 5, 6] # (lists)" 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": 22, 465 | "id": "960c25de", 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "name": "stdout", 470 | "output_type": "stream", 471 | "text": [ 472 | "5\n", 473 | "Hello, world!\n", 474 | "[1, 2, 3, 4, 5, 6]\n" 475 | ] 476 | } 477 | ], 478 | "source": [ 479 | "print(result1)\n", 480 | "print(result2)\n", 481 | "print(result3)" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": null, 487 | "id": "809e0bd8", 488 | "metadata": {}, 489 | "outputs": [], 490 | "source": [] 491 | }, 492 | { 493 | "cell_type": "code", 494 | "execution_count": null, 495 | "id": "616d2412", 496 | "metadata": {}, 497 | "outputs": [], 498 | "source": [] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": null, 503 | "id": "ef622965", 504 | "metadata": {}, 505 | "outputs": [], 506 | "source": [] 507 | }, 508 | { 509 | "cell_type": "code", 510 | "execution_count": null, 511 | "id": "3f010bfe", 512 | "metadata": {}, 513 | "outputs": [], 514 | "source": [] 515 | }, 516 | { 517 | "cell_type": "markdown", 518 | "id": "5d516c19", 519 | "metadata": {}, 520 | "source": [ 521 | "**Aggregation Functions:**\n", 522 | "- Aggregation functions like sum(), mean(), max(), etc., can be applied to different data structures such as lists, arrays, or DataFrames.\n", 523 | "- These functions demonstrate polymorphic behavior as they can operate on various data types and produce meaningful results." 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 13, 529 | "id": "55390b7c", 530 | "metadata": {}, 531 | "outputs": [], 532 | "source": [ 533 | "import numpy as np\n", 534 | "\n", 535 | "# Polymorphic behavior with aggregation functions\n", 536 | "numbers = [1, 2, 3, 4, 5]\n", 537 | "result1 = sum(numbers) # (list)\n", 538 | "result2 = np.mean(numbers) # (numpy array)\n" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 14, 544 | "id": "b97b89b8", 545 | "metadata": {}, 546 | "outputs": [ 547 | { 548 | "name": "stdout", 549 | "output_type": "stream", 550 | "text": [ 551 | "15\n", 552 | "3.0\n" 553 | ] 554 | } 555 | ], 556 | "source": [ 557 | "print(result1)\n", 558 | "print(result2)" 559 | ] 560 | }, 561 | { 562 | "cell_type": "markdown", 563 | "id": "9c2a7b1f", 564 | "metadata": {}, 565 | "source": [ 566 | "**Handling Missing Data:**\n", 567 | "- When dealing with datasets, it's common to encounter missing data. \n", 568 | "- Polymorphic behavior can be observed when functions or methods handle missing data gracefully, regardless of the data structure." 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": 23, 574 | "id": "9ead2ff6", 575 | "metadata": {}, 576 | "outputs": [], 577 | "source": [ 578 | "import pandas as pd\n", 579 | "\n", 580 | "# Polymorphic behavior in handling missing data\n", 581 | "data = {'A': [1, 2, None, 4],\n", 582 | " 'B': [5, None, 7, 8]}\n", 583 | "df = pd.DataFrame(data)" 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 24, 589 | "id": "8411ae98", 590 | "metadata": {}, 591 | "outputs": [ 592 | { 593 | "data": { 594 | "text/html": [ 595 | "
\n", 596 | "\n", 609 | "\n", 610 | " \n", 611 | " \n", 612 | " \n", 613 | " \n", 614 | " \n", 615 | " \n", 616 | " \n", 617 | " \n", 618 | " \n", 619 | " \n", 620 | " \n", 621 | " \n", 622 | " \n", 623 | " \n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | " \n", 638 | " \n", 639 | "
AB
01.05.0
12.0NaN
2NaN7.0
34.08.0
\n", 640 | "
" 641 | ], 642 | "text/plain": [ 643 | " A B\n", 644 | "0 1.0 5.0\n", 645 | "1 2.0 NaN\n", 646 | "2 NaN 7.0\n", 647 | "3 4.0 8.0" 648 | ] 649 | }, 650 | "execution_count": 24, 651 | "metadata": {}, 652 | "output_type": "execute_result" 653 | } 654 | ], 655 | "source": [ 656 | "df" 657 | ] 658 | }, 659 | { 660 | "cell_type": "code", 661 | "execution_count": 25, 662 | "id": "87ac3b05", 663 | "metadata": {}, 664 | "outputs": [], 665 | "source": [ 666 | "result1 = df.mean() # Output: Calculates mean for each column, ignoring missing values\n", 667 | "result2 = df.sum() # Output: Calculates sum for each column, treating missing values as zero" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": 26, 673 | "id": "aad72e84", 674 | "metadata": {}, 675 | "outputs": [ 676 | { 677 | "data": { 678 | "text/plain": [ 679 | "A 2.333333\n", 680 | "B 6.666667\n", 681 | "dtype: float64" 682 | ] 683 | }, 684 | "execution_count": 26, 685 | "metadata": {}, 686 | "output_type": "execute_result" 687 | } 688 | ], 689 | "source": [ 690 | "result1" 691 | ] 692 | }, 693 | { 694 | "cell_type": "code", 695 | "execution_count": 27, 696 | "id": "d0f1ccb5", 697 | "metadata": {}, 698 | "outputs": [ 699 | { 700 | "data": { 701 | "text/plain": [ 702 | "A 7.0\n", 703 | "B 20.0\n", 704 | "dtype: float64" 705 | ] 706 | }, 707 | "execution_count": 27, 708 | "metadata": {}, 709 | "output_type": "execute_result" 710 | } 711 | ], 712 | "source": [ 713 | "result2" 714 | ] 715 | }, 716 | { 717 | "cell_type": "markdown", 718 | "id": "c06ed530", 719 | "metadata": {}, 720 | "source": [ 721 | "**Function Application to Columns or Rows:**\n", 722 | "- In data analysis libraries like pandas, you can apply functions to columns or rows of a DataFrame.\n", 723 | "- The function applied may vary depending on the data type of each column, and this can be considered a form of polymorphism" 724 | ] 725 | }, 726 | { 727 | "cell_type": "code", 728 | "execution_count": 28, 729 | "id": "d2457b31", 730 | "metadata": {}, 731 | "outputs": [], 732 | "source": [ 733 | "import pandas as pd\n", 734 | "\n", 735 | "# Polymorphic behavior with function application in pandas\n", 736 | "data = {'A': [1, 2, 3, 4],\n", 737 | " 'B': ['apple', 'banana', 'cherry', 'date']}\n", 738 | "df = pd.DataFrame(data)" 739 | ] 740 | }, 741 | { 742 | "cell_type": "code", 743 | "execution_count": 31, 744 | "id": "ede278fe", 745 | "metadata": {}, 746 | "outputs": [ 747 | { 748 | "data": { 749 | "text/html": [ 750 | "
\n", 751 | "\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 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | "
AB
01apple
12banana
23cherry
34date
\n", 795 | "
" 796 | ], 797 | "text/plain": [ 798 | " A B\n", 799 | "0 1 apple\n", 800 | "1 2 banana\n", 801 | "2 3 cherry\n", 802 | "3 4 date" 803 | ] 804 | }, 805 | "execution_count": 31, 806 | "metadata": {}, 807 | "output_type": "execute_result" 808 | } 809 | ], 810 | "source": [ 811 | "df" 812 | ] 813 | }, 814 | { 815 | "cell_type": "code", 816 | "execution_count": 32, 817 | "id": "be32e8f1", 818 | "metadata": {}, 819 | "outputs": [], 820 | "source": [ 821 | "# Apply different functions to different columns\n", 822 | "result1 = df['A'].mean() # Output: 2.5 (mean of integers)\n", 823 | "result2 = df['B'].str.upper() # Output: ['APPLE', 'BANANA', 'CHERRY', 'DATE'] (uppercase strings)" 824 | ] 825 | }, 826 | { 827 | "cell_type": "code", 828 | "execution_count": 33, 829 | "id": "a745d8d4", 830 | "metadata": {}, 831 | "outputs": [ 832 | { 833 | "data": { 834 | "text/plain": [ 835 | "2.5" 836 | ] 837 | }, 838 | "execution_count": 33, 839 | "metadata": {}, 840 | "output_type": "execute_result" 841 | } 842 | ], 843 | "source": [ 844 | "result1" 845 | ] 846 | }, 847 | { 848 | "cell_type": "code", 849 | "execution_count": 34, 850 | "id": "b0de520e", 851 | "metadata": {}, 852 | "outputs": [ 853 | { 854 | "data": { 855 | "text/plain": [ 856 | "0 APPLE\n", 857 | "1 BANANA\n", 858 | "2 CHERRY\n", 859 | "3 DATE\n", 860 | "Name: B, dtype: object" 861 | ] 862 | }, 863 | "execution_count": 34, 864 | "metadata": {}, 865 | "output_type": "execute_result" 866 | } 867 | ], 868 | "source": [ 869 | "result2" 870 | ] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": null, 875 | "id": "4b2abb9d", 876 | "metadata": {}, 877 | "outputs": [], 878 | "source": [] 879 | } 880 | ], 881 | "metadata": { 882 | "kernelspec": { 883 | "display_name": "Python 3 (ipykernel)", 884 | "language": "python", 885 | "name": "python3" 886 | }, 887 | "language_info": { 888 | "codemirror_mode": { 889 | "name": "ipython", 890 | "version": 3 891 | }, 892 | "file_extension": ".py", 893 | "mimetype": "text/x-python", 894 | "name": "python", 895 | "nbconvert_exporter": "python", 896 | "pygments_lexer": "ipython3", 897 | "version": "3.9.16" 898 | }, 899 | "vp": { 900 | "vp_config_version": "1.0.0", 901 | "vp_menu_width": 273, 902 | "vp_note_display": false, 903 | "vp_note_width": 0, 904 | "vp_position": { 905 | "width": 278 906 | }, 907 | "vp_section_display": false, 908 | "vp_signature": "VisualPython" 909 | } 910 | }, 911 | "nbformat": 4, 912 | "nbformat_minor": 5 913 | } 914 | -------------------------------------------------------------------------------- /Python.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Python.zip -------------------------------------------------------------------------------- /Recursion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c8ccf889", 6 | "metadata": {}, 7 | "source": [ 8 | "- Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, more manageable subproblems. \n", 9 | "- In essence, it is a way of solving problems by dividing them into smaller instances of the same problem until a base case is reached, at which point the recursion \"unwinds\" and returns the results of the smaller subproblems to solve the original problem.\n", 10 | "\n", 11 | "- Recursion is commonly used in algorithms and programming tasks that involve repetitive and self-referential processes.\n", 12 | "- It is especially useful when dealing with problems that have a recursive or fractal-like structure." 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "id": "4caf83ba", 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "name": "stdout", 23 | "output_type": "stream", 24 | "text": [ 25 | "120\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "def factorial(n):\n", 31 | " if n == 0:\n", 32 | " return 1 # Base case: factorial(0) is 1\n", 33 | " else:\n", 34 | " return n * factorial(n - 1) # Recursive case: factorial(n) = n * factorial(n-1)\n", 35 | "\n", 36 | "# Example usage:\n", 37 | "result = factorial(5) # 5! = 5 * 4 * 3 * 2 * 1 = 120\n", 38 | "print(result)\n" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 32, 44 | "id": "da1d1613", 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "The time of execution of the above code is -0.0001 seconds\n", 52 | "120\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "start_time_1 = time.time()\n", 58 | "result = factorial(5) # 5! = 5 * 4 * 3 * 2 * 1 = 120\n", 59 | "end_time_1 = time.time()\n", 60 | "print('The time of execution of the above code is {} seconds'.format(round(start_time_1-end_time_1,6)))\n", 61 | "print(result)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "id": "17e0d536", 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "id": "e50e443d", 75 | "metadata": {}, 76 | "source": [ 77 | "## Advantages of Recursion" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "0ec514db", 83 | "metadata": {}, 84 | "source": [ 85 | " **Simplicity and Clarity** \n", 86 | "- Recursive solutions can often be more intuitive and easier to understand than iterative solutions, especially for problems with a recursive nature or those involving self-similar subproblems." 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "id": "353c8f21", 92 | "metadata": {}, 93 | "source": [ 94 | " **Reduced Code Length** \n", 95 | "- Recursive solutions can sometimes be more concise than their iterative counterparts, as they focus on the high-level logic and delegate repetitive tasks to recursive calls." 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "id": "db779cd3", 101 | "metadata": {}, 102 | "source": [ 103 | "**Example**" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 2, 109 | "id": "45a71fcc", 110 | "metadata": {}, 111 | "outputs": [ 112 | { 113 | "name": "stdout", 114 | "output_type": "stream", 115 | "text": [ 116 | "15\n" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "def recursive_sum(arr, n):\n", 122 | " if n == 0:\n", 123 | " return 0 # Base case: When there are no elements to add, return 0\n", 124 | " else:\n", 125 | " return arr[n - 1] + recursive_sum(arr, n - 1) # Recursive case: Add the last element and call with the rest\n", 126 | "\n", 127 | "# Example usage:\n", 128 | "my_array = [1, 2, 3, 4, 5]\n", 129 | "result = recursive_sum(my_array, len(my_array))\n", 130 | "print(result) " 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": null, 136 | "id": "ce3a6a41", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 2, 144 | "id": "0addb6dc", 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "name": "stdout", 149 | "output_type": "stream", 150 | "text": [ 151 | "15\n" 152 | ] 153 | } 154 | ], 155 | "source": [ 156 | "def iterative_sum(arr):\n", 157 | " sum_result = 0\n", 158 | " for num in arr:\n", 159 | " sum_result = sum_result + num\n", 160 | " return sum_result\n", 161 | "\n", 162 | "# Example usage:\n", 163 | "my_array = [1, 2, 3, 4, 5]\n", 164 | "result = iterative_sum(my_array)\n", 165 | "print(result) " 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "id": "5b46f3e3", 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "\n" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": null, 181 | "id": "0918d974", 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 3, 189 | "id": "e58bcfd4", 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "g1 = 60" 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": 4, 199 | "id": "c1342ba8", 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "60" 206 | ] 207 | }, 208 | "execution_count": 4, 209 | "metadata": {}, 210 | "output_type": "execute_result" 211 | } 212 | ], 213 | "source": [ 214 | "g1 " 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 17, 220 | "id": "a6f4b3a6", 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [ 224 | "def fun():\n", 225 | " global g1\n", 226 | " g1 = 50\n", 227 | " print(\"g1: \", g1)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 18, 233 | "id": "e53dd1ea", 234 | "metadata": {}, 235 | "outputs": [ 236 | { 237 | "data": { 238 | "text/plain": [ 239 | "60" 240 | ] 241 | }, 242 | "execution_count": 18, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "g1" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 19, 254 | "id": "4480f7f3", 255 | "metadata": {}, 256 | "outputs": [ 257 | { 258 | "name": "stdout", 259 | "output_type": "stream", 260 | "text": [ 261 | "g1: 50\n" 262 | ] 263 | } 264 | ], 265 | "source": [ 266 | "fun()" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 20, 272 | "id": "ff6ab158", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "data": { 277 | "text/plain": [ 278 | "50" 279 | ] 280 | }, 281 | "execution_count": 20, 282 | "metadata": {}, 283 | "output_type": "execute_result" 284 | } 285 | ], 286 | "source": [ 287 | "g1" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": null, 293 | "id": "706b0c99", 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": null, 301 | "id": "6ae875d3", 302 | "metadata": {}, 303 | "outputs": [], 304 | "source": [] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "execution_count": null, 309 | "id": "d6ba4e08", 310 | "metadata": {}, 311 | "outputs": [], 312 | "source": [] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": null, 317 | "id": "449005b1", 318 | "metadata": {}, 319 | "outputs": [], 320 | "source": [] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": null, 325 | "id": "cdf71c9f", 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": null, 333 | "id": "35b34074", 334 | "metadata": {}, 335 | "outputs": [], 336 | "source": [] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": null, 341 | "id": "c07e3339", 342 | "metadata": {}, 343 | "outputs": [], 344 | "source": [] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": null, 349 | "id": "cf347818", 350 | "metadata": {}, 351 | "outputs": [], 352 | "source": [] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": null, 357 | "id": "6f0822e4", 358 | "metadata": {}, 359 | "outputs": [], 360 | "source": [] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 10, 365 | "id": "9150c5d0", 366 | "metadata": {}, 367 | "outputs": [], 368 | "source": [ 369 | "def global_variable():\n", 370 | " c1 = 10 # local variable\n", 371 | " print(\"c1 : \", c1+10)" 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": 11, 377 | "id": "85a6b083", 378 | "metadata": {}, 379 | "outputs": [ 380 | { 381 | "ename": "NameError", 382 | "evalue": "name 'c1' is not defined", 383 | "output_type": "error", 384 | "traceback": [ 385 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 386 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 387 | "Cell \u001b[0;32mIn[11], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mc1\u001b[49m\n", 388 | "\u001b[0;31mNameError\u001b[0m: name 'c1' is not defined" 389 | ] 390 | } 391 | ], 392 | "source": [ 393 | "c1" 394 | ] 395 | }, 396 | { 397 | "cell_type": "code", 398 | "execution_count": 12, 399 | "id": "009f415c", 400 | "metadata": {}, 401 | "outputs": [ 402 | { 403 | "name": "stdout", 404 | "output_type": "stream", 405 | "text": [ 406 | "c1 : 20\n" 407 | ] 408 | } 409 | ], 410 | "source": [ 411 | "global_variable()" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": null, 417 | "id": "ed2cc8cf", 418 | "metadata": {}, 419 | "outputs": [], 420 | "source": [] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": null, 425 | "id": "151edf60", 426 | "metadata": {}, 427 | "outputs": [], 428 | "source": [ 429 | "def fun():\n", 430 | " " 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": null, 436 | "id": "611176c6", 437 | "metadata": {}, 438 | "outputs": [], 439 | "source": [] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "id": "93f67184", 445 | "metadata": {}, 446 | "outputs": [], 447 | "source": [] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": null, 452 | "id": "3a7153a8", 453 | "metadata": {}, 454 | "outputs": [], 455 | "source": [] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": null, 460 | "id": "bb600a90", 461 | "metadata": {}, 462 | "outputs": [], 463 | "source": [] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": null, 468 | "id": "4c22f8a9", 469 | "metadata": {}, 470 | "outputs": [], 471 | "source": [] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": null, 476 | "id": "0a7cf5ba", 477 | "metadata": {}, 478 | "outputs": [], 479 | "source": [] 480 | }, 481 | { 482 | "cell_type": "code", 483 | "execution_count": null, 484 | "id": "2def8caf", 485 | "metadata": {}, 486 | "outputs": [], 487 | "source": [] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": null, 492 | "id": "9113bdf0", 493 | "metadata": {}, 494 | "outputs": [], 495 | "source": [] 496 | }, 497 | { 498 | "cell_type": "code", 499 | "execution_count": null, 500 | "id": "088229b4", 501 | "metadata": {}, 502 | "outputs": [], 503 | "source": [] 504 | }, 505 | { 506 | "cell_type": "markdown", 507 | "id": "657ae2e2", 508 | "metadata": {}, 509 | "source": [ 510 | "## Disadvantages of Recursion" 511 | ] 512 | }, 513 | { 514 | "cell_type": "markdown", 515 | "id": "53f506c1", 516 | "metadata": {}, 517 | "source": [ 518 | "- **Stack Overflow** : Recursive solutions can lead to stack overflow errors if the recursion depth becomes too large.\n", 519 | "- This happens when there are too many nested function calls, and the call stack exceeds its allocated memory." 520 | ] 521 | }, 522 | { 523 | "cell_type": "code", 524 | "execution_count": 21, 525 | "id": "d1e72cf3", 526 | "metadata": { 527 | "scrolled": true 528 | }, 529 | "outputs": [ 530 | { 531 | "ename": "RecursionError", 532 | "evalue": "maximum recursion depth exceeded in comparison", 533 | "output_type": "error", 534 | "traceback": [ 535 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 536 | "\u001b[0;31mRecursionError\u001b[0m Traceback (most recent call last)", 537 | "Cell \u001b[0;32mIn[21], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mfactorial\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m10000\u001b[39;49m\u001b[43m)\u001b[49m\n", 538 | "Cell \u001b[0;32mIn[1], line 5\u001b[0m, in \u001b[0;36mfactorial\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m1\u001b[39m \u001b[38;5;66;03m# Base case: factorial(0) is 1\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m n \u001b[38;5;241m*\u001b[39m \u001b[43mfactorial\u001b[49m\u001b[43m(\u001b[49m\u001b[43mn\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n", 539 | "Cell \u001b[0;32mIn[1], line 5\u001b[0m, in \u001b[0;36mfactorial\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m1\u001b[39m \u001b[38;5;66;03m# Base case: factorial(0) is 1\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m n \u001b[38;5;241m*\u001b[39m \u001b[43mfactorial\u001b[49m\u001b[43m(\u001b[49m\u001b[43mn\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n", 540 | " \u001b[0;31m[... skipping similar frames: factorial at line 5 (2969 times)]\u001b[0m\n", 541 | "Cell \u001b[0;32mIn[1], line 5\u001b[0m, in \u001b[0;36mfactorial\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m1\u001b[39m \u001b[38;5;66;03m# Base case: factorial(0) is 1\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m n \u001b[38;5;241m*\u001b[39m \u001b[43mfactorial\u001b[49m\u001b[43m(\u001b[49m\u001b[43mn\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n", 542 | "Cell \u001b[0;32mIn[1], line 2\u001b[0m, in \u001b[0;36mfactorial\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfactorial\u001b[39m(n):\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mn\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m:\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m1\u001b[39m \u001b[38;5;66;03m# Base case: factorial(0) is 1\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", 543 | "\u001b[0;31mRecursionError\u001b[0m: maximum recursion depth exceeded in comparison" 544 | ] 545 | } 546 | ], 547 | "source": [ 548 | "factorial(10000)" 549 | ] 550 | }, 551 | { 552 | "cell_type": "markdown", 553 | "id": "4e0aed7d", 554 | "metadata": {}, 555 | "source": [ 556 | "- If you run this code with large_number = 10000, you will encounter a \n", 557 | " \n", 558 | " \"RecursionError: maximum recursion depth exceeded\" error. \n", 559 | " \n", 560 | " - This is because the recursive solution attempts to make too many nested function calls, and the call stack eventually exceeds its allocated memory, leading to a stack overflow error.\n", 561 | "\n", 562 | "- To avoid this error, you can use an iterative or tail-recursive approach for calculating the factorial of large numbers, as they do not involve excessive nested function calls and do not consume additional stack space." 563 | ] 564 | }, 565 | { 566 | "cell_type": "code", 567 | "execution_count": 23, 568 | "id": "eb5fee6d", 569 | "metadata": {}, 570 | "outputs": [], 571 | "source": [ 572 | "import time" 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": 29, 578 | "id": "cabef36a", 579 | "metadata": {}, 580 | "outputs": [ 581 | { 582 | "name": "stdout", 583 | "output_type": "stream", 584 | "text": [ 585 | "The time of execution of this code is 3e-06 seconds\n", 586 | "120\n" 587 | ] 588 | } 589 | ], 590 | "source": [ 591 | "def factorial_iterative(n):\n", 592 | " start_time = time.time()\n", 593 | " if n < 0:\n", 594 | " return None # Factorial is not defined for negative numbers\n", 595 | "\n", 596 | " result = 1\n", 597 | " for i in range(1, n + 1):\n", 598 | " result *= i\n", 599 | " \n", 600 | " end_time = time.time()\n", 601 | " print(\"The time of execution of this code is {} seconds\".format(round(end_time-start_time,6)))\n", 602 | "\n", 603 | " return result\n", 604 | "\n", 605 | "# Example usage:\n", 606 | "result = factorial_iterative(5)\n", 607 | "print(result) " 608 | ] 609 | }, 610 | { 611 | "cell_type": "markdown", 612 | "id": "39da9153", 613 | "metadata": {}, 614 | "source": [ 615 | "- **Performance Overhead** : Recursive solutions can sometimes be less efficient than iterative solutions due to the overhead of maintaining the call stack and making repeated function calls." 616 | ] 617 | }, 618 | { 619 | "cell_type": "code", 620 | "execution_count": 22, 621 | "id": "404705df", 622 | "metadata": {}, 623 | "outputs": [ 624 | { 625 | "name": "stdout", 626 | "output_type": "stream", 627 | "text": [ 628 | "The 30th Fibonacci number is: 832040\n", 629 | "The time of execution of this code is 0.17975902557373047 seconds\n" 630 | ] 631 | } 632 | ], 633 | "source": [ 634 | "def fibonacci_recursive(n):\n", 635 | " if n <= 0:\n", 636 | " return None # Error handling for non-positive integers\n", 637 | " elif n == 1 or n == 2:\n", 638 | " return 1 # Base case: Fibonacci of 1 or 2 is 1\n", 639 | " else:\n", 640 | " \n", 641 | " return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2) # Recursive case\n", 642 | "\n", 643 | "# Example usage:\n", 644 | "n = 30\n", 645 | "start_time = time.time()\n", 646 | "result = fibonacci_recursive(n)\n", 647 | "end_time = time.time()\n", 648 | "print(f\"The {n}th Fibonacci number is: {result}\")\n", 649 | "print(\"The time of execution of this code is {} seconds\".format(end_time-start_time))" 650 | ] 651 | }, 652 | { 653 | "cell_type": "markdown", 654 | "id": "455b899a", 655 | "metadata": {}, 656 | "source": [ 657 | "###### Iterative approach" 658 | ] 659 | }, 660 | { 661 | "cell_type": "code", 662 | "execution_count": 34, 663 | "id": "73a6e4ef", 664 | "metadata": {}, 665 | "outputs": [ 666 | { 667 | "name": "stdout", 668 | "output_type": "stream", 669 | "text": [ 670 | "The 30th Fibonacci number is: 832040\n", 671 | "Execution time for iterative solution: 0.000072 seconds\n" 672 | ] 673 | } 674 | ], 675 | "source": [ 676 | "import time\n", 677 | "\n", 678 | "def fibonacci_iterative(n):\n", 679 | " if n <= 0:\n", 680 | " return None # Error handling for non-positive integers\n", 681 | "\n", 682 | " if n == 1 or n == 2:\n", 683 | " return 1 # Base case: Fibonacci of 1 or 2 is 1\n", 684 | "\n", 685 | " # Initialize variables for the first two Fibonacci numbers\n", 686 | " prev, curr = 1, 1\n", 687 | "\n", 688 | " for _ in range(n - 2): # Iterate n-2 times to calculate the nth Fibonacci number\n", 689 | " prev, curr = curr, prev + curr\n", 690 | "\n", 691 | " return curr\n", 692 | "\n", 693 | "# Example usage with execution time measurement:\n", 694 | "n = 30\n", 695 | "\n", 696 | "start_time = time.time()\n", 697 | "result = fibonacci_iterative(n)\n", 698 | "end_time = time.time()\n", 699 | "\n", 700 | "print(f\"The {n}th Fibonacci number is: {result}\")\n", 701 | "print(f\"Execution time for iterative solution: {end_time - start_time:.6f} seconds\")" 702 | ] 703 | }, 704 | { 705 | "cell_type": "code", 706 | "execution_count": null, 707 | "id": "90e91564", 708 | "metadata": {}, 709 | "outputs": [], 710 | "source": [] 711 | }, 712 | { 713 | "cell_type": "code", 714 | "execution_count": null, 715 | "id": "c421914b", 716 | "metadata": {}, 717 | "outputs": [], 718 | "source": [] 719 | }, 720 | { 721 | "cell_type": "code", 722 | "execution_count": null, 723 | "id": "b938254e", 724 | "metadata": {}, 725 | "outputs": [], 726 | "source": [] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": null, 731 | "id": "b5079e64", 732 | "metadata": {}, 733 | "outputs": [], 734 | "source": [] 735 | }, 736 | { 737 | "cell_type": "code", 738 | "execution_count": null, 739 | "id": "9a350907", 740 | "metadata": {}, 741 | "outputs": [], 742 | "source": [] 743 | }, 744 | { 745 | "cell_type": "code", 746 | "execution_count": null, 747 | "id": "bde1bd1b", 748 | "metadata": {}, 749 | "outputs": [], 750 | "source": [] 751 | }, 752 | { 753 | "cell_type": "code", 754 | "execution_count": null, 755 | "id": "a172fac8", 756 | "metadata": {}, 757 | "outputs": [], 758 | "source": [] 759 | }, 760 | { 761 | "cell_type": "code", 762 | "execution_count": null, 763 | "id": "d0e337c5", 764 | "metadata": {}, 765 | "outputs": [], 766 | "source": [] 767 | }, 768 | { 769 | "cell_type": "code", 770 | "execution_count": null, 771 | "id": "329eb922", 772 | "metadata": {}, 773 | "outputs": [], 774 | "source": [] 775 | }, 776 | { 777 | "cell_type": "code", 778 | "execution_count": null, 779 | "id": "7f53d705", 780 | "metadata": {}, 781 | "outputs": [], 782 | "source": [] 783 | }, 784 | { 785 | "cell_type": "markdown", 786 | "id": "cd57640d", 787 | "metadata": {}, 788 | "source": [ 789 | "- **Difficult Debugging** : Recursive code can be more challenging to debug than iterative code because the flow of execution is less linear and may involve multiple levels of function calls." 790 | ] 791 | }, 792 | { 793 | "cell_type": "markdown", 794 | "id": "928ab3c3", 795 | "metadata": {}, 796 | "source": [ 797 | "- **Time and Space Complexity** : Recursive algorithms can result in higher time and space complexity than iterative solutions for some problems." 798 | ] 799 | }, 800 | { 801 | "cell_type": "code", 802 | "execution_count": null, 803 | "id": "84628de1", 804 | "metadata": {}, 805 | "outputs": [], 806 | "source": [] 807 | }, 808 | { 809 | "cell_type": "code", 810 | "execution_count": null, 811 | "id": "074142e0", 812 | "metadata": {}, 813 | "outputs": [], 814 | "source": [] 815 | }, 816 | { 817 | "cell_type": "code", 818 | "execution_count": null, 819 | "id": "83a4c976", 820 | "metadata": {}, 821 | "outputs": [], 822 | "source": [] 823 | }, 824 | { 825 | "cell_type": "code", 826 | "execution_count": null, 827 | "id": "ed79b36a", 828 | "metadata": {}, 829 | "outputs": [], 830 | "source": [] 831 | }, 832 | { 833 | "cell_type": "code", 834 | "execution_count": null, 835 | "id": "14615452", 836 | "metadata": {}, 837 | "outputs": [], 838 | "source": [] 839 | }, 840 | { 841 | "cell_type": "code", 842 | "execution_count": null, 843 | "id": "7f248ac1", 844 | "metadata": {}, 845 | "outputs": [], 846 | "source": [] 847 | }, 848 | { 849 | "cell_type": "code", 850 | "execution_count": null, 851 | "id": "1f8f95cb", 852 | "metadata": {}, 853 | "outputs": [], 854 | "source": [] 855 | }, 856 | { 857 | "cell_type": "code", 858 | "execution_count": null, 859 | "id": "6ca03a52", 860 | "metadata": {}, 861 | "outputs": [], 862 | "source": [] 863 | }, 864 | { 865 | "cell_type": "code", 866 | "execution_count": null, 867 | "id": "c543d0f8", 868 | "metadata": {}, 869 | "outputs": [], 870 | "source": [] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": null, 875 | "id": "4cf4e353", 876 | "metadata": {}, 877 | "outputs": [], 878 | "source": [] 879 | }, 880 | { 881 | "cell_type": "code", 882 | "execution_count": null, 883 | "id": "268a1350", 884 | "metadata": {}, 885 | "outputs": [], 886 | "source": [] 887 | }, 888 | { 889 | "cell_type": "code", 890 | "execution_count": null, 891 | "id": "62aac3b0", 892 | "metadata": {}, 893 | "outputs": [], 894 | "source": [] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "execution_count": null, 899 | "id": "cf99443b", 900 | "metadata": {}, 901 | "outputs": [], 902 | "source": [] 903 | }, 904 | { 905 | "cell_type": "code", 906 | "execution_count": null, 907 | "id": "e7ea5cf4", 908 | "metadata": {}, 909 | "outputs": [], 910 | "source": [] 911 | }, 912 | { 913 | "cell_type": "code", 914 | "execution_count": null, 915 | "id": "8b50ac5f", 916 | "metadata": {}, 917 | "outputs": [], 918 | "source": [] 919 | }, 920 | { 921 | "cell_type": "code", 922 | "execution_count": null, 923 | "id": "aecb0df4", 924 | "metadata": {}, 925 | "outputs": [], 926 | "source": [] 927 | } 928 | ], 929 | "metadata": { 930 | "kernelspec": { 931 | "display_name": "Python 3 (ipykernel)", 932 | "language": "python", 933 | "name": "python3" 934 | }, 935 | "language_info": { 936 | "codemirror_mode": { 937 | "name": "ipython", 938 | "version": 3 939 | }, 940 | "file_extension": ".py", 941 | "mimetype": "text/x-python", 942 | "name": "python", 943 | "nbconvert_exporter": "python", 944 | "pygments_lexer": "ipython3", 945 | "version": "3.9.16" 946 | }, 947 | "vp": { 948 | "vp_config_version": "1.0.0", 949 | "vp_menu_width": 273, 950 | "vp_note_display": false, 951 | "vp_note_width": 0, 952 | "vp_position": { 953 | "width": 278 954 | }, 955 | "vp_section_display": false, 956 | "vp_signature": "VisualPython" 957 | } 958 | }, 959 | "nbformat": 4, 960 | "nbformat_minor": 5 961 | } 962 | -------------------------------------------------------------------------------- /SVM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/SVM.pdf -------------------------------------------------------------------------------- /Statistics.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Statistics.zip -------------------------------------------------------------------------------- /String formating.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "c53517ad", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "a= 3" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "id": "14f0c329", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "data": { 21 | "text/plain": [ 22 | "int" 23 | ] 24 | }, 25 | "execution_count": 2, 26 | "metadata": {}, 27 | "output_type": "execute_result" 28 | } 29 | ], 30 | "source": [ 31 | "type(3)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 3, 37 | "id": "75613952", 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "b = 3.0" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 4, 47 | "id": "f20f5f28", 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "float" 54 | ] 55 | }, 56 | "execution_count": 4, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "type(b)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 5, 68 | "id": "6ed232e5", 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "c = \"3\"" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 6, 78 | "id": "f67befd8", 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "data": { 83 | "text/plain": [ 84 | "str" 85 | ] 86 | }, 87 | "execution_count": 6, 88 | "metadata": {}, 89 | "output_type": "execute_result" 90 | } 91 | ], 92 | "source": [ 93 | "type(c)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 7, 99 | "id": "3189235f", 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "d = \"3.0\"" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 8, 109 | "id": "a1fe2706", 110 | "metadata": {}, 111 | "outputs": [ 112 | { 113 | "data": { 114 | "text/plain": [ 115 | "str" 116 | ] 117 | }, 118 | "execution_count": 8, 119 | "metadata": {}, 120 | "output_type": "execute_result" 121 | } 122 | ], 123 | "source": [ 124 | "type(d)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "id": "8e7bc4bb", 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "set, dict, list, tuple" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 9, 140 | "id": "7e99a17c", 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "sets = {2,3,2,34,234,5,6}" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 10, 150 | "id": "4e800406", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "set" 157 | ] 158 | }, 159 | "execution_count": 10, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "type(sets)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 11, 171 | "id": "b283bea6", 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "dictionary = {\"name\":['Aman','Arun'], \n", 176 | " \"Place\": ['goa', 'Mumbai']}" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 12, 182 | "id": "f105bdc0", 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "data": { 187 | "text/plain": [ 188 | "dict" 189 | ] 190 | }, 191 | "execution_count": 12, 192 | "metadata": {}, 193 | "output_type": "execute_result" 194 | } 195 | ], 196 | "source": [ 197 | "type(dictionary)" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "id": "97bd1bbb", 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 13, 211 | "id": "9ae95c5a", 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "p = [2,3,4,5,6,7]" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 14, 221 | "id": "05989a2f", 222 | "metadata": {}, 223 | "outputs": [ 224 | { 225 | "data": { 226 | "text/plain": [ 227 | "list" 228 | ] 229 | }, 230 | "execution_count": 14, 231 | "metadata": {}, 232 | "output_type": "execute_result" 233 | } 234 | ], 235 | "source": [ 236 | "type(p)" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 15, 242 | "id": "6c366b4e", 243 | "metadata": {}, 244 | "outputs": [], 245 | "source": [ 246 | "q = (1,2,3,4,5,6)" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 16, 252 | "id": "43eb176b", 253 | "metadata": {}, 254 | "outputs": [ 255 | { 256 | "data": { 257 | "text/plain": [ 258 | "tuple" 259 | ] 260 | }, 261 | "execution_count": 16, 262 | "metadata": {}, 263 | "output_type": "execute_result" 264 | } 265 | ], 266 | "source": [ 267 | "type(q)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "id": "b0262a6a", 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "id": "179207c3", 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [ 285 | "Hackerrank.com ===> register yourself as a developer\n", 286 | "python" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "id": "1cff9f1b", 293 | "metadata": {}, 294 | "outputs": [], 295 | "source": [] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "id": "8faa0163", 301 | "metadata": {}, 302 | "outputs": [], 303 | "source": [] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": null, 308 | "id": "35dce3a6", 309 | "metadata": {}, 310 | "outputs": [], 311 | "source": [] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "id": "657c47c2", 316 | "metadata": {}, 317 | "source": [ 318 | "- String formatting in Python allows you to create formatted strings by inserting values into a placeholder within a string.\n", 319 | "- There are multiple ways to achieve string formatting in Python." 320 | ] 321 | }, 322 | { 323 | "cell_type": "markdown", 324 | "id": "a4878bf7", 325 | "metadata": {}, 326 | "source": [ 327 | "- Here are some common methods:" 328 | ] 329 | }, 330 | { 331 | "cell_type": "markdown", 332 | "id": "dea773e9", 333 | "metadata": {}, 334 | "source": [ 335 | "### Using % Operator (Old Style Formatting):\n" 336 | ] 337 | }, 338 | { 339 | "cell_type": "markdown", 340 | "id": "85e2e129", 341 | "metadata": {}, 342 | "source": [ 343 | "- The % operator is the older method of string formatting in Python. \n", 344 | "- It uses placeholders with % followed by format specifiers to indicate the type of values to be inserted into the string." 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": 18, 350 | "id": "d948ac1c", 351 | "metadata": {}, 352 | "outputs": [ 353 | { 354 | "name": "stdout", 355 | "output_type": "stream", 356 | "text": [ 357 | "My name is John, and I am 30 years old.\n" 358 | ] 359 | } 360 | ], 361 | "source": [ 362 | "name = \"John\"\n", 363 | "age = 30\n", 364 | "name_2 = \"Rohit\"\n", 365 | "age_2 = 20\n", 366 | "formatted_string = \"My name is %s, and I am %d years old.\" % (name, age)\n", 367 | "print(formatted_string)" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 19, 373 | "id": "c75605fd", 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "'My name is Rohit, and I am 20 years old.'" 380 | ] 381 | }, 382 | "execution_count": 19, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "\"My name is %s, and I am %d years old.\" % (name_2, age_2)" 389 | ] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "execution_count": 20, 394 | "id": "405740c0", 395 | "metadata": {}, 396 | "outputs": [], 397 | "source": [ 398 | "name_3 = \"George\"\n", 399 | "name_4 = \"Paul\"" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 21, 405 | "id": "52b457e0", 406 | "metadata": {}, 407 | "outputs": [ 408 | { 409 | "data": { 410 | "text/plain": [ 411 | "'My first name is George and my last name is Paul'" 412 | ] 413 | }, 414 | "execution_count": 21, 415 | "metadata": {}, 416 | "output_type": "execute_result" 417 | } 418 | ], 419 | "source": [ 420 | "\"My first name is %s and my last name is %s\"%(name_3, name_4) " 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": null, 426 | "id": "6bacf97c", 427 | "metadata": {}, 428 | "outputs": [], 429 | "source": [] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "id": "ec097756", 434 | "metadata": {}, 435 | "source": [ 436 | "### Using .format() Method (New Style Formatting):\n" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 2, 442 | "id": "d260d46e", 443 | "metadata": {}, 444 | "outputs": [ 445 | { 446 | "name": "stdout", 447 | "output_type": "stream", 448 | "text": [ 449 | "My name is John, and I am 30 years old.\n" 450 | ] 451 | } 452 | ], 453 | "source": [ 454 | "name = \"John\"\n", 455 | "age = 30\n", 456 | "formatted_string = \"My name is {}, and I am {} years old.\".format(name, age)\n", 457 | "print(formatted_string)" 458 | ] 459 | }, 460 | { 461 | "cell_type": "markdown", 462 | "id": "90fe52fe", 463 | "metadata": {}, 464 | "source": [ 465 | "**You can also place the positional placeholders for more clarity**" 466 | ] 467 | }, 468 | { 469 | "cell_type": "code", 470 | "execution_count": 22, 471 | "id": "b9e84d0b", 472 | "metadata": {}, 473 | "outputs": [ 474 | { 475 | "name": "stdout", 476 | "output_type": "stream", 477 | "text": [ 478 | "My name is John, and I am 30 years old. Hi John!\n" 479 | ] 480 | } 481 | ], 482 | "source": [ 483 | "name = \"John\"\n", 484 | "age = 30\n", 485 | "formatted_string = \"My name is {0}, and I am {1} years old. Hi {0}!\".format(name, age)\n", 486 | "print(formatted_string)" 487 | ] 488 | }, 489 | { 490 | "cell_type": "markdown", 491 | "id": "fb25ea1e", 492 | "metadata": {}, 493 | "source": [ 494 | "### Using f-strings (Python 3.6+):\n" 495 | ] 496 | }, 497 | { 498 | "cell_type": "markdown", 499 | "id": "922ff692", 500 | "metadata": {}, 501 | "source": [ 502 | "- f-strings are an even more convenient and readable method of string formatting introduced in Python 3.6. \n", 503 | "- They allow you to directly embed expressions inside curly braces {} within the string." 504 | ] 505 | }, 506 | { 507 | "cell_type": "code", 508 | "execution_count": 23, 509 | "id": "444ce54e", 510 | "metadata": {}, 511 | "outputs": [ 512 | { 513 | "name": "stdout", 514 | "output_type": "stream", 515 | "text": [ 516 | "My name is John, and I am 30 years old.\n" 517 | ] 518 | } 519 | ], 520 | "source": [ 521 | "name = \"John\"\n", 522 | "age = 30\n", 523 | "formatted_string = f\"My name is {name}, and I am {age} years old.\"\n", 524 | "print(formatted_string)" 525 | ] 526 | }, 527 | { 528 | "cell_type": "code", 529 | "execution_count": 24, 530 | "id": "b4eff05d", 531 | "metadata": {}, 532 | "outputs": [ 533 | { 534 | "name": "stdout", 535 | "output_type": "stream", 536 | "text": [ 537 | "my name is John and I am 30 years old\n" 538 | ] 539 | } 540 | ], 541 | "source": [ 542 | "print(f\"my name is {name} and I am {age} years old\")" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": null, 548 | "id": "7c303ecf", 549 | "metadata": {}, 550 | "outputs": [], 551 | "source": [] 552 | }, 553 | { 554 | "cell_type": "code", 555 | "execution_count": 25, 556 | "id": "564aeaa5", 557 | "metadata": {}, 558 | "outputs": [], 559 | "source": [ 560 | "def sum_all(a,b,c):\n", 561 | " add = a+b+c\n", 562 | " print(f\"the number are a : {a}, b: {b} and c : {c} and the sum of the numbers is {add}\")" 563 | ] 564 | }, 565 | { 566 | "cell_type": "code", 567 | "execution_count": 26, 568 | "id": "d5274ed8", 569 | "metadata": {}, 570 | "outputs": [ 571 | { 572 | "name": "stdout", 573 | "output_type": "stream", 574 | "text": [ 575 | "the number are a : 2, b: 3 and c : 4 and the sum of the numbers is 9\n" 576 | ] 577 | } 578 | ], 579 | "source": [ 580 | "sum_all(2,3,4)" 581 | ] 582 | }, 583 | { 584 | "cell_type": "code", 585 | "execution_count": null, 586 | "id": "a50c75f2", 587 | "metadata": {}, 588 | "outputs": [], 589 | "source": [] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": null, 594 | "id": "82cc3d7d", 595 | "metadata": {}, 596 | "outputs": [], 597 | "source": [] 598 | }, 599 | { 600 | "cell_type": "code", 601 | "execution_count": null, 602 | "id": "473864a4", 603 | "metadata": {}, 604 | "outputs": [], 605 | "source": [] 606 | } 607 | ], 608 | "metadata": { 609 | "kernelspec": { 610 | "display_name": "Python 3 (ipykernel)", 611 | "language": "python", 612 | "name": "python3" 613 | }, 614 | "language_info": { 615 | "codemirror_mode": { 616 | "name": "ipython", 617 | "version": 3 618 | }, 619 | "file_extension": ".py", 620 | "mimetype": "text/x-python", 621 | "name": "python", 622 | "nbconvert_exporter": "python", 623 | "pygments_lexer": "ipython3", 624 | "version": "3.9.16" 625 | }, 626 | "vp": { 627 | "vp_config_version": "1.0.0", 628 | "vp_menu_width": 273, 629 | "vp_note_display": false, 630 | "vp_note_width": 0, 631 | "vp_position": { 632 | "width": 278 633 | }, 634 | "vp_section_display": false, 635 | "vp_signature": "VisualPython" 636 | } 637 | }, 638 | "nbformat": 4, 639 | "nbformat_minor": 5 640 | } 641 | -------------------------------------------------------------------------------- /Visualization.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/Visualization.zip -------------------------------------------------------------------------------- /mytree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/mytree.png -------------------------------------------------------------------------------- /tree_pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/training-ml/Theory-Notes/9eb918c742f985a35708e82dfb93dba466aff69c/tree_pt.png -------------------------------------------------------------------------------- /weights.csv: -------------------------------------------------------------------------------- 1 | Person Height(in metres),Person Favorite Colour,Person Gender,Person Weight (in Kg) 2 | 1.6,Blue,Male,88 3 | 1.6,Green,Female,76 4 | 1.5,Blue,Female,56 5 | 1.8,Red,Male,73 6 | 1.5,Green,Male,77 7 | 1.4,Blue,Female,57 8 | --------------------------------------------------------------------------------