├── Advertisements-Data.csv ├── Age,_Gender_and_Race_Prediction.ipynb ├── Auto_Apply_for_Job_with_AI.ipynb ├── BLack Minimalist Corporate Staff Identity LinkedIn Banner.png ├── Build_a_simple_image_classifier.ipynb ├── Build_and_deploy_your_first_machine_learning_web_app.ipynb ├── Building_a_Real_Time_Emotion_Detection_with_Python.ipynb ├── Computer Vision ├── Building_a_Real_Time_Emotion_Detection_with_Python.ipynb ├── Driver_Drowsiness_Detection_System_with_OpenCV_&_Keras( not completed).ipynb ├── Face_Detection.ipynb ├── Gender and Age Detection Python │ ├── Gender_and_Age_Detection_Python_Project_(1).ipynb │ └── readme ├── Human_Activity_Recognition.ipynb ├── Real_Time_Face_Mask_Detector_(Not_Completed)_.ipynb └── readme ├── Convert_Color_Image_to_Sketchipynb.ipynb ├── DL ├── TableofContent.md └── readme.md ├── Datasets ├── cars.jpeg ├── readme └── student-mat.csv ├── Detecting_Sports_Content_with_Machine_Learning".ipynb ├── Emotion_Detection_in_Text.ipynb ├── File_organizer.ipynb ├── Freelancer ├── AI problems (5).pdf ├── AI_Assigment.ipynb └── Read ├── Hate_Speech_Detection_with_Machine_Learning(_Decsion_Tree)_(1).ipynb ├── Image_Data_Preprocessing.ipynb ├── Important_Python_script.ipynb ├── ML ├── Birth_Rate_Analysis.ipynb ├── Credit_Card_Fraud_Detection_DT_and_RF.ipynb ├── Data_Science_Project_on_Area_and_Population.ipynb ├── How_to_Save_a_Machine_Learning_Model.ipynb ├── Predict_IPL_Winner_with_ML.ipynb ├── President_Heights_exploratory_data.ipynb ├── Stock_Price_Prediction_using_Linear_Regression.ipynb └── read.md ├── Machine Learning End to End ├── Build_and_Deploy_Data_Science_Products_.ipynb ├── End_to_End_Fake_News_Detection_with_Python_(Naybaies_Streamlite).ipynb ├── End_to_End_Machine_Learning_Model.ipynb ├── radfd.md └── readmi.md ├── Model_Training_2.ipynb ├── Movie_Reviews_through_Sentiment_Analysis_in_NLP.ipynb ├── National Language processing ├── Chatbot_using_Python.ipynb ├── End_to_End_Spam_Detection_with_Python.ipynb ├── Fake_News_Classifier_using_Bidirectional_LSTM.ipynb ├── Feature_Extraction_Zernike_Moment.ipynb ├── Next_Word_Prediction.ipynb ├── POS Tagging for Multiple Languages.py ├── Readm.md ├── Spam_Detection_with_Machine_Learning.ipynb ├── Summarize_Text_with_Machine_Learning.ipynb └── Text_Classification.ipynb ├── Next_Word_Prediction_Model.ipynb ├── Plagiarism_checker_Python.ipynb ├── Predict_Ads_Click_–_Practice_Data_Analysis_and_Logistic_Regression_Prediction.ipynb ├── Projects (1) (1).png ├── QR_Code_Generation_using_Python.ipynb ├── README.md ├── Recommender System ├── Amazon_Recommendation_System_using_Python.ipynb ├── Content_Based_Filtering_in_Machine_Learning.ipynb ├── Movie_Recommender_9_26_2020.ipynb └── readme ├── Spam_Detection_using_Machine_Learning.ipynb ├── Stock_Price_Prediction.ipynb ├── Stress_Detection_with_Machine_Learning.ipynb ├── Text_Preprocessing.ipynb ├── Time Series Forecasting ├── Covid_19_Cases_Prediction_with_Python (1).ipynb ├── Time_Series_with_LSTM_in_Machine_Learning.ipynb └── readme ├── Tokenization_stemming_lemmatization_stopword_postagging.ipynb ├── Traffic_Sign_Classification_with_Keras_and_Deep_Learning.ipynb ├── chatbot_in_Healthcare.ipynb ├── emo.jfif ├── emo2.jpg ├── intentsnew (6).json ├── linkedIn_auto_jobs_applier_with_AI.ipynb └── stock_data.csv /Auto_Apply_for_Job_with_AI.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyOo3Os5DwheMRyxlAEq9VgD", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "id": "K4PvRdFA3Qdr" 34 | }, 35 | "outputs": [], 36 | "source": [] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "source": [ 41 | "# **References**" 42 | ], 43 | "metadata": { 44 | "id": "fS5uDTaj3YX8" 45 | } 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "source": [ 50 | "[LinkedIn_AIHawk](https://github.com/feder-cr/linkedIn_auto_jobs_applier_with_AI?tab=readme-ov-file)" 51 | ], 52 | "metadata": { 53 | "id": "P6PdFcnw3iiE" 54 | } 55 | } 56 | ] 57 | } -------------------------------------------------------------------------------- /BLack Minimalist Corporate Staff Identity LinkedIn Banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dr-mushtaq/Projects/28f8dc0e8a0500af4610121178b70b5efedb87ee/BLack Minimalist Corporate Staff Identity LinkedIn Banner.png -------------------------------------------------------------------------------- /Build_a_simple_image_classifier.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "toc_visible": true, 8 | "authorship_tag": "ABX9TyMO6oiaia/UwQAAJFFCeITX", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "id": "PKIk5iSfqvoS" 35 | }, 36 | "outputs": [], 37 | "source": [] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "source": [ 42 | "# **Table of Content**\n", 43 | "\n", 44 | "\n", 45 | "1. Introduction\n", 46 | "2. Import Libraries\n", 47 | "3. Load Dataset\n", 48 | "4. Hot Encoding\n", 49 | "5. Create Model\n", 50 | "5. Fit The model\n", 51 | "6. Improve Accuracy\n", 52 | "7. Source\n", 53 | "\n" 54 | ], 55 | "metadata": { 56 | "id": "UER8fSt13gBE" 57 | } 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "source": [ 62 | "# **Introduction**" 63 | ], 64 | "metadata": { 65 | "id": "2CngjLQ2rTtL" 66 | } 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "source": [ 71 | "This is a very simple fashion classifier.It uses a data set called \"fashion mnist\", a set of small b&w images of apparel This training script classifies with around 15% accuracy. See if you can get it to 80% accuracy by normalizing the input data andusing a softmax activation function." 72 | ], 73 | "metadata": { 74 | "id": "6L389pO6rQFr" 75 | } 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "source": [ 80 | "# **Import Libraries**" 81 | ], 82 | "metadata": { 83 | "id": "x11CA7ERrqih" 84 | } 85 | }, 86 | { 87 | "cell_type": "code", 88 | "source": [ 89 | "!pip install wandb" 90 | ], 91 | "metadata": { 92 | "id": "CB7UOUAksBpa" 93 | }, 94 | "execution_count": null, 95 | "outputs": [] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "source": [ 100 | "from tensorflow.keras.utils import to_categorical\n", 101 | "from tensorflow.keras.datasets import fashion_mnist\n", 102 | "from tensorflow.keras.models import Sequential\n", 103 | "from tensorflow.keras.layers import Dense, Flatten\n", 104 | "import wandb\n", 105 | "from wandb.keras import WandbCallback" 106 | ], 107 | "metadata": { 108 | "id": "F5YtpX3Pryqw" 109 | }, 110 | "execution_count": null, 111 | "outputs": [] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "source": [ 116 | "# **Load Dataset**" 117 | ], 118 | "metadata": { 119 | "id": "3VK1jGPdsH6A" 120 | } 121 | }, 122 | { 123 | "cell_type": "code", 124 | "source": [ 125 | "# load data\n", 126 | "(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()\n", 127 | "img_width = X_train.shape[1]\n", 128 | "img_height = X_train.shape[2]" 129 | ], 130 | "metadata": { 131 | "id": "9e1ES5jfsQLB" 132 | }, 133 | "execution_count": null, 134 | "outputs": [] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "source": [ 139 | "# **Hot encoding**" 140 | ], 141 | "metadata": { 142 | "id": "QBI8XJOcsh2E" 143 | } 144 | }, 145 | { 146 | "cell_type": "code", 147 | "source": [ 148 | "# one hot encode outputs\n", 149 | "y_train = to_categorical(y_train)\n", 150 | "y_test = to_categorical(y_test)\n", 151 | "labels = [\"T-shirt/top\", \"Trouser\", \"Pullover\", \"Dress\",\n", 152 | " \"Coat\", \"Sandal\", \"Shirt\", \"Sneaker\", \"Bag\", \"Ankle boot\"]\n" 153 | ], 154 | "metadata": { 155 | "id": "KCfBuwUdsp5J" 156 | }, 157 | "execution_count": null, 158 | "outputs": [] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "source": [ 163 | "num_classes = y_train.shape[1]" 164 | ], 165 | "metadata": { 166 | "id": "gctbDDzcs2Qo" 167 | }, 168 | "execution_count": null, 169 | "outputs": [] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "source": [ 174 | "# **Create model**" 175 | ], 176 | "metadata": { 177 | "id": "ODai5bROso_g" 178 | } 179 | }, 180 | { 181 | "cell_type": "code", 182 | "source": [ 183 | "# create model\n", 184 | "model = Sequential()\n", 185 | "model.add(Flatten(input_shape=(img_width, img_height)))\n", 186 | "model.add(Dense(num_classes))\n", 187 | "model.compile(loss='categorical_crossentropy', optimizer='adam',\n", 188 | " metrics=['accuracy'])" 189 | ], 190 | "metadata": { 191 | "id": "ePhA_hcttEZC" 192 | }, 193 | "execution_count": null, 194 | "outputs": [] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "source": [], 199 | "metadata": { 200 | "id": "7t5ZkviLtKE7" 201 | }, 202 | "execution_count": null, 203 | "outputs": [] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "source": [ 208 | "# **Fit the model**" 209 | ], 210 | "metadata": { 211 | "id": "I5NPht3vtLI4" 212 | } 213 | }, 214 | { 215 | "cell_type": "code", 216 | "source": [ 217 | "model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))\n" 218 | ], 219 | "metadata": { 220 | "id": "egRzmSM-wB2C" 221 | }, 222 | "execution_count": null, 223 | "outputs": [] 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "source": [ 228 | "# **Improve Accuracy**" 229 | ], 230 | "metadata": { 231 | "id": "WDHsJwSK4UKk" 232 | } 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "source": [ 237 | "## **import libraries**" 238 | ], 239 | "metadata": { 240 | "id": "nx68sNSo4bKM" 241 | } 242 | }, 243 | { 244 | "cell_type": "code", 245 | "source": [ 246 | "!pip install wandb" 247 | ], 248 | "metadata": { 249 | "colab": { 250 | "base_uri": "https://localhost:8080/" 251 | }, 252 | "id": "A8J7xasf5HQV", 253 | "outputId": "9e336796-fa07-4100-fbef-934f592af9a1" 254 | }, 255 | "execution_count": 2, 256 | "outputs": [ 257 | { 258 | "output_type": "stream", 259 | "name": "stdout", 260 | "text": [ 261 | "Collecting wandb\n", 262 | " Downloading wandb-0.16.6-py3-none-any.whl (2.2 MB)\n", 263 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m24.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 264 | "\u001b[?25hRequirement already satisfied: Click!=8.0.0,>=7.1 in /usr/local/lib/python3.10/dist-packages (from wandb) (8.1.7)\n", 265 | "Collecting GitPython!=3.1.29,>=1.0.0 (from wandb)\n", 266 | " Downloading GitPython-3.1.43-py3-none-any.whl (207 kB)\n", 267 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.3/207.3 kB\u001b[0m \u001b[31m22.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 268 | "\u001b[?25hRequirement already satisfied: requests<3,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from wandb) (2.31.0)\n", 269 | "Requirement already satisfied: psutil>=5.0.0 in /usr/local/lib/python3.10/dist-packages (from wandb) (5.9.5)\n", 270 | "Collecting sentry-sdk>=1.0.0 (from wandb)\n", 271 | " Downloading sentry_sdk-1.45.0-py2.py3-none-any.whl (267 kB)\n", 272 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m267.1/267.1 kB\u001b[0m \u001b[31m26.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 273 | "\u001b[?25hCollecting docker-pycreds>=0.4.0 (from wandb)\n", 274 | " Downloading docker_pycreds-0.4.0-py2.py3-none-any.whl (9.0 kB)\n", 275 | "Requirement already satisfied: PyYAML in /usr/local/lib/python3.10/dist-packages (from wandb) (6.0.1)\n", 276 | "Collecting setproctitle (from wandb)\n", 277 | " Downloading setproctitle-1.3.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (30 kB)\n", 278 | "Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from wandb) (67.7.2)\n", 279 | "Requirement already satisfied: appdirs>=1.4.3 in /usr/local/lib/python3.10/dist-packages (from wandb) (1.4.4)\n", 280 | "Requirement already satisfied: protobuf!=4.21.0,<5,>=3.19.0 in /usr/local/lib/python3.10/dist-packages (from wandb) (3.20.3)\n", 281 | "Requirement already satisfied: six>=1.4.0 in /usr/local/lib/python3.10/dist-packages (from docker-pycreds>=0.4.0->wandb) (1.16.0)\n", 282 | "Collecting gitdb<5,>=4.0.1 (from GitPython!=3.1.29,>=1.0.0->wandb)\n", 283 | " Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)\n", 284 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.7/62.7 kB\u001b[0m \u001b[31m8.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 285 | "\u001b[?25hRequirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.0.0->wandb) (3.3.2)\n", 286 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.0.0->wandb) (3.6)\n", 287 | "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.0.0->wandb) (2.0.7)\n", 288 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.0.0->wandb) (2024.2.2)\n", 289 | "Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->GitPython!=3.1.29,>=1.0.0->wandb)\n", 290 | " Downloading smmap-5.0.1-py3-none-any.whl (24 kB)\n", 291 | "Installing collected packages: smmap, setproctitle, sentry-sdk, docker-pycreds, gitdb, GitPython, wandb\n", 292 | "Successfully installed GitPython-3.1.43 docker-pycreds-0.4.0 gitdb-4.0.11 sentry-sdk-1.45.0 setproctitle-1.3.3 smmap-5.0.1 wandb-0.16.6\n" 293 | ] 294 | } 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "source": [ 300 | "from tensorflow.keras.utils import to_categorical\n", 301 | "from tensorflow.keras.datasets import fashion_mnist\n", 302 | "from tensorflow.keras.models import Sequential\n", 303 | "from tensorflow.keras.layers import Dense, Flatten\n", 304 | "import wandb" 305 | ], 306 | "metadata": { 307 | "id": "69tIHILD49W1" 308 | }, 309 | "execution_count": 3, 310 | "outputs": [] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "source": [ 315 | "## **Load Data**" 316 | ], 317 | "metadata": { 318 | "id": "05SuCJWj5h9F" 319 | } 320 | }, 321 | { 322 | "cell_type": "code", 323 | "source": [ 324 | "# load data\n", 325 | "(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()\n", 326 | "img_width = X_train.shape[1]\n", 327 | "img_height = X_train.shape[2]" 328 | ], 329 | "metadata": { 330 | "colab": { 331 | "base_uri": "https://localhost:8080/" 332 | }, 333 | "id": "Jytxfw-L5jRG", 334 | "outputId": "45374dda-4c1a-4e48-e564-68c2a71ab7d1" 335 | }, 336 | "execution_count": 4, 337 | "outputs": [ 338 | { 339 | "output_type": "stream", 340 | "name": "stdout", 341 | "text": [ 342 | "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz\n", 343 | "29515/29515 [==============================] - 0s 0us/step\n", 344 | "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz\n", 345 | "26421880/26421880 [==============================] - 0s 0us/step\n", 346 | "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz\n", 347 | "5148/5148 [==============================] - 0s 0us/step\n", 348 | "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz\n", 349 | "4422102/4422102 [==============================] - 0s 0us/step\n" 350 | ] 351 | } 352 | ] 353 | }, 354 | { 355 | "cell_type": "markdown", 356 | "source": [ 357 | "## **One hot encode outputs**" 358 | ], 359 | "metadata": { 360 | "id": "cIVXpWdh52TE" 361 | } 362 | }, 363 | { 364 | "cell_type": "code", 365 | "source": [ 366 | "y_train = to_categorical(y_train)\n", 367 | "y_test = to_categorical(y_test)\n", 368 | "labels = [\"T-shirt/top\", \"Trouser\", \"Pullover\", \"Dress\",\n", 369 | " \"Coat\", \"Sandal\", \"Shirt\", \"Sneaker\", \"Bag\", \"Ankle boot\"]" 370 | ], 371 | "metadata": { 372 | "id": "4xUxF5C75_k_" 373 | }, 374 | "execution_count": 5, 375 | "outputs": [] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "source": [ 380 | "X_train = X_train / 255.\n", 381 | "X_test = X_test / 255." 382 | ], 383 | "metadata": { 384 | "id": "MqgDtwyM6EbV" 385 | }, 386 | "execution_count": 6, 387 | "outputs": [] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "source": [ 392 | "num_classes = y_train.shape[1]" 393 | ], 394 | "metadata": { 395 | "id": "SmnTYC1g6H0u" 396 | }, 397 | "execution_count": 7, 398 | "outputs": [] 399 | }, 400 | { 401 | "cell_type": "markdown", 402 | "source": [ 403 | "## **Create model**" 404 | ], 405 | "metadata": { 406 | "id": "hDEoCJzM6O8M" 407 | } 408 | }, 409 | { 410 | "cell_type": "code", 411 | "source": [ 412 | "# create model\n", 413 | "model = Sequential()\n", 414 | "model.add(Flatten(input_shape=(img_width, img_height)))\n", 415 | "model.add(Dense(num_classes, activation=\"softmax\"))\n", 416 | "model.compile(loss='categorical_crossentropy', optimizer='adam',\n", 417 | " metrics=['accuracy'])" 418 | ], 419 | "metadata": { 420 | "id": "B4x2HvGu6MD8" 421 | }, 422 | "execution_count": 10, 423 | "outputs": [] 424 | }, 425 | { 426 | "cell_type": "markdown", 427 | "source": [ 428 | "## **Fit the model**" 429 | ], 430 | "metadata": { 431 | "id": "8-bVfBy46eF8" 432 | } 433 | }, 434 | { 435 | "cell_type": "code", 436 | "source": [ 437 | "model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))" 438 | ], 439 | "metadata": { 440 | "colab": { 441 | "base_uri": "https://localhost:8080/" 442 | }, 443 | "id": "3sDzCFf06obG", 444 | "outputId": "04bb2441-b547-43a3-8971-c84ff4be3ae6" 445 | }, 446 | "execution_count": 12, 447 | "outputs": [ 448 | { 449 | "output_type": "stream", 450 | "name": "stdout", 451 | "text": [ 452 | "Epoch 1/10\n", 453 | "1875/1875 [==============================] - 5s 2ms/step - loss: 0.5971 - accuracy: 0.7986 - val_loss: 0.5115 - val_accuracy: 0.8235\n", 454 | "Epoch 2/10\n", 455 | "1875/1875 [==============================] - 3s 2ms/step - loss: 0.4613 - accuracy: 0.8428 - val_loss: 0.5009 - val_accuracy: 0.8208\n", 456 | "Epoch 3/10\n", 457 | "1875/1875 [==============================] - 4s 2ms/step - loss: 0.4364 - accuracy: 0.8501 - val_loss: 0.4658 - val_accuracy: 0.8388\n", 458 | "Epoch 4/10\n", 459 | "1875/1875 [==============================] - 4s 2ms/step - loss: 0.4224 - accuracy: 0.8551 - val_loss: 0.4715 - val_accuracy: 0.8359\n", 460 | "Epoch 5/10\n", 461 | "1875/1875 [==============================] - 4s 2ms/step - loss: 0.4123 - accuracy: 0.8580 - val_loss: 0.4604 - val_accuracy: 0.8411\n", 462 | "Epoch 6/10\n", 463 | "1875/1875 [==============================] - 3s 2ms/step - loss: 0.4076 - accuracy: 0.8575 - val_loss: 0.4633 - val_accuracy: 0.8353\n", 464 | "Epoch 7/10\n", 465 | "1875/1875 [==============================] - 3s 2ms/step - loss: 0.4015 - accuracy: 0.8607 - val_loss: 0.4718 - val_accuracy: 0.8381\n", 466 | "Epoch 8/10\n", 467 | "1875/1875 [==============================] - 4s 2ms/step - loss: 0.3981 - accuracy: 0.8620 - val_loss: 0.4449 - val_accuracy: 0.8447\n", 468 | "Epoch 9/10\n", 469 | "1875/1875 [==============================] - 3s 2ms/step - loss: 0.3958 - accuracy: 0.8620 - val_loss: 0.4608 - val_accuracy: 0.8352\n", 470 | "Epoch 10/10\n", 471 | "1875/1875 [==============================] - 4s 2ms/step - loss: 0.3913 - accuracy: 0.8643 - val_loss: 0.4640 - val_accuracy: 0.8389\n" 472 | ] 473 | }, 474 | { 475 | "output_type": "execute_result", 476 | "data": { 477 | "text/plain": [ 478 | "" 479 | ] 480 | }, 481 | "metadata": {}, 482 | "execution_count": 12 483 | } 484 | ] 485 | }, 486 | { 487 | "cell_type": "markdown", 488 | "source": [ 489 | "# **Source**\n", 490 | "1- [Projects](https://github.com/lukas/ml-class)" 491 | ], 492 | "metadata": { 493 | "id": "B1ckuxnO0UJr" 494 | } 495 | } 496 | ] 497 | } -------------------------------------------------------------------------------- /Computer Vision/Gender and Age Detection Python/readme: -------------------------------------------------------------------------------- 1 | 2 | Gender and Age Detection Python Project 3 | https://data-flair.training/blogs/python-project-gender-age-detection/?fbclid=IwAR2YqS3yzlvQwqgkWuSjv4azyxkzSMamn97StQ0Vqm5KGy_7-2Sj4EoHVrI 4 | -------------------------------------------------------------------------------- /Computer Vision/Human_Activity_Recognition.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Human Activity Recognition.ipynb", 7 | "provenance": [], 8 | "toc_visible": true, 9 | "authorship_tag": "ABX9TyNUXpa9XSHvstZh4kvMW9BT", 10 | "include_colab_link": true 11 | }, 12 | "kernelspec": { 13 | "name": "python3", 14 | "display_name": "Python 3" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "id": "view-in-github", 22 | "colab_type": "text" 23 | }, 24 | "source": [ 25 | "\"Open" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "id": "5k4WRBaseTdn" 32 | }, 33 | "source": [ 34 | "#**1-Introduction**\n", 35 | "Human activity recognition is the problem of classifying sequences of data recorded by specialized harnesses or smart phones into known well-defined Human activities.[1]\n", 36 | "\n", 37 | "It is a challenging problem as the large number of observations are produced each second, the temporal nature of the observations, and the lack of a clear way to relate data to known movements increase the challenges.\n", 38 | "\n" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": { 44 | "id": "KM1lOZwhe0st" 45 | }, 46 | "source": [ 47 | "#**2-Importing necessary libraries**\n" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "metadata": { 53 | "id": "9XtT225Fe7gv", 54 | "outputId": "d5051e58-4a51-45be-80e0-e381a4be0af6", 55 | "colab": { 56 | "base_uri": "https://localhost:8080/", 57 | "height": 71 58 | } 59 | }, 60 | "source": [ 61 | "import pandas as pd\n", 62 | "import numpy as np\n", 63 | "import seaborn as sns\n", 64 | "import matplotlib.pyplot as plt\n", 65 | "%matplotlib inline\n", 66 | "import warnings\n", 67 | "warnings.filterwarnings(\"ignore\")" 68 | ], 69 | "execution_count": 1, 70 | "outputs": [ 71 | { 72 | "output_type": "stream", 73 | "text": [ 74 | "/usr/local/lib/python3.6/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.\n", 75 | " import pandas.util.testing as tm\n" 76 | ], 77 | "name": "stderr" 78 | } 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "id": "xSq-zDRqfWK5" 85 | }, 86 | "source": [ 87 | "#**3-Reading the data**" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "metadata": { 93 | "id": "VcqUC890fgbS", 94 | "outputId": "33aa3290-80ea-4fa8-d619-facb65e63e94", 95 | "colab": { 96 | "base_uri": "https://localhost:8080/", 97 | "height": 34 98 | } 99 | }, 100 | "source": [ 101 | "from google.colab import drive\n", 102 | "drive.mount('/content/drive')" 103 | ], 104 | "execution_count": 2, 105 | "outputs": [ 106 | { 107 | "output_type": "stream", 108 | "text": [ 109 | "Mounted at /content/drive\n" 110 | ], 111 | "name": "stdout" 112 | } 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "metadata": { 118 | "id": "JHq3cC7Tfeyu" 119 | }, 120 | "source": [ 121 | "train = pd.read_csv(\"/content/drive/My Drive/Datasets/Human Activity Recognition/train-1.csv\")\n", 122 | "test = pd.read_csv(\"/content/drive/My Drive/Datasets/Human Activity Recognition/test.csv\")" 123 | ], 124 | "execution_count": 3, 125 | "outputs": [] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "metadata": { 130 | "id": "_FdoawX66eFB" 131 | }, 132 | "source": [ 133 | "train.head()" 134 | ], 135 | "execution_count": null, 136 | "outputs": [] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "metadata": { 141 | "id": "fHzJ4ecc6m3g" 142 | }, 143 | "source": [ 144 | "train.shape, test.shape" 145 | ], 146 | "execution_count": null, 147 | "outputs": [] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": { 152 | "id": "wup0Ul0Q6NvB" 153 | }, 154 | "source": [ 155 | "#**4-To Combine both the data framemes**\n", 156 | "To Combine both the data frames\n", 157 | "\n", 158 | "\n" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "metadata": { 164 | "id": "b96SHjK-6YiB" 165 | }, 166 | "source": [ 167 | "train['Data'] = 'Train'\n", 168 | "test['Data'] = 'Test'\n", 169 | "both = pd.concat([train, test], axis=0).reset_index(drop=True)\n", 170 | "both['subject'] = '#' + both['subject'].astype(str)" 171 | ], 172 | "execution_count": 4, 173 | "outputs": [] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "metadata": { 178 | "id": "nZq3lA6u64ix" 179 | }, 180 | "source": [ 181 | "both.head()" 182 | ], 183 | "execution_count": null, 184 | "outputs": [] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "metadata": { 189 | "id": "x9v_GQGh6xrh", 190 | "outputId": "aea302ef-2cd5-42dd-9d3e-c1a9ecefcf2a", 191 | "colab": { 192 | "base_uri": "https://localhost:8080/", 193 | "height": 68 194 | } 195 | }, 196 | "source": [ 197 | "both.dtypes.value_counts()" 198 | ], 199 | "execution_count": 8, 200 | "outputs": [ 201 | { 202 | "output_type": "execute_result", 203 | "data": { 204 | "text/plain": [ 205 | "float64 561\n", 206 | "object 3\n", 207 | "dtype: int64" 208 | ] 209 | }, 210 | "metadata": { 211 | "tags": [] 212 | }, 213 | "execution_count": 8 214 | } 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "metadata": { 220 | "id": "YUci-bBi70uP" 221 | }, 222 | "source": [ 223 | "def basic_details(df):\n", 224 | " b = pd.DataFrame()\n", 225 | " b['Missing value'] = df.isnull().sum()\n", 226 | " b['N unique value'] = df.nunique()\n", 227 | " b['dtype'] = df.dtypes\n", 228 | " return b\n", 229 | "basic_details(both)" 230 | ], 231 | "execution_count": null, 232 | "outputs": [] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "metadata": { 237 | "id": "f5QMFvbS8Bx_" 238 | }, 239 | "source": [ 240 | "activity = both['Activity']\n", 241 | "label_counts = activity.value_counts()\n", 242 | "\n", 243 | "plt.figure(figsize= (12, 8))\n", 244 | "plt.bar(label_counts.index, label_counts)" 245 | ], 246 | "execution_count": null, 247 | "outputs": [] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "metadata": { 252 | "id": "65IC5kdf8NOq" 253 | }, 254 | "source": [ 255 | "ata = both['Data']\n", 256 | "Subject = both['subject']\n", 257 | "train = both.copy()\n", 258 | "train = train.drop(['Data','subject','Activity'], axis =1)" 259 | ], 260 | "execution_count": 12, 261 | "outputs": [] 262 | }, 263 | { 264 | "cell_type": "markdown", 265 | "metadata": { 266 | "id": "TxHuKZ_Z8XRl" 267 | }, 268 | "source": [ 269 | "#**4-To Scale the data**\n" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "metadata": { 275 | "id": "S7Rhv0Li8h0W" 276 | }, 277 | "source": [ 278 | "# Standard Scaler\n", 279 | "from sklearn.preprocessing import StandardScaler\n", 280 | "slc = StandardScaler()\n", 281 | "train = slc.fit_transform(train)\n", 282 | "\n", 283 | "# dimensionality reduction\n", 284 | "from sklearn.decomposition import PCA\n", 285 | "pca = PCA(n_components=0.9, random_state=0)\n", 286 | "train = pca.fit_transform(train)" 287 | ], 288 | "execution_count": 13, 289 | "outputs": [] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "metadata": { 294 | "id": "9DsuD_fH8pRl" 295 | }, 296 | "source": [ 297 | "#**5-Splitting the data into training and testing**\n" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "metadata": { 303 | "id": "NF59C5YR8vtf" 304 | }, 305 | "source": [ 306 | "from sklearn.model_selection import train_test_split\n", 307 | "X_train, X_test, y_train, y_test = train_test_split(train, activity, test_size = 0.2, random_state = 0)" 308 | ], 309 | "execution_count": 14, 310 | "outputs": [] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "metadata": { 315 | "id": "6gcJRPtr84vu" 316 | }, 317 | "source": [ 318 | "Test options and evaluation metric" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "metadata": { 324 | "id": "uT4rap_j8_3O" 325 | }, 326 | "source": [ 327 | "num_folds = 10\n", 328 | "seed = 0\n", 329 | "scoring = 'accuracy'\n", 330 | "results = {}\n", 331 | "accuracy = {}" 332 | ], 333 | "execution_count": 15, 334 | "outputs": [] 335 | }, 336 | { 337 | "cell_type": "markdown", 338 | "metadata": { 339 | "id": "r7YE34nh9GLb" 340 | }, 341 | "source": [ 342 | "#**6-Activity Recognition Algorithm**" 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "metadata": { 348 | "id": "4CkuDXzf9TZ1" 349 | }, 350 | "source": [ 351 | "# Finalizing the model and comparing the test, predict results\n", 352 | "from sklearn.neighbors import KNeighborsClassifier\n", 353 | "from sklearn.metrics import confusion_matrix, accuracy_score, classification_report\n", 354 | "from sklearn.model_selection import KFold, cross_val_score" 355 | ], 356 | "execution_count": 16, 357 | "outputs": [] 358 | }, 359 | { 360 | "cell_type": "code", 361 | "metadata": { 362 | "id": "0XKSsQTn9ZLu" 363 | }, 364 | "source": [ 365 | "model = KNeighborsClassifier(algorithm= 'auto', n_neighbors= 8, p= 1, weights= 'distance')\n", 366 | "\n", 367 | "_ = cross_val_score(model, X_train, y_train, cv=10, scoring=scoring)\n", 368 | "results[\"GScv\"] = (_.mean(), _.std())\n" 369 | ], 370 | "execution_count": 17, 371 | "outputs": [] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "metadata": { 376 | "id": "plEb_ooJ9kUO" 377 | }, 378 | "source": [ 379 | "model.fit(X_train, y_train) \n", 380 | "y_predict = model.predict(X_test)\n" 381 | ], 382 | "execution_count": 18, 383 | "outputs": [] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "metadata": { 388 | "id": "MohEpL9L9rCu" 389 | }, 390 | "source": [ 391 | "accuracy[\"GScv\"] = accuracy_score(y_test, y_predict)" 392 | ], 393 | "execution_count": 19, 394 | "outputs": [] 395 | }, 396 | { 397 | "cell_type": "code", 398 | "metadata": { 399 | "id": "65Q1gxZ49w3-" 400 | }, 401 | "source": [ 402 | "print(classification_report(y_test, y_predict))" 403 | ], 404 | "execution_count": null, 405 | "outputs": [] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "metadata": { 410 | "id": "z4uAByj695y2" 411 | }, 412 | "source": [ 413 | "cm= confusion_matrix(y_test, y_predict)\n", 414 | "sns.heatmap(cm, annot=True)" 415 | ], 416 | "execution_count": null, 417 | "outputs": [] 418 | }, 419 | { 420 | "cell_type": "markdown", 421 | "metadata": { 422 | "id": "1-JTCUE0d-YJ" 423 | }, 424 | "source": [ 425 | "#**References**\n", 426 | "[[1]Human Activity Recognition using Smartphone Data with Machine Learning](https://thecleverprogrammer.com/2020/05/27/human-activity-recognition-using-smartphone-data-with-machine-learning/)" 427 | ] 428 | } 429 | ] 430 | } -------------------------------------------------------------------------------- /Computer Vision/Real_Time_Face_Mask_Detector_(Not_Completed)_.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Real_Time_Face_Mask_Detector_(Not_Completed)_.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "accelerator": "GPU" 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "metadata": { 20 | "id": "view-in-github" 21 | }, 22 | "source": [ 23 | "\"Open" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": { 29 | "id": "Ghz5R8e3_09f" 30 | }, 31 | "source": [ 32 | "#**1-Introducion**\n", 33 | "\n", 34 | "During pandemic COVID-19, WHO has made wearing masks compulsory to protect against this deadly virus. In this tutorial we will develop a machine learning project – Real-time Face Mask Detector with Python.\n", 35 | "\n", 36 | "We will build a real-time system to detect whether the person on the webcam is wearing a mask or not. We will train the face mask detector model using Keras and OpenCV" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "metadata": { 42 | "id": "KIqScL3BuF5Y", 43 | "colab": { 44 | "base_uri": "https://localhost:8080/", 45 | "height": 34 46 | }, 47 | "outputId": "23dfad96-379b-40f7-f8d8-219585115980" 48 | }, 49 | "source": [ 50 | "from google.colab import drive\n", 51 | "drive.mount('/content/drive')" 52 | ], 53 | "execution_count": null, 54 | "outputs": [ 55 | { 56 | "output_type": "stream", 57 | "text": [ 58 | "Mounted at /content/drive\n" 59 | ], 60 | "name": "stdout" 61 | } 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "metadata": { 67 | "id": "GY4UiMiovb7b" 68 | }, 69 | "source": [ 70 | "!unzip -uq \"/content/drive/My Drive/Datasets/Real time Mask Detection /train.zip\" -d \"/content/drive/My Drive/Datasets/Real time Mask Detection /train\"\n" 71 | ], 72 | "execution_count": null, 73 | "outputs": [] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "metadata": { 78 | "id": "qR0dhQjrvb6L" 79 | }, 80 | "source": [ 81 | "!unzip -uq \"/content/drive/My Drive/Datasets/Real time Mask Detection /test.zip\" -d \"/content/drive/My Drive/Datasets/Real time Mask Detection /test\"\n" 82 | ], 83 | "execution_count": null, 84 | "outputs": [] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": { 89 | "id": "EfhBTSsBA9Z6" 90 | }, 91 | "source": [ 92 | "#**2- Dataset**\n", 93 | "The dataset we are working on consists of 1376 images with 690 images containing images of people wearing masks and 686 images with people without masks." 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "id": "6AQ-eKWUF2Hb" 100 | }, 101 | "source": [ 102 | "#**2-Import libraries and modules**" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "metadata": { 108 | "id": "3OFPPWYxGCKB" 109 | }, 110 | "source": [ 111 | "from keras.optimizers import RMSprop\n", 112 | "from keras.preprocessing.image import ImageDataGenerator\n", 113 | "import cv2\n", 114 | "from keras.models import Sequential\n", 115 | "from keras.layers import Conv2D, Input, ZeroPadding2D, BatchNormalization, Activation, MaxPooling2D, Flatten, Dense,Dropout\n", 116 | "from keras.models import Model, load_model\n", 117 | "from keras.callbacks import TensorBoard, ModelCheckpoint\n", 118 | "from sklearn.model_selection import train_test_split\n", 119 | "from sklearn.metrics import f1_score\n", 120 | "from sklearn.utils import shuffle\n", 121 | "import imutils\n", 122 | "import numpy as np" 123 | ], 124 | "execution_count": null, 125 | "outputs": [] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": { 130 | "id": "chN1TaDmGQKh" 131 | }, 132 | "source": [ 133 | "#**3- Build the neural network**\n", 134 | "\n", 135 | "This convolution network consists of two pairs of Conv and MaxPool layers to extract features from the dataset. Which is then followed by a Flatten and Dropout layer to convert the data in 1D and ensure overfitting.\n", 136 | "\n", 137 | "And then two Dense layers for classification." 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "metadata": { 143 | "id": "RUUbpIcMGZ94" 144 | }, 145 | "source": [ 146 | "model = Sequential([\n", 147 | " Conv2D(100, (3,3), activation='relu', input_shape=(150, 150, 3)),\n", 148 | " MaxPooling2D(2,2),\n", 149 | " \n", 150 | " Conv2D(100, (3,3), activation='relu'),\n", 151 | " MaxPooling2D(2,2),\n", 152 | " \n", 153 | " Flatten(),\n", 154 | " Dropout(0.5),\n", 155 | " Dense(50, activation='relu'),\n", 156 | " Dense(2, activation='softmax')\n", 157 | "])" 158 | ], 159 | "execution_count": null, 160 | "outputs": [] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "metadata": { 165 | "id": "DAxX4mV9Gmqa" 166 | }, 167 | "source": [ 168 | "model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])" 169 | ], 170 | "execution_count": null, 171 | "outputs": [] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": { 176 | "id": "jBn7P92dG8jc" 177 | }, 178 | "source": [ 179 | "##**4-Image Data Generation/Augmentation**" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "metadata": { 185 | "id": "2JjGqvMfHMo6", 186 | "colab": { 187 | "base_uri": "https://localhost:8080/", 188 | "height": 51 189 | }, 190 | "outputId": "324b964e-45a8-42ec-990a-fc558433fa76" 191 | }, 192 | "source": [ 193 | "TRAINING_DIR = \"/content/drive/My Drive/Datasets/Real time Mask Detection /train\"\n", 194 | "train_datagen = ImageDataGenerator(rescale=1.0/255,\n", 195 | " rotation_range=40,\n", 196 | " width_shift_range=0.2,\n", 197 | " height_shift_range=0.2,\n", 198 | " shear_range=0.2,\n", 199 | " zoom_range=0.2,\n", 200 | " horizontal_flip=True,\n", 201 | " fill_mode='nearest')\n", 202 | "train_generator = train_datagen.flow_from_directory(TRAINING_DIR, \n", 203 | " batch_size=10, \n", 204 | " target_size=(150, 150))\n", 205 | "VALIDATION_DIR = \"/content/drive/My Drive/Datasets/Real time Mask Detection /test\"\n", 206 | "validation_datagen = ImageDataGenerator(rescale=1.0/255)\n", 207 | "validation_generator = validation_datagen.flow_from_directory(VALIDATION_DIR, \n", 208 | " batch_size=10, \n", 209 | " target_size=(150, 150))" 210 | ], 211 | "execution_count": null, 212 | "outputs": [ 213 | { 214 | "output_type": "stream", 215 | "text": [ 216 | "Found 1315 images belonging to 1 classes.\n", 217 | "Found 194 images belonging to 1 classes.\n" 218 | ], 219 | "name": "stdout" 220 | } 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": { 226 | "id": "22YEm0M_HWUw" 227 | }, 228 | "source": [ 229 | "##5-**Initialize a callback checkpoint**\n", 230 | "Initialize a callback checkpoint to keep saving best model after each epoch while training:" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "metadata": { 236 | "id": "oswEGEf2Hhmi" 237 | }, 238 | "source": [ 239 | "checkpoint = ModelCheckpoint('model2-{epoch:03d}.model',monitor='val_loss',verbose=0,save_best_only=True,mode='auto')" 240 | ], 241 | "execution_count": null, 242 | "outputs": [] 243 | }, 244 | { 245 | "cell_type": "markdown", 246 | "metadata": { 247 | "id": "BSjZM6-WHunD" 248 | }, 249 | "source": [ 250 | "## **6-Train the model**" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "metadata": { 256 | "id": "mHmmke5YH4Lp", 257 | "colab": { 258 | "base_uri": "https://localhost:8080/", 259 | "height": 581 260 | }, 261 | "outputId": "b6c5a2d0-1cf3-4925-9c27-90225421e647" 262 | }, 263 | "source": [ 264 | "history = model.fit_generator(train_generator,\n", 265 | " epochs=10,\n", 266 | " validation_data=validation_generator,\n", 267 | " callbacks=[checkpoint])" 268 | ], 269 | "execution_count": null, 270 | "outputs": [ 271 | { 272 | "output_type": "stream", 273 | "text": [ 274 | "WARNING:tensorflow:From :4: Model.fit_generator (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.\n", 275 | "Instructions for updating:\n", 276 | "Please use Model.fit, which supports generators.\n", 277 | "Epoch 1/10\n", 278 | "132/132 [==============================] - ETA: 0s - loss: 0.8223 - acc: 0.9688WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.\n", 279 | "Instructions for updating:\n", 280 | "This property should not be used in TensorFlow 2.0, as updates are applied automatically.\n", 281 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/tracking.py:111: Layer.updates (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.\n", 282 | "Instructions for updating:\n", 283 | "This property should not be used in TensorFlow 2.0, as updates are applied automatically.\n", 284 | "INFO:tensorflow:Assets written to: model2-001.model/assets\n", 285 | "132/132 [==============================] - 732s 6s/step - loss: 0.8223 - acc: 0.9688 - val_loss: 0.6931 - val_acc: 1.0000\n", 286 | "Epoch 2/10\n", 287 | "132/132 [==============================] - ETA: 0s - loss: 0.6931 - acc: 1.0000INFO:tensorflow:Assets written to: model2-002.model/assets\n", 288 | "132/132 [==============================] - 16s 121ms/step - loss: 0.6931 - acc: 1.0000 - val_loss: 0.6931 - val_acc: 1.0000\n", 289 | "Epoch 3/10\n", 290 | "132/132 [==============================] - ETA: 0s - loss: 0.6931 - acc: 0.9992INFO:tensorflow:Assets written to: model2-003.model/assets\n", 291 | "132/132 [==============================] - 16s 119ms/step - loss: 0.6931 - acc: 0.9992 - val_loss: 0.6931 - val_acc: 1.0000\n", 292 | "Epoch 4/10\n", 293 | "132/132 [==============================] - 15s 112ms/step - loss: 0.6931 - acc: 1.0000 - val_loss: 0.6931 - val_acc: 1.0000\n", 294 | "Epoch 5/10\n", 295 | "132/132 [==============================] - 15s 112ms/step - loss: 0.6931 - acc: 0.9696 - val_loss: 0.6931 - val_acc: 0.0000e+00\n", 296 | "Epoch 6/10\n", 297 | "132/132 [==============================] - 14s 107ms/step - loss: 0.6931 - acc: 0.1217 - val_loss: 0.6931 - val_acc: 1.0000\n", 298 | "Epoch 7/10\n", 299 | "132/132 [==============================] - 15s 112ms/step - loss: 0.6931 - acc: 1.0000 - val_loss: 0.6931 - val_acc: 1.0000\n", 300 | "Epoch 8/10\n", 301 | "132/132 [==============================] - 15s 112ms/step - loss: 0.6931 - acc: 1.0000 - val_loss: 0.6931 - val_acc: 1.0000\n", 302 | "Epoch 9/10\n", 303 | "132/132 [==============================] - 15s 111ms/step - loss: 0.6931 - acc: 1.0000 - val_loss: 0.6931 - val_acc: 1.0000\n", 304 | "Epoch 10/10\n", 305 | "132/132 [==============================] - 14s 110ms/step - loss: 0.6931 - acc: 1.0000 - val_loss: 0.6931 - val_acc: 1.0000\n" 306 | ], 307 | "name": "stdout" 308 | } 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "metadata": { 314 | "id": "6CpIkbe6VtWL" 315 | }, 316 | "source": [ 317 | "model.save(\"model-010.h5\")" 318 | ], 319 | "execution_count": null, 320 | "outputs": [] 321 | }, 322 | { 323 | "cell_type": "markdown", 324 | "metadata": { 325 | "id": "D6zNOlMNH81w" 326 | }, 327 | "source": [ 328 | "#**7- Test the model** \n", 329 | "\n", 330 | "Now we will test the results of face mask detector model using OpenCV.\n", 331 | "\n", 332 | "Make a python file “test.py” and paste the below script." 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "metadata": { 338 | "id": "rInQ9kEhc44w" 339 | }, 340 | "source": [ 341 | "import cv2\n", 342 | "import numpy as np\n", 343 | "from keras.models import load_model\n", 344 | "model=load_model(\"model-010.h5\")\n", 345 | "\n", 346 | "labels_dict={0:'without mask',1:'mask'}\n", 347 | "color_dict={0:(0,0,255),1:(0,255,0)}\n", 348 | "\n", 349 | "size = 4\n", 350 | "webcam = cv2.VideoCapture(0) #Use camera 0\n", 351 | "\n", 352 | "# We load the xml file\n", 353 | "classifier = cv2.CascadeClassifier('/content/drive/My Drive/Datasets/Real time Mask Detection/haarcascade_frontalface_default.xml')\n", 354 | "\n", 355 | "while True:\n", 356 | " (rval, im) = webcam.read()\n", 357 | " im=cv2.flip(im,1,1) #Flip to act as a mirror\n", 358 | " # Resize the image to speed up detection\n", 359 | " mini = cv2.resize(im, (im.shape[1])) // rect_size, im.shape[0] // rect_size))\n", 360 | "\n", 361 | " faces = classifier.detectMultiScale(mini)\n", 362 | "\n", 363 | " # Draw rectangles around each face\n", 364 | " for f in faces:\n", 365 | " (x, y, w, h) = [v * size for v in f] #Scale the shapesize backup\n", 366 | " #Save just the rectangle faces in SubRecFaces\n", 367 | " face_img = im[y:y+h, x:x+w]\n", 368 | " resized=cv2.resize(face_img,(150,150))\n", 369 | " normalized=resized/255.0\n", 370 | " reshaped=np.reshape(normalized,(1,150,150,3))\n", 371 | " reshaped = np.vstack([reshaped])\n", 372 | " result=model.predict(reshaped)\n", 373 | " #print(result)\n", 374 | " \n", 375 | " label=np.argmax(result,axis=1)[0]\n", 376 | " \n", 377 | " cv2.rectangle(im,(x,y),(x+w,y+h),color_dict[label],2)\n", 378 | " cv2.rectangle(im,(x,y-40),(x+w,y),color_dict[label],-1)\n", 379 | " cv2.putText(im, labels_dict[label], (x, y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)\n", 380 | " \n", 381 | " # Show the image\n", 382 | " cv2.imshow('LIVE', im)\n", 383 | " key = cv2.waitKey(10)\n", 384 | " # if Esc key is press then break out of the loop \n", 385 | " if key == 27: #The Esc key\n", 386 | " break\n", 387 | "# Stop video\n", 388 | "webcam.release()\n", 389 | "\n", 390 | "# Close all started windows\n", 391 | "cv2.destroyAllWindows()" 392 | ], 393 | "execution_count": null, 394 | "outputs": [] 395 | }, 396 | { 397 | "cell_type": "markdown", 398 | "metadata": { 399 | "id": "zGNQE8-Y_gDP" 400 | }, 401 | "source": [ 402 | "# **References** \n", 403 | "[[1] Real-Time Face Mask Detector with Python](https://https://data-flair.training/blogs/face-mask-detection-with-python/)\n", 404 | "\n", 405 | "[[2]Face Mask Detection using Convolutional Neural Networks - Python | Keras | Tensorflow | OpenCV](https://www.youtube.com/watch?v=d3DJqucOq4g)\n", 406 | "\n", 407 | "[3] How to Use Webcam In Google Colab for Images and Video (FACE DETECTION)\n", 408 | "https://morioh.com/p/cddc982c4352?f=5c21fb01c16e2556b555ab32&fbclid=IwAR3K80ExXTZlG5PMPX7__Xx0w0SLMf1GZwfWzrtbRT9c7y4TwsymUayI-Zc" 409 | ] 410 | } 411 | ] 412 | } -------------------------------------------------------------------------------- /Computer Vision/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /DL/TableofContent.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /DL/readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Datasets/cars.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dr-mushtaq/Projects/28f8dc0e8a0500af4610121178b70b5efedb87ee/Datasets/cars.jpeg -------------------------------------------------------------------------------- /Datasets/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /File_organizer.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyMctezci4pAS6IzQbkkbQ36", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "id": "NYJP3aOzbhim" 34 | }, 35 | "outputs": [], 36 | "source": [] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "source": [ 41 | "# **References**" 42 | ], 43 | "metadata": { 44 | "id": "wIDmEoy5blcX" 45 | } 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "source": [ 50 | "[1-Local-File-Organizer](https://github.com/QiuYannnn/Local-File-Organizer/tree/main)\n", 51 | "\n", 52 | "[2-I built a Python script uses AI to organize files, runs 100% on your device](https://www.reddit.com/r/Python/comments/1fmgj31/i_built_a_python_script_uses_ai_to_organize_files/)" 53 | ], 54 | "metadata": { 55 | "id": "c8182BC8brNn" 56 | } 57 | } 58 | ] 59 | } -------------------------------------------------------------------------------- /Freelancer/AI problems (5).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dr-mushtaq/Projects/28f8dc0e8a0500af4610121178b70b5efedb87ee/Freelancer/AI problems (5).pdf -------------------------------------------------------------------------------- /Freelancer/Read: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ML/Data_Science_Project_on_Area_and_Population.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Data Science Project on Area and Population.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "vwhNM-sPzs1G" 23 | }, 24 | "source": [ 25 | "# **Datasets**\n", 26 | "\n", 27 | "In this project we’ll use the size of points to indicate the area and populations of California cities. We would like a legend that specifies the scale of the sizes of the points, and we’ll accomplish this by plotting some labeled data with no entries." 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "metadata": { 33 | "id": "m7FlbPEV0zi3" 34 | }, 35 | "source": [ 36 | "from google.colab import drive\n", 37 | "drive.mount('/content/drive')" 38 | ], 39 | "execution_count": null, 40 | "outputs": [] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "metadata": { 45 | "id": "X2jENpNnzbZx" 46 | }, 47 | "source": [ 48 | "import pandas as pd\n", 49 | "cities = pd.read_csv(\"/content/drive/MyDrive/Datasets/Area and Population/california_cities.csv\") " 50 | ], 51 | "execution_count": 23, 52 | "outputs": [] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "metadata": { 57 | "colab": { 58 | "base_uri": "https://localhost:8080/", 59 | "height": 241 60 | }, 61 | "id": "Lgxv7dQV150H", 62 | "outputId": "17ff1596-5c48-4dee-efda-b6871c5f49d3" 63 | }, 64 | "source": [ 65 | "cities.head()" 66 | ], 67 | "execution_count": 24, 68 | "outputs": [ 69 | { 70 | "output_type": "execute_result", 71 | "data": { 72 | "text/html": [ 73 | "
\n", 74 | "\n", 87 | "\n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \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 | "
Unnamed: 0citylatdlongdelevation_melevation_ftpopulation_totalarea_total_sq_miarea_land_sq_miarea_water_sq_miarea_total_km2area_land_km2area_water_km2area_water_percent
00Adelanto34.576111-117.432778875.02871.03176556.02756.0090.018145.107145.0620.0460.03
11AgouraHills34.153333-118.761667281.0922.0203307.8227.7930.02920.26020.1840.0760.37
22Alameda37.756111-122.274444NaN33.07546722.96010.61112.34959.46527.48231.98353.79
33Albany37.886944-122.297778NaN43.0189695.4651.7883.67714.1554.6329.52467.28
44Alhambra34.081944-118.135000150.0492.0830897.6327.6310.00119.76619.7630.0030.01
\n", 195 | "
" 196 | ], 197 | "text/plain": [ 198 | " Unnamed: 0 city ... area_water_km2 area_water_percent\n", 199 | "0 0 Adelanto ... 0.046 0.03\n", 200 | "1 1 AgouraHills ... 0.076 0.37\n", 201 | "2 2 Alameda ... 31.983 53.79\n", 202 | "3 3 Albany ... 9.524 67.28\n", 203 | "4 4 Alhambra ... 0.003 0.01\n", 204 | "\n", 205 | "[5 rows x 14 columns]" 206 | ] 207 | }, 208 | "metadata": { 209 | "tags": [] 210 | }, 211 | "execution_count": 24 212 | } 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "metadata": { 218 | "id": "Byh5JpI12w8p" 219 | }, 220 | "source": [ 221 | "# extracting the data we ar interested in\n", 222 | "latitude, longitude = cities[\"latd\"], cities[\"longd\"]\n", 223 | "population, area = cities[\"population_total\"], cities[\"area_total_km2\"]" 224 | ], 225 | "execution_count": 25, 226 | "outputs": [] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "metadata": { 231 | "id": "XnE1NmOx78uA" 232 | }, 233 | "source": [ 234 | "# to scatter the points, using size and color but without label\n", 235 | "import numpy as np\n", 236 | "import matplotlib.pyplot as plt\n", 237 | "import seaborn\n", 238 | "seaborn.set()\n", 239 | "plt.scatter(longitude, latitude, label=None, c=np.log10(population),\n", 240 | " cmap='viridis', s=area, linewidth=0, alpha=0.5)\n", 241 | "plt.axis(aspect='equal')\n", 242 | "plt.xlabel('Longitude')\n", 243 | "plt.ylabel('Longitude')\n", 244 | "plt.colorbar(label='log$_{10}$(population)')\n", 245 | "plt.clim(3, 7)\n", 246 | "# now we will craete a legend, we will plot empty lists with the desired size and label\n", 247 | "for area in [100, 300, 500]:\n", 248 | " plt.scatter([], [], c='k', alpha=0.3, s=area, label=str(area) + 'km$^2$')\n", 249 | "plt.legend(scatterpoints=1, frameon=False, labelspacing=1, title='City Areas')\n", 250 | "plt.title(\"Area and Population of California Cities\")\n", 251 | "plt.show()" 252 | ], 253 | "execution_count": null, 254 | "outputs": [] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "metadata": { 259 | "id": "ImiW7uD94qUu" 260 | }, 261 | "source": [ 262 | "# **References**" 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "metadata": { 268 | "id": "8JCjJCjP4u_p" 269 | }, 270 | "source": [ 271 | "[Data Science Project on Area and Population](https://thecleverprogrammer.com/2020/05/09/data-science-project-on-area-and-population/)" 272 | ] 273 | } 274 | ] 275 | } -------------------------------------------------------------------------------- /ML/President_Heights_exploratory_data.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "President Heights_exploratory data.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | } 13 | }, 14 | "cells": [ 15 | { 16 | "cell_type": "markdown", 17 | "metadata": { 18 | "id": "VLBfWEAzvy4m" 19 | }, 20 | "source": [ 21 | "# **1- Read Data**" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "metadata": { 27 | "colab": { 28 | "base_uri": "https://localhost:8080/" 29 | }, 30 | "id": "lOXT9jLAifU7", 31 | "outputId": "baf6a1d1-19bb-4ca6-e2a9-906c7e5734e2" 32 | }, 33 | "source": [ 34 | "from google.colab import drive\r\n", 35 | "drive.mount('/content/drive')" 36 | ], 37 | "execution_count": 1, 38 | "outputs": [ 39 | { 40 | "output_type": "stream", 41 | "text": [ 42 | "Mounted at /content/drive\n" 43 | ], 44 | "name": "stdout" 45 | } 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "metadata": { 51 | "id": "OWcKC8M4tMGH" 52 | }, 53 | "source": [ 54 | "import pandas as pd \r\n" 55 | ], 56 | "execution_count": 2, 57 | "outputs": [] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "metadata": { 62 | "id": "KRhuIfEeswYk" 63 | }, 64 | "source": [ 65 | "data = pd.read_csv(\"/content/drive/My Drive/Datasets/President Heights/president_heights.csv\")" 66 | ], 67 | "execution_count": 6, 68 | "outputs": [] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "metadata": { 73 | "id": "RUsO8tBGuebK" 74 | }, 75 | "source": [ 76 | "print(data.head())" 77 | ], 78 | "execution_count": null, 79 | "outputs": [] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "id": "zR8K8NUtulS3" 85 | }, 86 | "source": [ 87 | "We’ll use the Pandas package to read the file and extract this information (note that the heights are measured in centimeters):" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "metadata": { 93 | "id": "8heF3-ORuqfY" 94 | }, 95 | "source": [ 96 | "import numpy as np \r\n", 97 | "height = np.array(data[\"height(cm)\"])\r\n", 98 | "print(height)" 99 | ], 100 | "execution_count": null, 101 | "outputs": [] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": { 106 | "id": "Od_Gf0YLv-_b" 107 | }, 108 | "source": [ 109 | "# **2- summary statistics**" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": { 115 | "id": "eYXe4UtSu2ZJ" 116 | }, 117 | "source": [ 118 | "Now that we have this data array, we can compute a variety of summary statistics:\r\n", 119 | "\r\n" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "metadata": { 125 | "id": "3Peo8bqbu4LH" 126 | }, 127 | "source": [ 128 | "print(\"Mean of heights =\", height.mean())\r\n", 129 | "print(\"Standard Deviation of height =\", height.std())\r\n", 130 | "print(\"Minimum height =\", height.min())\r\n", 131 | "print(\"Maximum height =\", height.max())" 132 | ], 133 | "execution_count": null, 134 | "outputs": [] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": { 139 | "id": "OjmRGKIIvBzo" 140 | }, 141 | "source": [ 142 | "Note that in each case, the aggregation operation reduced the entire array to a single summarizing value, which gives us information about the distribution of values. We may also wish to compute quantiles:" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "metadata": { 148 | "id": "AtQbRegjvOwx" 149 | }, 150 | "source": [ 151 | "print(\"25th percentile =\", np.percentile(height, 25))\r\n", 152 | "print(\"Median =\", np.median(height))\r\n", 153 | "print(\"75th percentile =\", np.percentile(height, 75))" 154 | ], 155 | "execution_count": null, 156 | "outputs": [] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": { 161 | "id": "zWvwrSo1wPmQ" 162 | }, 163 | "source": [ 164 | "# **3- visual representation**" 165 | ] 166 | }, 167 | { 168 | "cell_type": "markdown", 169 | "metadata": { 170 | "id": "d_XgTxfetLOj" 171 | }, 172 | "source": [ 173 | "We see that the median height of US presidents is 182 cm, or just shy of six feet. Of course, sometimes it’s more useful to see a visual representation of this data, which we can accomplish using tools in Matplotlib:" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "metadata": { 179 | "id": "r-RXoly5vgts" 180 | }, 181 | "source": [ 182 | "import matplotlib.pyplot as plt\r\n", 183 | "import seaborn as sns\r\n", 184 | "sns.set()\r\n" 185 | ], 186 | "execution_count": 12, 187 | "outputs": [] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "metadata": { 192 | "id": "SUVETaw4vo2X" 193 | }, 194 | "source": [ 195 | "plt.hist(height)\r\n", 196 | "plt.title(\"Height Distribution of Presidents of USA\")\r\n", 197 | "plt.xlabel(\"height(cm)\")\r\n", 198 | "plt.ylabel(\"Number\")\r\n", 199 | "plt.show()" 200 | ], 201 | "execution_count": null, 202 | "outputs": [] 203 | }, 204 | { 205 | "cell_type": "markdown", 206 | "metadata": { 207 | "id": "0JSZsBVDwVwt" 208 | }, 209 | "source": [ 210 | "# **References**\r\n", 211 | "[Data Science Project on President Heights](https://thecleverprogrammer.com/2020/05/08/data-science-project-on-president-heights/)" 212 | ] 213 | } 214 | ] 215 | } -------------------------------------------------------------------------------- /ML/Stock_Price_Prediction_using_Linear_Regression.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Stock Price Prediction using-Linear Regression.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "id": "kkdLMCcxbwQA" 20 | }, 21 | "source": [ 22 | "# **1- Introduction**\r\n", 23 | "Predicting the stock market is one of the most important applications of Machine Learning in finance. In this article, I will take you through a simple Data Science project on Stock Price Prediction using Machine Learning Python." 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": { 29 | "id": "NATWVPgKcACn" 30 | }, 31 | "source": [ 32 | "# **2-Stock Price Prediction**\r\n", 33 | "\r\n", 34 | "Predicting the stock market has been the bane and goal of investors since its inception. Every day billions of dollars are traded on the stock exchange, and behind every dollar is an investor hoping to make a profit in one way or another.\r\n", 35 | "\r\n", 36 | "Entire companies rise and fall daily depending on market behaviour. If an investor is able to accurately predict market movements, he offers a tantalizing promise of wealth and influence. \r\n", 37 | "\r\n", 38 | "\r\n", 39 | " \r\n", 40 | "Today, so many people are making money staying at home trading in the stock market. It is a plus point for you if you use your experience in the stock market and your machine learning skills for the task of stock price prediction.\r\n", 41 | "\r\n", 42 | "Let’s see how to predict stock prices using Machine Learning and the python programming language. I will start this task by importing all the necessary python libraries that we need for this task:" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": { 48 | "id": "17PGGREJcUIt" 49 | }, 50 | "source": [ 51 | "# **3- Import Nessary library**" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "metadata": { 57 | "id": "8-MwpYmdbZ51" 58 | }, 59 | "source": [ 60 | "import numpy as np\r\n", 61 | "import pandas as pd\r\n", 62 | "from sklearn import preprocessing\r\n", 63 | "from sklearn.model_selection import train_test_split\r\n", 64 | "from sklearn.linear_model import LinearRegression" 65 | ], 66 | "execution_count": 4, 67 | "outputs": [] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": { 72 | "id": "mKLDktRWVSge" 73 | }, 74 | "source": [ 75 | "#**4- Read Data**" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "metadata": { 81 | "colab": { 82 | "base_uri": "https://localhost:8080/" 83 | }, 84 | "id": "EAwT1IcvJpha", 85 | "outputId": "be2e6a30-b05e-4806-899a-220d6e8cfda6" 86 | }, 87 | "source": [ 88 | "from google.colab import drive\r\n", 89 | "drive.mount('/content/drive')" 90 | ], 91 | "execution_count": 1, 92 | "outputs": [ 93 | { 94 | "output_type": "stream", 95 | "text": [ 96 | "Mounted at /content/drive\n" 97 | ], 98 | "name": "stdout" 99 | } 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "metadata": { 105 | "id": "pmO--ZoiL5qu" 106 | }, 107 | "source": [ 108 | "df = pd.read_csv(\"/content/drive/My Drive/Datasets/Stock Price Prediction/stock_data.csv\")\r\n", 109 | "#df = df[df.symbol == \"GOOG\"]" 110 | ], 111 | "execution_count": 12, 112 | "outputs": [] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": { 117 | "id": "kQ1R6zXwVcIk" 118 | }, 119 | "source": [ 120 | "# **5- Preprocessing**" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "metadata": { 126 | "id": "ei1ocSYgNE2u" 127 | }, 128 | "source": [ 129 | "df " 130 | ], 131 | "execution_count": null, 132 | "outputs": [] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "metadata": { 137 | "id": "_3n6O9DJOgoy" 138 | }, 139 | "source": [ 140 | "cols = [1,2,3,4,5,7]" 141 | ], 142 | "execution_count": 14, 143 | "outputs": [] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "metadata": { 148 | "id": "jfbe5FQKOnDK" 149 | }, 150 | "source": [ 151 | "df = df[df.columns[cols]]\r\n" 152 | ], 153 | "execution_count": 15, 154 | "outputs": [] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "metadata": { 159 | "id": "SIGUmEFmOqHy" 160 | }, 161 | "source": [ 162 | "df" 163 | ], 164 | "execution_count": null, 165 | "outputs": [] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "metadata": { 170 | "id": "RcJqZxRARsig" 171 | }, 172 | "source": [ 173 | "X=df.drop(columns=['Close'])" 174 | ], 175 | "execution_count": 21, 176 | "outputs": [] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "metadata": { 181 | "colab": { 182 | "base_uri": "https://localhost:8080/", 183 | "height": 419 184 | }, 185 | "id": "LRl0PPQ9R4qu", 186 | "outputId": "51909d30-a02e-411a-f557-e1757c172ded" 187 | }, 188 | "source": [ 189 | "X" 190 | ], 191 | "execution_count": 27, 192 | "outputs": [ 193 | { 194 | "output_type": "execute_result", 195 | "data": { 196 | "text/html": [ 197 | "
\n", 198 | "\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 | "
OpenHighLowVolumeStock
00.423880.429020.4187423220030AAPL
10.423880.425160.4136618022532AAPL
20.425160.436680.4251642498199AAPL
30.429020.431570.4161837125801AAPL
40.439270.440520.4392757822062AAPL
..................
19581178.56000180.45000178.3100013275578FB
19582180.50000180.74800179.4030012903836FB
19583179.79000180.35000179.1100010467606FB
19584178.31000179.40000177.0900012602188FB
19585178.35000179.10000177.9600011060355FB
\n", 313 | "

19586 rows × 5 columns

\n", 314 | "
" 315 | ], 316 | "text/plain": [ 317 | " Open High Low Volume Stock\n", 318 | "0 0.42388 0.42902 0.41874 23220030 AAPL\n", 319 | "1 0.42388 0.42516 0.41366 18022532 AAPL\n", 320 | "2 0.42516 0.43668 0.42516 42498199 AAPL\n", 321 | "3 0.42902 0.43157 0.41618 37125801 AAPL\n", 322 | "4 0.43927 0.44052 0.43927 57822062 AAPL\n", 323 | "... ... ... ... ... ...\n", 324 | "19581 178.56000 180.45000 178.31000 13275578 FB\n", 325 | "19582 180.50000 180.74800 179.40300 12903836 FB\n", 326 | "19583 179.79000 180.35000 179.11000 10467606 FB\n", 327 | "19584 178.31000 179.40000 177.09000 12602188 FB\n", 328 | "19585 178.35000 179.10000 177.96000 11060355 FB\n", 329 | "\n", 330 | "[19586 rows x 5 columns]" 331 | ] 332 | }, 333 | "metadata": { 334 | "tags": [] 335 | }, 336 | "execution_count": 27 337 | } 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "metadata": { 343 | "id": "xxrj4koVSEH-" 344 | }, 345 | "source": [ 346 | "cols = [3]\r\n", 347 | "Y = df[df.columns[cols]]" 348 | ], 349 | "execution_count": 24, 350 | "outputs": [] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "metadata": { 355 | "id": "6s1O7-yHSlFw" 356 | }, 357 | "source": [ 358 | "Y" 359 | ], 360 | "execution_count": null, 361 | "outputs": [] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "metadata": { 366 | "id": "ddZb6VHTS3R1" 367 | }, 368 | "source": [ 369 | "X.select_dtypes(include=['object']).columns" 370 | ], 371 | "execution_count": null, 372 | "outputs": [] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "metadata": { 377 | "id": "wgwM_JEmTB31" 378 | }, 379 | "source": [ 380 | "X['Stock'] = X['Stock'].fillna(X['Stock'].mode()[0])\r\n" 381 | ], 382 | "execution_count": 29, 383 | "outputs": [] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "metadata": { 388 | "id": "zwHSfWrQTWHG" 389 | }, 390 | "source": [ 391 | "# Convert categorical features to continuous features with Label Encoding\r\n", 392 | "from sklearn.preprocessing import LabelEncoder\r\n", 393 | "lencoders = {}\r\n", 394 | "for col in X.select_dtypes(include=['object']).columns:\r\n", 395 | " lencoders[col] = LabelEncoder()\r\n", 396 | " X[col] = lencoders[col].fit_transform(X[col])" 397 | ], 398 | "execution_count": 31, 399 | "outputs": [] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "metadata": { 404 | "id": "f7MBY2ySTqcl" 405 | }, 406 | "source": [ 407 | "X" 408 | ], 409 | "execution_count": null, 410 | "outputs": [] 411 | }, 412 | { 413 | "cell_type": "code", 414 | "metadata": { 415 | "id": "ueM201HKT0h9" 416 | }, 417 | "source": [ 418 | "import warnings\r\n", 419 | "warnings.filterwarnings(\"ignore\")\r\n", 420 | "# Multiple Imputation by Chained Equations\r\n", 421 | "from sklearn.experimental import enable_iterative_imputer\r\n", 422 | "from sklearn.impute import IterativeImputer\r\n", 423 | "MiceImputed = X.copy(deep=True) \r\n", 424 | "mice_imputer = IterativeImputer()\r\n", 425 | "MiceImputed.iloc[:, :] = mice_imputer.fit_transform(X)" 426 | ], 427 | "execution_count": 33, 428 | "outputs": [] 429 | }, 430 | { 431 | "cell_type": "code", 432 | "metadata": { 433 | "id": "yXsERht8T7tt" 434 | }, 435 | "source": [ 436 | "MiceImputed" 437 | ], 438 | "execution_count": null, 439 | "outputs": [] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "metadata": { 444 | "id": "Bb_06ov3UAsF" 445 | }, 446 | "source": [ 447 | "X=MiceImputed" 448 | ], 449 | "execution_count": 35, 450 | "outputs": [] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "metadata": { 455 | "id": "L7I1QYMaUMbk" 456 | }, 457 | "source": [ 458 | "# Standardizing data\r\n", 459 | "from sklearn import preprocessing\r\n", 460 | "r_scaler = preprocessing.MinMaxScaler()\r\n", 461 | "r_scaler.fit(MiceImputed)\r\n", 462 | "modified_data = pd.DataFrame(r_scaler.transform(MiceImputed), index=MiceImputed.index, columns=MiceImputed.columns)" 463 | ], 464 | "execution_count": 36, 465 | "outputs": [] 466 | }, 467 | { 468 | "cell_type": "code", 469 | "metadata": { 470 | "id": "86nOO0bKUPjU" 471 | }, 472 | "source": [ 473 | "modified_data" 474 | ], 475 | "execution_count": null, 476 | "outputs": [] 477 | }, 478 | { 479 | "cell_type": "markdown", 480 | "metadata": { 481 | "id": "hPlyXHJAVkTz" 482 | }, 483 | "source": [ 484 | "# **6-Data Spliiting** " 485 | ] 486 | }, 487 | { 488 | "cell_type": "code", 489 | "metadata": { 490 | "id": "71jffCRgUcOm" 491 | }, 492 | "source": [ 493 | "X_train, X_test, y_train, y_test = train_test_split(modified_data, Y, test_size=0.30, random_state=100)" 494 | ], 495 | "execution_count": 39, 496 | "outputs": [] 497 | }, 498 | { 499 | "cell_type": "markdown", 500 | "metadata": { 501 | "id": "QskbptQ1VrTN" 502 | }, 503 | "source": [ 504 | "# **7- Build Model**" 505 | ] 506 | }, 507 | { 508 | "cell_type": "code", 509 | "metadata": { 510 | "id": "8F1phluiUsJV" 511 | }, 512 | "source": [ 513 | "learner = LinearRegression() #initializing linear regression model\r\n" 514 | ], 515 | "execution_count": 40, 516 | "outputs": [] 517 | }, 518 | { 519 | "cell_type": "code", 520 | "metadata": { 521 | "id": "VKRHuF6OUt9k" 522 | }, 523 | "source": [ 524 | "learner.fit(X_train,y_train) #training the linear regression model" 525 | ], 526 | "execution_count": null, 527 | "outputs": [] 528 | }, 529 | { 530 | "cell_type": "code", 531 | "metadata": { 532 | "id": "6So1IOd9U6ZE" 533 | }, 534 | "source": [ 535 | "score=learner.score(X_test,y_test)#testing the linear regression model\r\n" 536 | ], 537 | "execution_count": 42, 538 | "outputs": [] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "metadata": { 543 | "id": "1AI19aLJVE8r" 544 | }, 545 | "source": [ 546 | "score" 547 | ], 548 | "execution_count": null, 549 | "outputs": [] 550 | }, 551 | { 552 | "cell_type": "markdown", 553 | "metadata": { 554 | "id": "V3BsycdObb0g" 555 | }, 556 | "source": [ 557 | "# **Reference** \r\n", 558 | "[Stock Price Prediction using Machine Learning](https://thecleverprogrammer.com/2020/11/14/stock-price-prediction-using-machine-learning/)" 559 | ] 560 | } 561 | ] 562 | } -------------------------------------------------------------------------------- /ML/read.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Machine Learning End to End/End_to_End_Fake_News_Detection_with_Python_(Naybaies_Streamlite).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "End-to-End Fake News Detection with Python (Naybaies Streamlite)", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "3y5steRGZdan" 23 | }, 24 | "source": [ 25 | "# **Introduction**" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "id": "weZu82mtnlYB" 32 | }, 33 | "source": [ 34 | "The spread of fake news is one of the most negative sides of social media applications. Recently I shared an article on how to detect fake news with machine learning which you can find here. With its continuation, in this article, I’ll take you through how to build an end-to-end fake news detection system with Python." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "id": "eaqsrot6jqtj" 41 | }, 42 | "source": [ 43 | "# **End-to-End Fake News Detection with Python**\n" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": { 49 | "id": "cV7zZ7Tls3-6" 50 | }, 51 | "source": [ 52 | "To create an end-to-end application for the task of fake news detection, you must first learn how to detect fake news with machine learning. You can learn all about Fake News detection with Machine Learning from here. Now returning to its end-to-end deployment, I’ll be using the streamlit library in Python to build an end-to-end application for the machine learning model to detect fake news in real-time. If you have never used the streamlit library before, you can easily install it on your system using the pip command:" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": { 58 | "id": "zn9LrOFutNXI" 59 | }, 60 | "source": [ 61 | "Now, if you have gone through this article, here is how you can build an end-to-end application for the task of fake news detection with Python:" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "metadata": { 67 | "id": "P0p34fjKlFoL" 68 | }, 69 | "source": [ 70 | "!pip install streamlit\n" 71 | ], 72 | "execution_count": null, 73 | "outputs": [] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "metadata": { 78 | "id": "TY9wsa_Gp_-O" 79 | }, 80 | "source": [ 81 | "!pip install ipykernel>=5.1.2\n", 82 | "!pip install pydeck" 83 | ], 84 | "execution_count": null, 85 | "outputs": [] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": { 90 | "id": "1wfEAwcpZkb1" 91 | }, 92 | "source": [ 93 | "# **Data Loading**" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "metadata": { 99 | "colab": { 100 | "base_uri": "https://localhost:8080/" 101 | }, 102 | "id": "XbcqNzNhZoxG", 103 | "outputId": "0bc65981-3671-48f9-9831-5440b7dfcc2b" 104 | }, 105 | "source": [ 106 | "from google.colab import drive\n", 107 | "drive.mount('/content/drive')" 108 | ], 109 | "execution_count": 3, 110 | "outputs": [ 111 | { 112 | "output_type": "stream", 113 | "name": "stdout", 114 | "text": [ 115 | "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" 116 | ] 117 | } 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "metadata": { 123 | "id": "_MSWWe4etaf4" 124 | }, 125 | "source": [ 126 | "import pandas as pd\n", 127 | "import numpy as np\n", 128 | "from sklearn.feature_extraction.text import CountVectorizer\n", 129 | "from sklearn.model_selection import train_test_split\n", 130 | "from sklearn.naive_bayes import MultinomialNB\n", 131 | "data = pd.read_csv(\"news.csv\")\n", 132 | "\n", 133 | "x = np.array(data[\"title\"])\n", 134 | "y = np.array(data[\"label\"])\n", 135 | "\n", 136 | "cv = CountVectorizer()\n", 137 | "x = cv.fit_transform(x)\n", 138 | "xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42)\n", 139 | "model = MultinomialNB()\n", 140 | "model.fit(xtrain, ytrain)\n", 141 | "\n", 142 | "import streamlit as st\n", 143 | "st.title(\"Fake News Detection System\")\n", 144 | "def fakenewsdetection():\n", 145 | " user = st.text_area(\"Enter Any News Headline: \")\n", 146 | " if len(user) < 1:\n", 147 | " st.write(\" \")\n", 148 | " else:\n", 149 | " sample = user\n", 150 | " data = cv.transform([sample]).toarray()\n", 151 | " a = model.predict(data)\n", 152 | " st.title(a)\n", 153 | "fakenewsdetection()" 154 | ], 155 | "execution_count": null, 156 | "outputs": [] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": { 161 | "id": "AaQzNurwuQLS" 162 | }, 163 | "source": [ 164 | "You cannot run this code the same way you run your other Python programs. As we are using the streamlit library here, so you need to write a command mentioned below in your command prompt or terminal to run this code:" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "metadata": { 170 | "id": "Rs4ldF-KuWSn" 171 | }, 172 | "source": [ 173 | "streamlit run filename.py" 174 | ], 175 | "execution_count": null, 176 | "outputs": [] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": { 181 | "id": "GF3nw_82w63F" 182 | }, 183 | "source": [ 184 | "Once this command executes, it will open a link on your default web browser that will display your output as a web interface for fake news detection, as shown below." 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "metadata": { 190 | "id": "Wb-f7U_ATlKy" 191 | }, 192 | "source": [ 193 | "# **References**\n", 194 | "[End-to-End Fake News Detection with Python](https://thecleverprogrammer.com/2021/07/09/end-to-end-fake-news-detection-with-python/)" 195 | ] 196 | } 197 | ] 198 | } -------------------------------------------------------------------------------- /Machine Learning End to End/End_to_End_Machine_Learning_Model.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "End-to-End Machine Learning Model", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "id": "3y5steRGZdan" 22 | }, 23 | "source": [ 24 | "# **Introduction**" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "id": "weZu82mtnlYB" 31 | }, 32 | "source": [ 33 | "You’ll find plenty of machine learning projects and tutorials on the internet, but only a few of them focus on end-to-end model deployment. So, if you want to learn how to build an end-to-end machine learning model, then this article is for you. In this article, I’ll walk you through how to build an end-to-end machine learning model using Python." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": { 39 | "id": "eaqsrot6jqtj" 40 | }, 41 | "source": [ 42 | "# **How to Build an End-to-End Machine Learning Model?**\n" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": { 48 | "id": "p5ZLfMInoB4n" 49 | }, 50 | "source": [ 51 | "An end-to-end machine learning model means that you train a model and deploy it into an end product or application where it can be used to add value to an organization. For example, when you train a model for the task of predicting stock prices, it cannot be said to be an end-to-end model. But if you build an app where you give a user input as the name of the stock or its symbol and get its future prices as output, this is an end-to-end model.\n", 52 | "\n", 53 | "So we can say that if you build an application where you can test the predictions of your trained model, it is an end-to-end model. This is why having an end to end application in your data science resume strengthens your profile as it shows that you know how to train a model that can add value to an organization when deployed in the product or the final application. In the section below, I’ll walk you through how to build an end-to-end model using Python." 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": { 59 | "id": "e38PRkl1oGiN" 60 | }, 61 | "source": [ 62 | "# **End-to-End Machine Learning Model using Python**\n" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": { 68 | "id": "TF3-9R0voPfd" 69 | }, 70 | "source": [ 71 | "We can use several ways in Python to build an end-to-end application for your model. I mainly use the streamlit library in Python which is so easy to use that it can deploy your model into an application in a few lines of code. If you’ve never used it before, you can easily install it using the pip command:\n", 72 | "\n" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "metadata": { 78 | "id": "P0p34fjKlFoL" 79 | }, 80 | "source": [ 81 | "!pip install streamlit\n" 82 | ], 83 | "execution_count": null, 84 | "outputs": [] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "metadata": { 89 | "id": "wiplM4rapl82" 90 | }, 91 | "source": [ 92 | "!pip install autots" 93 | ], 94 | "execution_count": null, 95 | "outputs": [] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "metadata": { 100 | "id": "TY9wsa_Gp_-O" 101 | }, 102 | "source": [ 103 | "!pip install ipykernel>=5.1.2\n", 104 | "!pip install pydeck" 105 | ], 106 | "execution_count": null, 107 | "outputs": [] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": { 112 | "id": "1wfEAwcpZkb1" 113 | }, 114 | "source": [ 115 | "# **Data Loading**" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "metadata": { 121 | "colab": { 122 | "base_uri": "https://localhost:8080/" 123 | }, 124 | "id": "XbcqNzNhZoxG", 125 | "outputId": "0bc65981-3671-48f9-9831-5440b7dfcc2b" 126 | }, 127 | "source": [ 128 | "from google.colab import drive\n", 129 | "drive.mount('/content/drive')" 130 | ], 131 | "execution_count": 3, 132 | "outputs": [ 133 | { 134 | "output_type": "stream", 135 | "name": "stdout", 136 | "text": [ 137 | "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" 138 | ] 139 | } 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "metadata": { 145 | "id": "DCZnlXXpfvCz" 146 | }, 147 | "source": [ 148 | "from autots import AutoTS\n", 149 | "import numpy as np\n", 150 | "import pandas as pd\n", 151 | "import matplotlib.pyplot as plt\n", 152 | "import seaborn as sns\n", 153 | "from seaborn import regression\n", 154 | "sns.set()\n", 155 | "plt.style.use('seaborn-whitegrid')\n", 156 | "\n", 157 | "import streamlit as st\n", 158 | "st.title(\"Future Price Prediction Model\")\n", 159 | "df = st.text_input(\"Let's Predict the Future Prices\")\n", 160 | "\n", 161 | "if df == \"Dogecoin\":\n", 162 | " data = pd.read_csv(\"/content/drive/MyDrive/Datasets/Future Price/Dogecoin.csv\")\n", 163 | " print(data.head())\n", 164 | " data.dropna()\n", 165 | " model = AutoTS(forecast_length=10, frequency='infer', ensemble='simple', drop_data_older_than_periods=200)\n", 166 | " model = model.fit(data, date_col='Date', value_col='Close', id_col=None)\n", 167 | " prediction = model.predict()\n", 168 | " forecast = prediction.forecast\n", 169 | " st.write(forecast)\n" 170 | ], 171 | "execution_count": null, 172 | "outputs": [] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": { 177 | "id": "0vfG21bgqdAE" 178 | }, 179 | "source": [ 180 | "To run this code, you have to write this command in your command prompt or terminal: \n", 181 | "\n", 182 | "**streamlit run filename.py **" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": { 188 | "id": "LN9UhFGdqf71" 189 | }, 190 | "source": [ 191 | "And then you will see a web page open in your default browser that will display your final output as shown below:" 192 | ] 193 | }, 194 | { 195 | "cell_type": "markdown", 196 | "metadata": { 197 | "id": "Wb-f7U_ATlKy" 198 | }, 199 | "source": [ 200 | "# **References**\n", 201 | "[End-to-End Machine Learning Model](https://thecleverprogrammer.com/2021/06/03/end-to-end-machine-learning-model/)" 202 | ] 203 | } 204 | ] 205 | } -------------------------------------------------------------------------------- /Machine Learning End to End/radfd.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Machine Learning End to End/readmi.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Model_Training_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "toc_visible": true, 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# **1-Import library**" 33 | ], 34 | "metadata": { 35 | "id": "3HLNoZfkBUGc" 36 | } 37 | }, 38 | { 39 | "cell_type": "code", 40 | "source": [ 41 | "import nltk\n", 42 | "from nltk.stem import WordNetLemmatizer\n", 43 | "lemmatizer = WordNetLemmatizer()\n", 44 | "import json\n", 45 | "import pickle\n", 46 | "\n", 47 | "import numpy as np\n", 48 | "from keras.models import Sequential\n", 49 | "from keras.layers import Dense, Activation, Dropout\n", 50 | "from keras.optimizers import SGD\n", 51 | "import random" 52 | ], 53 | "metadata": { 54 | "id": "UkuJaCW9bT6u" 55 | }, 56 | "execution_count": null, 57 | "outputs": [] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "source": [ 62 | "import nltk\n", 63 | "nltk.download('punkt')" 64 | ], 65 | "metadata": { 66 | "id": "TbN0QbsScujH" 67 | }, 68 | "execution_count": null, 69 | "outputs": [] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "source": [ 74 | "#**2-Dataset Loading**" 75 | ], 76 | "metadata": { 77 | "id": "CpC21eawvwSY" 78 | } 79 | }, 80 | { 81 | "cell_type": "code", 82 | "source": [ 83 | "from google.colab import drive\n", 84 | "drive.mount('/content/drive')" 85 | ], 86 | "metadata": { 87 | "colab": { 88 | "base_uri": "https://localhost:8080/" 89 | }, 90 | "id": "R60NmwbGDNp2", 91 | "outputId": "ce2de1b9-b58b-4b34-eba2-0bcffae5ed86" 92 | }, 93 | "execution_count": null, 94 | "outputs": [ 95 | { 96 | "output_type": "stream", 97 | "name": "stdout", 98 | "text": [ 99 | "Mounted at /content/drive\n" 100 | ] 101 | } 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "source": [ 107 | "words=[]\n", 108 | "classes = []\n", 109 | "documents = []\n", 110 | "ignore_words = ['?', '!']\n", 111 | "data_file = open('/content/drive/MyDrive/Research /Research Proposal /Dataset/intentsnew (6).json').read()\n", 112 | "intents = json.loads(data_file)" 113 | ], 114 | "metadata": { 115 | "id": "CfFYn2f_b5u9" 116 | }, 117 | "execution_count": null, 118 | "outputs": [] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "source": [ 123 | "# **3-Data Preprocessing**" 124 | ], 125 | "metadata": { 126 | "id": "5Yl5GZnxZnI3" 127 | } 128 | }, 129 | { 130 | "cell_type": "code", 131 | "source": [ 132 | "for intent in intents['intents']:\n", 133 | " for pattern in intent['patterns']:\n", 134 | "\n", 135 | " #tokenize each word\n", 136 | " w = nltk.word_tokenize(pattern)\n", 137 | " words.extend(w)\n", 138 | " # a dd documents in the corpus\n", 139 | " documents.append((w, intent['tag']))\n", 140 | "\n", 141 | " # add to our classes list\n", 142 | " if intent['tag'] not in classes:\n", 143 | " classes.append(intent['tag'])" 144 | ], 145 | "metadata": { 146 | "id": "ICA7KJTRD768" 147 | }, 148 | "execution_count": null, 149 | "outputs": [] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "source": [ 154 | "# lemmaztize and lower each word and remove duplicates\n", 155 | "nltk.download('wordnet')\n", 156 | "words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]\n", 157 | "words = sorted(list(set(words)))\n", 158 | "# sort classes\n", 159 | "classes = sorted(list(set(classes)))\n", 160 | "# documents = combination between patterns and intents\n", 161 | "print (len(documents), \"documents\")\n", 162 | "# classes = intents\n", 163 | "print (len(classes), \"classes\", classes)\n", 164 | "# words = all words, vocabulary\n", 165 | "print (len(words), \"unique lemmatized words\", words)\n", 166 | "pickle.dump(words,open('texts.pkl','wb'))\n", 167 | "pickle.dump(classes,open('labels.pkl','wb'))\n" 168 | ], 169 | "metadata": { 170 | "id": "-azsX0L8c7hX" 171 | }, 172 | "execution_count": null, 173 | "outputs": [] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "source": [ 178 | "# create our training data\n", 179 | "training = []\n", 180 | "# create an empty array for our output\n", 181 | "output_empty = [0] * len(classes)\n", 182 | "# training set, bag of words for each sentence\n", 183 | "for doc in documents:\n", 184 | " # initialize our bag of words\n", 185 | " bag = []\n", 186 | " # list of tokenized words for the pattern\n", 187 | " pattern_words = doc[0]\n", 188 | " # lemmatize each word - create base word, in attempt to represent related words\n", 189 | " pattern_words = [lemmatizer.lemmatize(word.lower()) for word in pattern_words]\n", 190 | " # create our bag of words array with 1, if word match found in current pattern\n", 191 | " for w in words:\n", 192 | " bag.append(1) if w in pattern_words else bag.append(0)\n", 193 | "\n", 194 | " # output is a '0' for each tag and '1' for current tag (for each pattern)\n", 195 | " output_row = list(output_empty)\n", 196 | " output_row[classes.index(doc[1])] = 1\n", 197 | "\n", 198 | " training.append([bag, output_row])\n", 199 | "# shuffle our features and turn into np.array\n", 200 | "random.shuffle(training)\n", 201 | "training = np.array(training)\n", 202 | "# create train and test lists. X - patterns, Y - intents\n", 203 | "train_x = list(training[:,0])\n", 204 | "train_y = list(training[:,1])\n", 205 | "print(\"Training data created\")\n" 206 | ], 207 | "metadata": { 208 | "id": "ZpeeTqAQdIUO", 209 | "outputId": "5c811704-a703-4873-ec88-81a6fbb1cac0", 210 | "colab": { 211 | "base_uri": "https://localhost:8080/" 212 | } 213 | }, 214 | "execution_count": null, 215 | "outputs": [ 216 | { 217 | "output_type": "stream", 218 | "name": "stdout", 219 | "text": [ 220 | "Training data created\n" 221 | ] 222 | }, 223 | { 224 | "output_type": "stream", 225 | "name": "stderr", 226 | "text": [ 227 | ":24: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n", 228 | " training = np.array(training)\n" 229 | ] 230 | } 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "source": [ 236 | "# **4-Model Training**" 237 | ], 238 | "metadata": { 239 | "id": "iiA5mfO_bf5G" 240 | } 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "source": [ 245 | "## **4.1-Neural Netowrk**" 246 | ], 247 | "metadata": { 248 | "id": "P-gDV4j8l0L0" 249 | } 250 | }, 251 | { 252 | "cell_type": "code", 253 | "source": [ 254 | "# Create model - 3 layers. First layer 128 neurons, second layer 64 neurons and 3rd output layer contains number of neurons\n", 255 | "# equal to number of intents to predict output intent with softmax\n", 256 | "model = Sequential()\n", 257 | "model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu'))\n", 258 | "model.add(Dropout(0.5))\n", 259 | "model.add(Dense(64, activation='relu'))\n", 260 | "model.add(Dropout(0.5))\n", 261 | "model.add(Dense(len(train_y[0]), activation='softmax'))\n", 262 | "\n", 263 | "# Compile model. Stochastic gradient descent with Nesterov accelerated gradient gives good results for this model\n", 264 | "sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)\n", 265 | "model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])\n", 266 | "\n", 267 | "#fitting and saving the model\n", 268 | "hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1)\n" 269 | ], 270 | "metadata": { 271 | "id": "pyIo9YkVdORl" 272 | }, 273 | "execution_count": null, 274 | "outputs": [] 275 | }, 276 | { 277 | "cell_type": "markdown", 278 | "source": [ 279 | "### **4.1.1 Model Saving**" 280 | ], 281 | "metadata": { 282 | "id": "Em4aCw6ImU3R" 283 | } 284 | }, 285 | { 286 | "cell_type": "code", 287 | "source": [ 288 | "model.save('chat_model', hist)\n", 289 | "print(\"model created\")" 290 | ], 291 | "metadata": { 292 | "id": "GwFda9VsmgQC", 293 | "outputId": "ccf8d6e4-6bef-4d81-92fd-245e2fc38a2f", 294 | "colab": { 295 | "base_uri": "https://localhost:8080/" 296 | } 297 | }, 298 | "execution_count": null, 299 | "outputs": [ 300 | { 301 | "output_type": "stream", 302 | "name": "stdout", 303 | "text": [ 304 | "model created\n" 305 | ] 306 | } 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "source": [ 312 | "## **4.2- LSTM**" 313 | ], 314 | "metadata": { 315 | "id": "5HvFngP6nzWA" 316 | } 317 | }, 318 | { 319 | "cell_type": "code", 320 | "source": [ 321 | "import numpy as np\n", 322 | "from keras.models import Sequential\n", 323 | "from keras.layers import LSTM, Dense" 324 | ], 325 | "metadata": { 326 | "id": "1nVA9smHqt4v" 327 | }, 328 | "execution_count": null, 329 | "outputs": [] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "source": [ 334 | "# Create the LSTM network\n", 335 | "model = Sequential()\n", 336 | "model.add(LSTM(8, input_shape=(5, 1), return_sequences=False))\n", 337 | "model.add(Dense(1))" 338 | ], 339 | "metadata": { 340 | "id": "kcFSuMKmq2C_" 341 | }, 342 | "execution_count": null, 343 | "outputs": [] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "source": [ 348 | "# Compile the model\n", 349 | "model.compile(loss='mse', optimizer='adam')" 350 | ], 351 | "metadata": { 352 | "id": "qO4Pu8Eaq68Y" 353 | }, 354 | "execution_count": null, 355 | "outputs": [] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "source": [ 360 | "# Train the model\n", 361 | "model.fit(np.array(train_x), np.array(train_y), epochs=100)" 362 | ], 363 | "metadata": { 364 | "id": "pISQug2TrAX3", 365 | "outputId": "c76ac1a4-5c42-4dea-a94b-dc4cdf4d20ae", 366 | "colab": { 367 | "base_uri": "https://localhost:8080/", 368 | "height": 606 369 | } 370 | }, 371 | "execution_count": null, 372 | "outputs": [ 373 | { 374 | "output_type": "stream", 375 | "name": "stdout", 376 | "text": [ 377 | "Epoch 1/100\n" 378 | ] 379 | }, 380 | { 381 | "output_type": "error", 382 | "ename": "ValueError", 383 | "evalue": "ignored", 384 | "traceback": [ 385 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 386 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", 387 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Train the model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_x\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 388 | "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/keras/utils/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[0;31m# To get the full stack trace, call:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0;31m# `tf.debugging.disable_traceback_filtering()`\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 70\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfiltered_tb\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 71\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mfiltered_tb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 389 | "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mtf__train_function\u001b[0;34m(iterator)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mdo_return\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mretval_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mag__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconverted_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mag__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mld\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstep_function\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mag__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mld\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mag__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mld\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfscope\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0;32mexcept\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mdo_return\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 390 | "\u001b[0;31mValueError\u001b[0m: in user code:\n\n File \"/usr/local/lib/python3.10/dist-packages/keras/engine/training.py\", line 1284, in train_function *\n return step_function(self, iterator)\n File \"/usr/local/lib/python3.10/dist-packages/keras/engine/training.py\", line 1268, in step_function **\n outputs = model.distribute_strategy.run(run_step, args=(data,))\n File \"/usr/local/lib/python3.10/dist-packages/keras/engine/training.py\", line 1249, in run_step **\n outputs = model.train_step(data)\n File \"/usr/local/lib/python3.10/dist-packages/keras/engine/training.py\", line 1050, in train_step\n y_pred = self(x, training=True)\n File \"/usr/local/lib/python3.10/dist-packages/keras/utils/traceback_utils.py\", line 70, in error_handler\n raise e.with_traceback(filtered_tb) from None\n File \"/usr/local/lib/python3.10/dist-packages/keras/engine/input_spec.py\", line 298, in assert_input_compatibility\n raise ValueError(\n\n ValueError: Input 0 of layer \"sequential_6\" is incompatible with the layer: expected shape=(None, 100), found shape=(None, 391)\n" 391 | ] 392 | } 393 | ] 394 | } 395 | ] 396 | } -------------------------------------------------------------------------------- /National Language processing/Chatbot_using_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Chatbot using Python.ipynb", 7 | "provenance": [], 8 | "toc_visible": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "gL0AffZGOZxZ" 23 | }, 24 | "source": [ 25 | "# **What is a Chatbot?**\n" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "id": "3yX2F4huOhMc" 32 | }, 33 | "source": [ 34 | "A Chatbot is an application that interacts with users like a human. Chatbots are typically used to resolve the most common queries that a business receives from its customers daily. In this article, I’ll walk you through how to create a Chatbot using Python." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "id": "kerEFyO-Ozbx" 41 | }, 42 | "source": [ 43 | "A Chatbot is an AI application that mimics human conversations. It is widely used by companies to solve the most common problems they receive from customers daily. For example, if you want to know the CRN of your bank account, a chatbot will assist you by asking for your bank details, then it will give you your CRN. But if you want to know something that is not that common, like asking how you can turn your account into a joint account, chances are the authorized employee will assist you.\n", 44 | "\n", 45 | "So while creating a chatbot for any company you should know what that company deals in and what problems their customers get daily. In the section below, I will take you through how to create a chatbot using Python." 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": { 51 | "id": "8w8p0-KTQWwo" 52 | }, 53 | "source": [ 54 | "**Chatbot with Python**\n" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": { 60 | "id": "Mlxs60-xQbeA" 61 | }, 62 | "source": [ 63 | "I hope you now have understood what are chatbots and why so many companies use them to solve the most common problems of their customers. Now let’s see how to create a chatbot with Python. Here, I will be using the **NLTK library** in Python which is one of the best Python libraries for any task of natural language processing:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "metadata": { 69 | "id": "bnyMCQ28Nv_R" 70 | }, 71 | "source": [ 72 | "from nltk.chat.util import Chat, reflections" 73 | ], 74 | "execution_count": 1, 75 | "outputs": [] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": { 80 | "id": "kNEwf4BrQqhB" 81 | }, 82 | "source": [ 83 | "Now I will be creating a list of queries and their responses for the chatbot:\n", 84 | "\n" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "metadata": { 90 | "id": "lGdlmHAxQw9a" 91 | }, 92 | "source": [ 93 | "#Pairs is a list of patterns and responses.\n", 94 | "pairs = [\n", 95 | " [\n", 96 | " r\"(.*)my name is (.*)\",\n", 97 | " [\"Hello %2, How are you today ?\",]\n", 98 | " ],\n", 99 | " [\n", 100 | " r\"(.*)help(.*) \",\n", 101 | " [\"I can help you \",]\n", 102 | " ],\n", 103 | " [\n", 104 | " r\"(.*) your name ?\",\n", 105 | " [\"My name is thecleverprogrammer, but you can just call me robot and I'm a chatbot .\",]\n", 106 | " ],\n", 107 | " [\n", 108 | " r\"how are you (.*) ?\",\n", 109 | " [\"I'm doing very well\", \"i am great !\"]\n", 110 | " ],\n", 111 | " [\n", 112 | " r\"sorry (.*)\",\n", 113 | " [\"Its alright\",\"Its OK, never mind that\",]\n", 114 | " ],\n", 115 | " [\n", 116 | " r\"i'm (.*) (good|well|okay|ok)\",\n", 117 | " [\"Nice to hear that\",\"Alright, great !\",]\n", 118 | " ],\n", 119 | " [\n", 120 | " r\"(hi|hey|hello|hola|holla)(.*)\",\n", 121 | " [\"Hello\", \"Hey there\",]\n", 122 | " ],\n", 123 | " [\n", 124 | " r\"what (.*) want ?\",\n", 125 | " [\"Make me an offer I can't refuse\",]\n", 126 | " \n", 127 | " ],\n", 128 | " [\n", 129 | " r\"(.*)created(.*)\",\n", 130 | " [\"Aman Kharwal created me using Python's NLTK library \",\"top secret ;)\",]\n", 131 | " ],\n", 132 | " [\n", 133 | " r\"(.*) (location|city) ?\",\n", 134 | " ['New Delhi, India',]\n", 135 | " ],\n", 136 | " [\n", 137 | " r\"(.*)raining in (.*)\",\n", 138 | " [\"No rain in the past 4 days here in %2\",\"In %2 there is a 50% chance of rain\",]\n", 139 | " ],\n", 140 | " [\n", 141 | " r\"how (.*) health (.*)\",\n", 142 | " [\"Health is very important, but I am a computer, so I don't need to worry about my health \",]\n", 143 | " ],\n", 144 | " [\n", 145 | " r\"(.*)(sports|game|sport)(.*)\",\n", 146 | " [\"I'm a very big fan of Cricket\",]\n", 147 | " ],\n", 148 | " [\n", 149 | " r\"who (.*) (Cricketer|Batsman)?\",\n", 150 | " [\"Virat Kohli\"]\n", 151 | " ],\n", 152 | " [\n", 153 | " r\"quit\",\n", 154 | " [\"Bye for now. See you soon :) \",\"It was nice talking to you. See you soon :)\"]\n", 155 | " ],\n", 156 | " [\n", 157 | " r\"(.*)\",\n", 158 | " ['That is nice to hear']\n", 159 | " ],\n", 160 | "]" 161 | ], 162 | "execution_count": 2, 163 | "outputs": [] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": { 168 | "id": "iROcEox2Q4Ms" 169 | }, 170 | "source": [ 171 | "Now let’s run this program and interact with the chatbot by using some of the queries related to the queries mentioned in the above list:" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "metadata": { 177 | "id": "-uMuLVX4RG-h" 178 | }, 179 | "source": [ 180 | "#default message at the start of chat\n", 181 | "print(\"Hi, I'm thecleverprogrammer and I like to chat\\nPlease type lowercase English language to start a conversation. Type quit to leave \")\n", 182 | "#Create Chat Bot\n", 183 | "chat = Chat(pairs, reflections)\n", 184 | "#Start conversation\n", 185 | "chat.converse()" 186 | ], 187 | "execution_count": null, 188 | "outputs": [] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "metadata": { 193 | "id": "MIXjbz4hOO6i" 194 | }, 195 | "source": [ 196 | "[Chatbot using Python](https://thecleverprogrammer.com/2021/03/25/chatbot-using-python/)" 197 | ] 198 | } 199 | ] 200 | } -------------------------------------------------------------------------------- /National Language processing/End_to_End_Spam_Detection_with_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "End-to-End Spam Detection with Python.ipynb", 7 | "provenance": [], 8 | "toc_visible": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "gL0AffZGOZxZ" 23 | }, 24 | "source": [ 25 | "# **Spam Detection**\n" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "id": "O5iX_J1BY8UO" 32 | }, 33 | "source": [ 34 | "Spam detection is one of the machine learning projects that every data science beginner must have tried once. Recently I shared an article on how to detect spam emails and messages with machine learning which you can find here. With its continuation in this article, I’ll walk you through how to build an end-to-end spam detection system with Python." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "id": "8w8p0-KTQWwo" 41 | }, 42 | "source": [ 43 | "**End-to-End Spam Detection with Python**\n" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": { 49 | "id": "Mlxs60-xQbeA" 50 | }, 51 | "source": [ 52 | "To create an end-to-end application for the spam detection task, you must first learn how to detect spam alerts with machine learning. You can learn all about Spam Detection with Machine Learning from here. Now returning to its end-to-end deployment, I’ll be using the streamlit library in Python to build an end-to-end application for the machine learning model to detect spam alerts in real-time. If you have never used the streamlit library before, you can easily install it on your system using the pip command:" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": { 58 | "id": "7v0rTZqiiMbJ" 59 | }, 60 | "source": [ 61 | "!pip install streamlit" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": { 67 | "id": "Q3TzKGZ3iQJJ" 68 | }, 69 | "source": [ 70 | "!pip install ipykernel>=5.1.2\n", 71 | "\n", 72 | "!pip install pydeck " 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "metadata": { 78 | "id": "ixuoUgX4aQl8" 79 | }, 80 | "source": [ 81 | "!pip install ipykernel>=5.1.2\n", 82 | "!pip install pydeck" 83 | ], 84 | "execution_count": null, 85 | "outputs": [] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": { 90 | "id": "kNEwf4BrQqhB" 91 | }, 92 | "source": [ 93 | "Now, if you have gone through this article, here is how you can build an end-to-end application for spam detection with Python:\n", 94 | "\n", 95 | "\n", 96 | "\n" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "metadata": { 102 | "id": "j15XwVa4ZumU" 103 | }, 104 | "source": [ 105 | "import pandas as pd\n", 106 | "import numpy as np\n", 107 | "from sklearn.feature_extraction.text import CountVectorizer\n", 108 | "from sklearn.model_selection import train_test_split\n", 109 | "from sklearn.naive_bayes import MultinomialNB\n", 110 | "data = pd.read_csv(\"https://raw.githubusercontent.com/amankharwal/SMS-Spam-Detection/master/spam.csv\", encoding= 'latin-1')\n", 111 | "data = data[[\"class\", \"message\"]]\n", 112 | "x = np.array(data[\"message\"])\n", 113 | "y = np.array(data[\"class\"])" 114 | ], 115 | "execution_count": 3, 116 | "outputs": [] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "metadata": { 121 | "id": "7GV9d0L9Z4cm" 122 | }, 123 | "source": [ 124 | "cv = CountVectorizer()\n", 125 | "X = cv.fit_transform(x) # Fit the Data\n", 126 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)\n", 127 | "\n", 128 | "clf = MultinomialNB()\n", 129 | "clf.fit(X_train,y_train)\n", 130 | "import streamlit as st\n", 131 | "st.title(\"Spam Detection System\")\n", 132 | "def spamdetection():\n", 133 | " user = st.text_area(\"Enter any Message or Email: \")\n", 134 | " if len(user) < 1:\n", 135 | " st.write(\" \")\n", 136 | " else:\n", 137 | " sample = user\n", 138 | " data = cv.transform([sample]).toarray()\n", 139 | " a = clf.predict(data)\n", 140 | " st.title(a)\n", 141 | "spamdetection()" 142 | ], 143 | "execution_count": null, 144 | "outputs": [] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": { 149 | "id": "POytgnMia-Pd" 150 | }, 151 | "source": [ 152 | "You cannot run this code the same way you run your other Python programs. As we are using the streamlit library here, so you need to write a command mentioned below in your command prompt or terminal to run this code:" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": { 158 | "id": "Xc8V53dbiHBq" 159 | }, 160 | "source": [ 161 | "**streamlit run filename.py**" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": { 167 | "id": "E6vA8E7WbGfO" 168 | }, 169 | "source": [ 170 | "Once this command executes, it will open a link on your default web browser that will display your end-to-end application for spam detection, as shown below." 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": { 176 | "id": "MIXjbz4hOO6i" 177 | }, 178 | "source": [ 179 | "[End-to-End Spam Detection with Python](https://thecleverprogrammer.com/2021/07/06/end-to-end-spam-detection-with-python/)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": { 185 | "id": "blbQhbt2h-9V" 186 | }, 187 | "source": [ 188 | "[error](http://5.9.10.113/67883973/error-while-creating-streamlit-webapp-using-google-colab-for-image-classificatio)" 189 | ] 190 | } 191 | ] 192 | } -------------------------------------------------------------------------------- /National Language processing/Next_Word_Prediction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Next Word Prediction.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyORSZkbG4V0B4X6TangNZUp", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "metadata": { 20 | "id": "view-in-github", 21 | "colab_type": "text" 22 | }, 23 | "source": [ 24 | "\"Open" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "metadata": { 30 | "id": "ZaI6Tg0J8T6i" 31 | }, 32 | "source": [ 33 | "" 34 | ], 35 | "execution_count": null, 36 | "outputs": [] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": { 41 | "id": "olKf7idT8tNp" 42 | }, 43 | "source": [ 44 | "# **1-Introduction**\n", 45 | "\n", 46 | "Most of the keyboards in smartphones give next word prediction features; google also uses next word prediction based on our browsing history. So a preloaded data is also stored in the keyboard function of our smartphones to predict the next word correctly. In this article, I will train a Deep Learning model for next word prediction using Python. I will use the Tensorflow and Keras library in Python for next word prediction model[1].\n", 47 | "For making a Next Word Prediction model, I will train a Recurrent Neural Network (RNN). So let’s start with this task now without wasting any time.[1]" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": { 53 | "id": "ekrccN86BJx3" 54 | }, 55 | "source": [ 56 | "#**2- Import Library**\n", 57 | "To start with our next word prediction model, let’s import some all the libraries we need for this task:\n", 58 | "\n" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "metadata": { 64 | "id": "Ec4zrgo4BXtw" 65 | }, 66 | "source": [ 67 | "import numpy as np\n", 68 | "from nltk.tokenize import RegexpTokenizer\n", 69 | "from keras.models import Sequential, load_model\n", 70 | "from keras.layers import LSTM\n", 71 | "from keras.layers.core import Dense, Activation\n", 72 | "from keras.optimizers import RMSprop\n", 73 | "import matplotlib.pyplot as plt\n", 74 | "import pickle\n", 75 | "import heapq" 76 | ], 77 | "execution_count": 11, 78 | "outputs": [] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": { 83 | "id": "YI1pDtID9IYQ" 84 | }, 85 | "source": [ 86 | "# **3- Dataset**\n", 87 | "\n", 88 | "As I told earlier, Google uses our browsing history to make next word predictions, smartphones, and all the keyboards that are trained to predict the next word are trained using some data. So I will also use a dataset. You can download the dataset from [here](https://drive.google.com/file/d/1GeUzNVqiixXHnTl8oNiQ2W3CynX_lsu2/view)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "metadata": { 94 | "id": "JglqMAQTAFwy", 95 | "outputId": "a3636c23-d586-4428-c5ec-a25e171f9aa9", 96 | "colab": { 97 | "base_uri": "https://localhost:8080/" 98 | } 99 | }, 100 | "source": [ 101 | "from google.colab import drive\n", 102 | "drive.mount('/content/drive')" 103 | ], 104 | "execution_count": 17, 105 | "outputs": [ 106 | { 107 | "output_type": "stream", 108 | "text": [ 109 | "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" 110 | ], 111 | "name": "stdout" 112 | } 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "metadata": { 118 | "id": "mCwasHeG-Uhy", 119 | "outputId": "179f86dc-1ad3-4925-f010-d61b9281bc41", 120 | "colab": { 121 | "base_uri": "https://localhost:8080/" 122 | } 123 | }, 124 | "source": [ 125 | "path = \"/content/drive/My Drive/Datasets/Next Word Prediction/1661-0.txt\"\n", 126 | "text = open(path).read().lower()\n", 127 | "print('corpus length:', len(text))" 128 | ], 129 | "execution_count": 18, 130 | "outputs": [ 131 | { 132 | "output_type": "stream", 133 | "text": [ 134 | "corpus length: 581888\n" 135 | ], 136 | "name": "stdout" 137 | } 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": { 143 | "id": "Mo6Lbqq9By3B" 144 | }, 145 | "source": [ 146 | "Now I will split the dataset into each word in order but without the presence of some special characters.[1]\n", 147 | "\n" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "metadata": { 153 | "id": "0DqYEwBtB97w" 154 | }, 155 | "source": [ 156 | "tokenizer = RegexpTokenizer(r'w+')\n", 157 | "words = tokenizer.tokenize(text)" 158 | ], 159 | "execution_count": 19, 160 | "outputs": [] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": { 165 | "id": "zVB6zOjkCOLn" 166 | }, 167 | "source": [ 168 | "Now the next process will be performing the feature engineering in our data. For this purpose, we will require a dictionary with each word in the data within the list of unique words as the key, and it’s significant portions as value." 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "metadata": { 174 | "id": "zO077DPMCZcY" 175 | }, 176 | "source": [ 177 | "unique_words = np.unique(words)\n", 178 | "unique_word_index = dict((c, i) for i, c in enumerate(unique_words))" 179 | ], 180 | "execution_count": 20, 181 | "outputs": [] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": { 186 | "id": "8w-AOzqsC0t4" 187 | }, 188 | "source": [ 189 | "# **4-Feature Engineering**\n", 190 | "\n", 191 | "Feature Engineering means taking whatever information we have about our problem and turning it into numbers that we can use to build our feature matrix. If you want a detailed tutorial of feature engineering, you can learn it from here.[1]\n", 192 | "\n", 193 | "Here I will define a Word length which will represent the number of previous words that will determine our next word. I will define prev words to keep five previous words and their corresponding next words in the list of next words[1]\n", 194 | "\n", 195 | "\n" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "metadata": { 201 | "id": "XLjbXJWeDeBn", 202 | "outputId": "66e28e2a-567b-47d3-ba82-6f3a482f71ac", 203 | "colab": { 204 | "base_uri": "https://localhost:8080/" 205 | } 206 | }, 207 | "source": [ 208 | "WORD_LENGTH = 5\n", 209 | "prev_words = []\n", 210 | "next_words = []\n", 211 | "for i in range(len(words) - WORD_LENGTH):\n", 212 | " prev_words.append(words[i:i + WORD_LENGTH])\n", 213 | " next_words.append(words[i + WORD_LENGTH])\n", 214 | "print(prev_words[0])\n", 215 | "print(next_words[0])" 216 | ], 217 | "execution_count": 21, 218 | "outputs": [ 219 | { 220 | "output_type": "stream", 221 | "text": [ 222 | "['w', 'w', 'w', 'w', 'w']\n", 223 | "www\n" 224 | ], 225 | "name": "stdout" 226 | } 227 | ] 228 | }, 229 | { 230 | "cell_type": "markdown", 231 | "metadata": { 232 | "id": "gM5ygqp0dyWn" 233 | }, 234 | "source": [ 235 | "Now I will create two numpy arrays x for storing the features and y for storing its corresponding label. I will iterate x and y if the word is available so that the corresponding position becomes 1." 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "metadata": { 241 | "id": "Ox38mcsud0TE" 242 | }, 243 | "source": [ 244 | "X = np.zeros((len(prev_words), WORD_LENGTH, len(unique_words)), dtype=bool)\n", 245 | "Y = np.zeros((len(next_words), len(unique_words)), dtype=bool)\n", 246 | "for i, each_words in enumerate(prev_words):\n", 247 | " for j, each_word in enumerate(each_words):\n", 248 | " X[i, j, unique_word_index[each_word]] = 1\n", 249 | " Y[i, unique_word_index[next_words[i]]] = 1" 250 | ], 251 | "execution_count": 22, 252 | "outputs": [] 253 | }, 254 | { 255 | "cell_type": "markdown", 256 | "metadata": { 257 | "id": "Nmt7_Yt6d5Jl" 258 | }, 259 | "source": [ 260 | "Now before moving forward, have a look at a single sequence of words:\n", 261 | "\n" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "metadata": { 267 | "id": "3NspIi8Ld9ld", 268 | "outputId": "6b1e963a-d975-43fb-cb8b-e3f60d3f7690", 269 | "colab": { 270 | "base_uri": "https://localhost:8080/" 271 | } 272 | }, 273 | "source": [ 274 | "print(X[0][0])\n" 275 | ], 276 | "execution_count": 23, 277 | "outputs": [ 278 | { 279 | "output_type": "stream", 280 | "text": [ 281 | "[ True False]\n" 282 | ], 283 | "name": "stdout" 284 | } 285 | ] 286 | }, 287 | { 288 | "cell_type": "markdown", 289 | "metadata": { 290 | "id": "APxYmNJZeHO1" 291 | }, 292 | "source": [ 293 | "#**5-Building the Recurrent Neural network**\n", 294 | "As I stated earlier, I will use the Recurrent Neural networks for next word prediction model. Here I will use the LSTM model, which is a very powerful RNN.[1]\n" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "metadata": { 300 | "id": "pKgP1X4veqjM" 301 | }, 302 | "source": [ 303 | "model = Sequential()\n", 304 | "model.add(LSTM(128, input_shape=(WORD_LENGTH, len(unique_words))))\n", 305 | "model.add(Dense(len(unique_words)))\n", 306 | "model.add(Activation('softmax'))" 307 | ], 308 | "execution_count": 24, 309 | "outputs": [] 310 | }, 311 | { 312 | "cell_type": "markdown", 313 | "metadata": { 314 | "id": "J1o_YDbSeuuU" 315 | }, 316 | "source": [ 317 | "#**6-Training the Next Word Prediction Model**\n", 318 | "I will be training the next word prediction model with 20 epochs[1]" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "metadata": { 324 | "id": "-YaeRP-be6OY" 325 | }, 326 | "source": [ 327 | "optimizer = RMSprop(lr=0.01)\n", 328 | "model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy'])\n", 329 | "history = model.fit(X, Y, validation_split=0.05, batch_size=128, epochs=2, shuffle=True).history" 330 | ], 331 | "execution_count": null, 332 | "outputs": [] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "metadata": { 337 | "id": "rfQGJjWlfK2m" 338 | }, 339 | "source": [ 340 | "Now we have successfully trained our model, before moving forward to evaluating our model, it will be better to save this model for our future use[1]" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "metadata": { 346 | "id": "SmW_O_cSfNbV" 347 | }, 348 | "source": [ 349 | "model.save('keras_next_word_model.h5')\n", 350 | "pickle.dump(history, open(\"history.p\", \"wb\"))\n", 351 | "model = load_model('keras_next_word_model.h5')\n", 352 | "history = pickle.load(open(\"history.p\", \"rb\"))" 353 | ], 354 | "execution_count": 26, 355 | "outputs": [] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "metadata": { 360 | "id": "N6woIuxnf9PE", 361 | "outputId": "93b264a2-d51f-46a1-863b-e4098b4808ff", 362 | "colab": { 363 | "base_uri": "https://localhost:8080/" 364 | } 365 | }, 366 | "source": [ 367 | "print(history)" 368 | ], 369 | "execution_count": 29, 370 | "outputs": [ 371 | { 372 | "output_type": "stream", 373 | "text": [ 374 | "{'loss': [0.009844760410487652, 0.002820393769070506], 'accuracy': [0.9999086856842041, 0.9999086856842041], 'val_loss': [0.2027292400598526, 0.23149938881397247], 'val_accuracy': [0.984402060508728, 0.984402060508728]}\n" 375 | ], 376 | "name": "stdout" 377 | } 378 | ] 379 | }, 380 | { 381 | "cell_type": "markdown", 382 | "metadata": { 383 | "id": "lKf1l5bVfXk3" 384 | }, 385 | "source": [ 386 | "#**7-Evaluating the Next Word Prediction Model**\n", 387 | "\n", 388 | "Now let’s have a quick look at how our model is going to behave based on its accuracy and loss changes while training:\n", 389 | "\n" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "metadata": { 395 | "id": "jeVQg0iFfie9" 396 | }, 397 | "source": [ 398 | "plt.plot(history['accuracy'])\n", 399 | "plt.plot(history['val_accuracy'])\n", 400 | "plt.title('model accuracy')\n", 401 | "plt.ylabel('accuracy')\n", 402 | "plt.xlabel('epoch')\n", 403 | "plt.legend(['train', 'test'], loc='upper left')" 404 | ], 405 | "execution_count": null, 406 | "outputs": [] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "metadata": { 411 | "id": "0XwYisZsgV6G" 412 | }, 413 | "source": [ 414 | "plt.plot(history['loss'])\n", 415 | "plt.plot(history['val_loss'])\n", 416 | "plt.title('model loss')\n", 417 | "plt.ylabel('loss')\n", 418 | "plt.xlabel('epoch')\n", 419 | "plt.legend(['train', 'test'], loc='upper left')" 420 | ], 421 | "execution_count": null, 422 | "outputs": [] 423 | }, 424 | { 425 | "cell_type": "markdown", 426 | "metadata": { 427 | "id": "EXAZaFzaghJz" 428 | }, 429 | "source": [ 430 | "#**8-Testing Next Word Prediction Model**\n", 431 | "\n", 432 | "Now let’s build a python program to predict the next word using our trained model. For this, I will define some essential functions that will be used in the process." 433 | ] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "metadata": { 438 | "id": "ICqkTlN8gs-g" 439 | }, 440 | "source": [ 441 | "def prepare_input(text):\n", 442 | " x = np.zeros((1, SEQUENCE_LENGTH, len(chars)))\n", 443 | " for t, char in enumerate(text):\n", 444 | " x[0, t, char_indices[char]] = 1.\n", 445 | " \n", 446 | " return x" 447 | ], 448 | "execution_count": 35, 449 | "outputs": [] 450 | }, 451 | { 452 | "cell_type": "markdown", 453 | "metadata": { 454 | "id": "tCv0KCZWg04X" 455 | }, 456 | "source": [ 457 | "Now before moving forward, let’s test the function, make sure you use a lower() function while giving input :\n", 458 | "\n" 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "metadata": { 464 | "id": "sWoj4Kp5g2id", 465 | "outputId": "7193d76c-4a1b-46db-9622-d39cccbd82c6", 466 | "colab": { 467 | "base_uri": "https://localhost:8080/", 468 | "height": 283 469 | } 470 | }, 471 | "source": [ 472 | "prepare_input(\"This is an example of input for our LSTM\".lower())\n" 473 | ], 474 | "execution_count": 37, 475 | "outputs": [ 476 | { 477 | "output_type": "error", 478 | "ename": "NameError", 479 | "evalue": "ignored", 480 | "traceback": [ 481 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 482 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 483 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprepare_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"This is an example of input for our LSTM\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlower\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 484 | "\u001b[0;32m\u001b[0m in \u001b[0;36mprepare_input\u001b[0;34m(text)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mprepare_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSEQUENCE_LENGTH\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mchars\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mchar\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mchar_indices\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mchar\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 485 | "\u001b[0;31mNameError\u001b[0m: name 'SEQUENCE_LENGTH' is not defined" 486 | ] 487 | } 488 | ] 489 | }, 490 | { 491 | "cell_type": "markdown", 492 | "metadata": { 493 | "id": "UaIX4lIl8a0Y" 494 | }, 495 | "source": [ 496 | "# **References**\n", 497 | "[Next Word Prediction Model](https://thecleverprogrammer.com/2020/07/20/next-word-prediction-model/)" 498 | ] 499 | } 500 | ] 501 | } -------------------------------------------------------------------------------- /National Language processing/POS Tagging for Multiple Languages.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, Request 2 | from fastapi.middleware.cors import CORSMiddleware 3 | from fastapi.responses import HTMLResponse 4 | from fastapi.templating import Jinja2Templates 5 | from pydantic import BaseModel 6 | import stanza 7 | import os 8 | 9 | app = FastAPI() 10 | templates = Jinja2Templates(directory="mini") 11 | 12 | # Only Indian languages officially supported by Stanza 13 | supported_indian_langs = { 14 | "en": "English", 15 | "hi": "Hindi", 16 | "ta": "Tamil", 17 | "te": "Telugu", 18 | "mr": "Marathi", 19 | "sa": "Sanskrit" 20 | } 21 | 22 | loaded_pipelines = {} 23 | 24 | app.add_middleware( 25 | CORSMiddleware, 26 | allow_origins=["*"], 27 | allow_methods=["*"], 28 | allow_headers=["*"], 29 | ) 30 | 31 | class InputText(BaseModel): 32 | text: str 33 | lang: str 34 | 35 | def download_model(lang): 36 | """Download model with error handling""" 37 | try: 38 | print(f"Downloading {lang} model...") 39 | stanza.download(lang) 40 | return True 41 | except Exception as e: 42 | print(f"Failed to download {lang}: {str(e)}") 43 | return False 44 | 45 | @app.post("/tag") 46 | async def pos_tag(input: InputText): 47 | lang = input.lang 48 | if lang not in supported_indian_langs: 49 | return {"result": f"Language not supported. Available: {', '.join(supported_indian_langs.values())}"} 50 | 51 | try: 52 | if lang not in loaded_pipelines: 53 | if not download_model(lang): 54 | return {"result": f"Failed to download model for {supported_indian_langs[lang]}"} 55 | 56 | # Special config for Bengali 57 | config = {"tokenize_pretokenized": True} if lang == "bn" else {} 58 | loaded_pipelines[lang] = stanza.Pipeline(lang=lang, **config) 59 | 60 | doc = loaded_pipelines[lang](input.text) 61 | return {"result": " ".join(f"{word.text}/{word.upos}" for sent in doc.sentences for word in sent.words)} 62 | 63 | except Exception as e: 64 | return {"result": f"Error processing text: {str(e)}"} 65 | 66 | @app.get("/", response_class=HTMLResponse) 67 | async def home(request: Request): 68 | return templates.TemplateResponse("index.html", { 69 | "request": request, 70 | "languages": supported_indian_langs 71 | }) 72 | 73 | -------------------------------------------------------------------------------- /National Language processing/Readm.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /National Language processing/Spam_Detection_with_Machine_Learning.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Spam Detection with Machine Learning.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "id": "Ei78b24mngey" 22 | }, 23 | "source": [ 24 | "# **Introduction**\n", 25 | "\n", 26 | "Detecting spam alerts in emails and messages is one of the main applications that every big tech company tries to improve for its customers. Apple’s official messaging app and Google’s Gmail are great examples of such applications where spam detection works well to protect users from spam alerts. So, if you are looking to build a spam detection system, this article is for you. In this article, I will walk you through the task of Spam Detection with Machine Learning using Python." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "id": "2wHz1KpjwAAk" 33 | }, 34 | "source": [ 35 | "**Spam Detection**\n", 36 | "\n", 37 | "Whenever you submit details about your email or contact number on any platform, it has become easy for those platforms to market their products by advertising them by sending emails or by sending messages directly to your contact number. This results in lots of spam alerts and notifications in your inbox. This is where the task of spam detection comes in.\n", 38 | "\n", 39 | "Spam detection means detecting spam messages or emails by understanding text content so that you can only receive notifications about messages or emails that are very important to you. If spam messages are found, they are automatically transferred to a spam folder and you are never notified of such alerts. This helps to improve the user experience, as many spam alerts can bother many users\n" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "id": "-804wtxDn976" 46 | }, 47 | "source": [ 48 | "# **Spam Detection using Python**\n", 49 | "\n", 50 | "Hope you now understand what spam detection is, now let’s see how to train a machine learning model for detecting spam alerts using Python. I’ll start this task by importing the necessary Python libraries and the dataset you need for this task:\n" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "metadata": { 56 | "id": "OOgGz72K0_jr" 57 | }, 58 | "source": [ 59 | "import pandas as pd\n", 60 | "import numpy as np\n", 61 | "from sklearn.feature_extraction.text import CountVectorizer\n", 62 | "from sklearn.model_selection import train_test_split\n", 63 | "from sklearn.naive_bayes import MultinomialNB" 64 | ], 65 | "execution_count": 15, 66 | "outputs": [] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "metadata": { 71 | "colab": { 72 | "base_uri": "https://localhost:8080/", 73 | "height": 204 74 | }, 75 | "id": "DP1NhI321BsL", 76 | "outputId": "803ee9c5-041e-41c7-9ba1-fcb1a8a4d949" 77 | }, 78 | "source": [ 79 | "data = pd.read_csv(\"https://raw.githubusercontent.com/amankharwal/SMS-Spam-Detection/master/spam.csv\", encoding= 'latin-1')\n", 80 | "data.head()" 81 | ], 82 | "execution_count": 16, 83 | "outputs": [ 84 | { 85 | "output_type": "execute_result", 86 | "data": { 87 | "text/html": [ 88 | "
\n", 89 | "\n", 102 | "\n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \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 | "
classmessageUnnamed: 2Unnamed: 3Unnamed: 4
0hamGo until jurong point, crazy.. Available only ...NaNNaNNaN
1hamOk lar... Joking wif u oni...NaNNaNNaN
2spamFree entry in 2 a wkly comp to win FA Cup fina...NaNNaNNaN
3hamU dun say so early hor... U c already then say...NaNNaNNaN
4hamNah I don't think he goes to usf, he lives aro...NaNNaNNaN
\n", 156 | "
" 157 | ], 158 | "text/plain": [ 159 | " class ... Unnamed: 4\n", 160 | "0 ham ... NaN\n", 161 | "1 ham ... NaN\n", 162 | "2 spam ... NaN\n", 163 | "3 ham ... NaN\n", 164 | "4 ham ... NaN\n", 165 | "\n", 166 | "[5 rows x 5 columns]" 167 | ] 168 | }, 169 | "metadata": { 170 | "tags": [] 171 | }, 172 | "execution_count": 16 173 | } 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": { 179 | "id": "Lr9UHJlc1WwY" 180 | }, 181 | "source": [ 182 | "From this dataset, class and message are the only features we need to train a machine learning model for spam detection, so let’s select these two columns as the new dataset:" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "metadata": { 188 | "id": "mJq8k4AE1bc5" 189 | }, 190 | "source": [ 191 | "data = data[[\"class\", \"message\"]]" 192 | ], 193 | "execution_count": 17, 194 | "outputs": [] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": { 199 | "id": "TtQG5bAb1mo3" 200 | }, 201 | "source": [ 202 | "Now let’s split this dataset into training and test sets and train the model to detect spam messages:" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "metadata": { 208 | "id": "RuIqY_v21lpu" 209 | }, 210 | "source": [ 211 | "x = np.array(data[\"message\"])\n", 212 | "y = np.array(data[\"class\"])" 213 | ], 214 | "execution_count": 18, 215 | "outputs": [] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "metadata": { 220 | "id": "yuLAnjuX2XHV" 221 | }, 222 | "source": [ 223 | "In order to use textual data for predictive modeling, the text must be parsed to remove certain words – this process is called **tokenization**. These words need to then be encoded as integers, or floating-point values, for use as inputs in machine learning algorithms. This process is called **feature extraction (or vectorization).**" 224 | ] 225 | }, 226 | { 227 | "cell_type": "markdown", 228 | "metadata": { 229 | "id": "2It78C2U2lUl" 230 | }, 231 | "source": [ 232 | "Scikit-learn’s **CountVectorizer** is used to convert a collection of text documents to a vector of term/token counts. It also enables the ​pre-processing of text data prior to generating the vector representation. This functionality makes it a highly flexible feature representation module for text." 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "metadata": { 238 | "id": "B4ChoRFD3qBU" 239 | }, 240 | "source": [ 241 | "![](https://drive.google.com/uc?export=view&id=1e38iFqQGrfcDubpBjqrCJDL1tMnv0zGA)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "metadata": { 247 | "id": "bv_P0WEf1wR2" 248 | }, 249 | "source": [ 250 | "cv = CountVectorizer()\n", 251 | "X = cv.fit_transform(x) # Fit the Data (# Encode the Document)" 252 | ], 253 | "execution_count": 19, 254 | "outputs": [] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "metadata": { 259 | "id": "jCeANVz45YRx" 260 | }, 261 | "source": [ 262 | "print(x)" 263 | ], 264 | "execution_count": null, 265 | "outputs": [] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "metadata": { 270 | "id": "_MN_Jo4h199m" 271 | }, 272 | "source": [ 273 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)\n" 274 | ], 275 | "execution_count": 22, 276 | "outputs": [] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "metadata": { 281 | "colab": { 282 | "base_uri": "https://localhost:8080/" 283 | }, 284 | "id": "JD6BHSqA6XcI", 285 | "outputId": "a34686ba-3020-4bc0-ac44-8acd232e7998" 286 | }, 287 | "source": [ 288 | "clf = MultinomialNB()\n", 289 | "clf.fit(X_train,y_train)" 290 | ], 291 | "execution_count": 26, 292 | "outputs": [ 293 | { 294 | "output_type": "execute_result", 295 | "data": { 296 | "text/plain": [ 297 | "MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True)" 298 | ] 299 | }, 300 | "metadata": { 301 | "tags": [] 302 | }, 303 | "execution_count": 26 304 | } 305 | ] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "metadata": { 310 | "id": "oEpL3WEu6hc_" 311 | }, 312 | "source": [ 313 | "Now let’s test this model by taking a user input as a message to detect whether it is spam or not:" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "metadata": { 319 | "id": "CXwuvEUE6jMP" 320 | }, 321 | "source": [ 322 | "sample = input('Enter a message:')\n", 323 | "data = cv.transform([sample]).toarray()\n", 324 | "print(clf.predict(data))" 325 | ], 326 | "execution_count": null, 327 | "outputs": [] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "metadata": { 332 | "id": "lvdXKVAQnQcC" 333 | }, 334 | "source": [ 335 | "# **References**\n", 336 | "\n", 337 | "[How to Save a Machine Learning Model?](https://thecleverprogrammer.com/2021/05/13/how-to-save-a-machine-learning-model/)\n", 338 | "\n", 339 | "[What's the difference between fit and fit_transform in scikit-learn models?](https://datascience.stackexchange.com/questions/12321/whats-the-difference-between-fit-and-fit-transform-in-scikit-learn-models)" 340 | ] 341 | } 342 | ] 343 | } -------------------------------------------------------------------------------- /National Language processing/Text_Classification.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Text Classification.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyPvP19vTj2cNZPCA5uT8itf", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "metadata": { 20 | "id": "view-in-github", 21 | "colab_type": "text" 22 | }, 23 | "source": [ 24 | "\"Open" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "id": "g_1jrmiVK6lp" 31 | }, 32 | "source": [ 33 | "# **1-Multinomial naive Bayes for text classification**" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": { 39 | "id": "hf-eIVCJJtDt" 40 | }, 41 | "source": [ 42 | "##**1.1- Introduction**\n", 43 | "\n", 44 | "One place in Data Science where multinomial naive Bayes is often used is in text classification, where the features are related to word counts or frequencies within the documents to be classified.\n", 45 | "\n", 46 | "In this data science project we will use the sparse word count features from the 20 Newsgroups corpus to show how we might classify these short documents into categories[1]" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": { 52 | "id": "8QR-OCyAKHEZ" 53 | }, 54 | "source": [ 55 | "##**1.2- Dataset** \n", 56 | "Let’s download the data and take a look at the target names:[1]" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "metadata": { 62 | "id": "yvnw-IXiKYc6" 63 | }, 64 | "source": [ 65 | "from sklearn.datasets import fetch_20newsgroups\n", 66 | "data = fetch_20newsgroups()\n", 67 | "print(data.target_names)" 68 | ], 69 | "execution_count": null, 70 | "outputs": [] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": { 75 | "id": "wpmoNU6mKxC6" 76 | }, 77 | "source": [ 78 | "## **1.3- Training and Testing**\n", 79 | "For simplicity, we will select just a few of these categories, and download the training and testing set[1]:\n", 80 | "\n" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "metadata": { 86 | "id": "VShV5srPLbvN" 87 | }, 88 | "source": [ 89 | "categories = ['talk.religion.misc', 'soc.religion.christian', 'sci.space', 'comp.graphics']\n", 90 | "train = fetch_20newsgroups(subset='train', categories=categories)\n", 91 | "test = fetch_20newsgroups(subset='test', categories=categories)" 92 | ], 93 | "execution_count": 2, 94 | "outputs": [] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "id": "I1iYjs36Li2j" 100 | }, 101 | "source": [ 102 | "Here is a representative entry from the data:[1]" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "metadata": { 108 | "id": "7Ok_kdz-Lq-S" 109 | }, 110 | "source": [ 111 | "print(train.data[5])" 112 | ], 113 | "execution_count": null, 114 | "outputs": [] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": { 119 | "id": "wEo1y1YxL3Lq" 120 | }, 121 | "source": [ 122 | "## **1.4- Build model**\n", 123 | "\n", 124 | "n order to use this data for machine learning, we need to be able to convert the content of each string into a vector of numbers. For this we will use the TF–IDF vectorizer, and create a pipeline that attaches it to a multinomial naive Bayes classifier:[1]" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "metadata": { 130 | "id": "c0d8XIYQMMkP" 131 | }, 132 | "source": [ 133 | "from sklearn.feature_extraction.text import TfidfVectorizer\n", 134 | "from sklearn.naive_bayes import MultinomialNB\n", 135 | "from sklearn.pipeline import make_pipeline" 136 | ], 137 | "execution_count": 4, 138 | "outputs": [] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "metadata": { 143 | "id": "R4JbEv4hMONJ" 144 | }, 145 | "source": [ 146 | "model = make_pipeline(TfidfVectorizer(), MultinomialNB())" 147 | ], 148 | "execution_count": 5, 149 | "outputs": [] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": { 154 | "id": "6iL07r6EMU8q" 155 | }, 156 | "source": [ 157 | "With this pipeline, we can apply the model to the training data, and predict labels for the test data:[1]\n", 158 | "\n" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "metadata": { 164 | "id": "gdpllpbFMaZR" 165 | }, 166 | "source": [ 167 | "model.fit(train.data, train.target)\n", 168 | "labels = model.predict(test.data)" 169 | ], 170 | "execution_count": 6, 171 | "outputs": [] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": { 176 | "id": "4oIz0zBoMv-S" 177 | }, 178 | "source": [ 179 | "## **1.5- Model evaluation**\n", 180 | "Now that we have predicted the labels for the test data, we can evaluate them to learn about the performance of the estimator. For example, here is the confusion matrix between the true and predicted labels for the test data[1].\n" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "metadata": { 186 | "id": "-Ij3asCGNILL" 187 | }, 188 | "source": [ 189 | "from sklearn.metrics import confusion_matrix\n", 190 | "mat = confusion_matrix(test.target, labels)\n", 191 | "import seaborn as sns\n", 192 | "import matplotlib.pyplot as plt\n", 193 | "sns.heatmap(mat.T,square=True,annot=True,fmt='d',cbar=False,\n", 194 | " xticklabels=train.target_names,yticklabels=train.target_names)\n", 195 | "plt.xlabel('True Label')\n", 196 | "plt.ylabel(\"Predicted Label\")\n", 197 | "plt.show()" 198 | ], 199 | "execution_count": null, 200 | "outputs": [] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": { 205 | "id": "ORjSMxTfOY66" 206 | }, 207 | "source": [ 208 | "Evidently, even this very simple classifier can successfully separate space talk from computer talk, but it gets confused between talk about religion and talk about Christianity. This is perhaps an expected area of confusion.\n", 209 | "\n", 210 | "The very cool thing here is that we now have the tools to determine the category for any string, using the predict() method of this pipeline. Here’s a quick utility function that will return the prediction for a single string:[1]" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "metadata": { 216 | "id": "aL8U0uKdObfC" 217 | }, 218 | "source": [ 219 | "def predict_category(s, train=train,model=model):\n", 220 | " pred = model.predict([s])\n", 221 | " print(train.target_names[pred[0]])" 222 | ], 223 | "execution_count": 10, 224 | "outputs": [] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "metadata": { 229 | "id": "lXsS8oR6Oity", 230 | "outputId": "d32d5aca-27f0-48c3-c8c2-3435768399ca", 231 | "colab": { 232 | "base_uri": "https://localhost:8080/" 233 | } 234 | }, 235 | "source": [ 236 | "predict_category(\"sending a payload to the ISS\")" 237 | ], 238 | "execution_count": 11, 239 | "outputs": [ 240 | { 241 | "output_type": "stream", 242 | "text": [ 243 | "sci.space\n" 244 | ], 245 | "name": "stdout" 246 | } 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "metadata": { 252 | "id": "bbNd-mbLOp1M" 253 | }, 254 | "source": [ 255 | "predict_category(\"discussing islam vs atheism\")" 256 | ], 257 | "execution_count": null, 258 | "outputs": [] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "metadata": { 263 | "id": "9C4ghbrQOu9c" 264 | }, 265 | "source": [ 266 | "predict_category(\"determining the screen resolution\")" 267 | ], 268 | "execution_count": null, 269 | "outputs": [] 270 | }, 271 | { 272 | "cell_type": "markdown", 273 | "metadata": { 274 | "id": "jj_itr1rO3dT" 275 | }, 276 | "source": [ 277 | "Remember that this is nothing more sophisticated than a simple probability model for the (weighted) frequency of each word in the string; nevertheless, the result is striking. Even a very naive algorithm, when used carefully and trained on a large set of high-dimensional data, can be surprisingly effective." 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": { 283 | "id": "oX1A0hwlJMH6" 284 | }, 285 | "source": [ 286 | "# **References** \n", 287 | "\n", 288 | "[[1]-Text Classification with Data Science](https://thecleverprogrammer.com/2020/05/14/text-classification-with-data-science/)\n", 289 | "\n", 290 | "[[2]-Text Classification Using Convolutional Neural Networks](https://www.youtube.com/watch?v=8YsZXTpFRO0)" 291 | ] 292 | } 293 | ] 294 | } -------------------------------------------------------------------------------- /Next_Word_Prediction_Model.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "toc_visible": true, 8 | "authorship_tag": "ABX9TyMYFTQ9qNrwr8BNHGW9YFBR", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "# **Introduction**" 34 | ], 35 | "metadata": { 36 | "id": "Z6FcOtuKD-45" 37 | } 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "source": [ 42 | "Most of the keyboards in smartphones give next word prediction features; google also uses next word prediction based on our browsing history. So a preloaded data is also stored in the keyboard function of our smartphones to predict the next word correctly." 43 | ], 44 | "metadata": { 45 | "id": "ZSlATptKEE0Z" 46 | } 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "source": [ 51 | "# **Table of Content**" 52 | ], 53 | "metadata": { 54 | "id": "W47NdJsKEIwv" 55 | } 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "source": [ 60 | "# **Techniques and Libraries**" 61 | ], 62 | "metadata": { 63 | "id": "hYdz0Dd8EPK_" 64 | } 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "source": [ 69 | "\n", 70 | "\n", 71 | "* Keras library\n", 72 | "* \n", 73 | "\n" 74 | ], 75 | "metadata": { 76 | "id": "g-txLfUVEhY_" 77 | } 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "source": [ 82 | "# **Import libraries**" 83 | ], 84 | "metadata": { 85 | "id": "RlQs8u0kEtpP" 86 | } 87 | }, 88 | { 89 | "cell_type": "code", 90 | "source": [], 91 | "metadata": { 92 | "id": "pyuDMENBFSlo" 93 | }, 94 | "execution_count": null, 95 | "outputs": [] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "metadata": { 101 | "id": "L6ZhWXfY2b5e" 102 | }, 103 | "outputs": [], 104 | "source": [ 105 | "import numpy as np\n", 106 | "from nltk.tokenize import RegexpTokenizer\n", 107 | "from keras.models import Sequential, load_model\n", 108 | "from keras.layers import LSTM, Dense, Activation # import Dense and Activation directly from keras.layers\n", 109 | "from keras.optimizers import RMSprop\n", 110 | "import matplotlib.pyplot as plt\n", 111 | "import pickle\n", 112 | "import heapq\n", 113 | "import pandas as pd" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "source": [ 119 | "# **Load Dataset**" 120 | ], 121 | "metadata": { 122 | "id": "XgJg16XtLxNe" 123 | } 124 | }, 125 | { 126 | "cell_type": "code", 127 | "source": [ 128 | "\n", 129 | "from google.colab import drive\n", 130 | "drive.mount('/content/gdrive')" 131 | ], 132 | "metadata": { 133 | "id": "cPgLVAO4J-Kq", 134 | "outputId": "67ed261d-930d-4bf9-8a35-054b6c95e978", 135 | "colab": { 136 | "base_uri": "https://localhost:8080/" 137 | } 138 | }, 139 | "execution_count": null, 140 | "outputs": [ 141 | { 142 | "output_type": "stream", 143 | "name": "stdout", 144 | "text": [ 145 | "Mounted at /content/gdrive\n" 146 | ] 147 | } 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "source": [ 153 | "\n", 154 | "path = '/content/gdrive/MyDrive/Datasets (1)/Next Word Prediction/1661-0.txt'\n", 155 | "text = open(path).read().lower()\n", 156 | "print('corpus length:', len(text))" 157 | ], 158 | "metadata": { 159 | "id": "NnhZrjI-KfS5", 160 | "outputId": "515e7d93-5085-4134-e1f6-f5da57da8088", 161 | "colab": { 162 | "base_uri": "https://localhost:8080/" 163 | } 164 | }, 165 | "execution_count": null, 166 | "outputs": [ 167 | { 168 | "output_type": "stream", 169 | "name": "stdout", 170 | "text": [ 171 | "corpus length: 581888\n" 172 | ] 173 | } 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "source": [ 179 | "# **References**" 180 | ], 181 | "metadata": { 182 | "id": "Rfq5lKZ32hgM" 183 | } 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "source": [ 188 | "[1-Next Word Prediction Model](https://thecleverprogrammer.com/2020/07/20/next-word-prediction-model/)\n", 189 | "\n", 190 | "[2-Next-Word-Prediction-with-NLP-and-Deep-Learning](https://github.com/Bharath-K3/Next-Word-Prediction-with-NLP-and-Deep-Learning)\n", 191 | "\n", 192 | "[3-Text Generation AI - Next Word Prediction in Python](https://www.youtube.com/watch?v=tEV_Jtmx2cc)" 193 | ], 194 | "metadata": { 195 | "id": "DORoprVG2nxg" 196 | } 197 | } 198 | ] 199 | } -------------------------------------------------------------------------------- /Plagiarism_checker_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "toc_visible": true, 8 | "authorship_tag": "ABX9TyMrt/TE/0tNguSz3RGr9Bna", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "id": "mLkwxtDlEBop" 35 | }, 36 | "outputs": [], 37 | "source": [] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "source": [ 42 | "# **References**" 43 | ], 44 | "metadata": { 45 | "id": "9cBibLFwEaBT" 46 | } 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "source": [ 51 | "[1-Plagiarism-checker-Python](https://github.com/Kalebu/Plagiarism-checker-Python/tree/master)" 52 | ], 53 | "metadata": { 54 | "id": "jxFD1Q-nEeNj" 55 | } 56 | } 57 | ] 58 | } -------------------------------------------------------------------------------- /Projects (1) (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dr-mushtaq/Projects/28f8dc0e8a0500af4610121178b70b5efedb87ee/Projects (1) (1).png -------------------------------------------------------------------------------- /QR_Code_Generation_using_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "include_colab_link": true 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "id": "view-in-github", 22 | "colab_type": "text" 23 | }, 24 | "source": [ 25 | "\"Open" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "source": [ 31 | "# **Generating QR Code in Python**\n", 32 | "QR (Quick Response) codes have become ubiquitous in our digital age. These square-shaped patterns, composed of black squares arranged on a white background, encode information that can be quickly and easily scanned by a smartphone camera.\n", 33 | "\n", 34 | " Originally developed in Japan in the 1990s for tracking automotive parts, QR codes have since found widespread use in various applications, including advertising, marketing, inventory management, ticketing, and more.\n", 35 | "\n", 36 | "\n", 37 | "In this tutorial, we'll explore how to generate QR codes in Python using the `qrcode` library. We'll create a simple QR code that encodes the URL \"https://coursesteach.com/\".\n", 38 | "\n", 39 | "## **1- Installing the qrcode Library**\n", 40 | "\n", 41 | "First, let's install the `qrcode` library using pip.\n", 42 | "\n", 43 | " Run the following command in your terminal or Jupyter notebook:" 44 | ], 45 | "metadata": { 46 | "id": "BfXGp-rwoEO3" 47 | } 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "id": "qP-qdb2xn94D", 54 | "colab": { 55 | "base_uri": "https://localhost:8080/" 56 | }, 57 | "outputId": "c54e6e90-97e3-4668-b0d6-cb225386c922" 58 | }, 59 | "outputs": [ 60 | { 61 | "output_type": "stream", 62 | "name": "stdout", 63 | "text": [ 64 | "Collecting qrcode\n", 65 | " Downloading qrcode-7.4.2-py3-none-any.whl (46 kB)\n", 66 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.2/46.2 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 67 | "\u001b[?25hRequirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from qrcode) (4.11.0)\n", 68 | "Collecting pypng (from qrcode)\n", 69 | " Downloading pypng-0.20220715.0-py3-none-any.whl (58 kB)\n", 70 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.1/58.1 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 71 | "\u001b[?25hInstalling collected packages: pypng, qrcode\n", 72 | "Successfully installed pypng-0.20220715.0 qrcode-7.4.2\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "!pip install qrcode" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "source": [ 83 | "## **2- Importing Libraries**\n", 84 | "\n", 85 | "\n", 86 | "\n" 87 | ], 88 | "metadata": { 89 | "id": "1n_C---7poOI" 90 | } 91 | }, 92 | { 93 | "cell_type": "code", 94 | "source": [ 95 | "import qrcode as qr" 96 | ], 97 | "metadata": { 98 | "id": "xS2imlfPqVLj" 99 | }, 100 | "execution_count": 2, 101 | "outputs": [] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "source": [ 106 | "# **3- Generating Qr Code**\n", 107 | "##### Now, let's generate the QR code using the qrcode library. We'll encode the URL \"https://coursesteach.com/\" into the QR code." 108 | ], 109 | "metadata": { 110 | "id": "N3C8WZmSqnzn" 111 | } 112 | }, 113 | { 114 | "cell_type": "code", 115 | "source": [ 116 | "img=qr.make(\"https://coursesteach.com/\")" 117 | ], 118 | "metadata": { 119 | "id": "H09M1k1prGZw" 120 | }, 121 | "execution_count": 3, 122 | "outputs": [] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "source": [ 127 | "#**4-Saving Qr Code**\n", 128 | "The below code will create a QR code representing the URL \"https://coursesteach.com/\" and save it as an image file named \"courseteach.png\" in the current directory." 129 | ], 130 | "metadata": { 131 | "id": "CMPshIY0rMuF" 132 | } 133 | }, 134 | { 135 | "cell_type": "code", 136 | "source": [ 137 | "img.save(\"corusesteah.png\")" 138 | ], 139 | "metadata": { 140 | "id": "I9YlsR3BruIJ" 141 | }, 142 | "execution_count": 4, 143 | "outputs": [] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "source": [ 148 | "#**5-Viewing the QR Code**\n", 149 | "Let's display the generated QR code image:\n", 150 | "\n", 151 | "\n", 152 | "You can scan this QR code using a QR code scanner app on your smartphone or any QR code reader to open the encoded URL \"https://coursesteach.com/\".\n" 153 | ], 154 | "metadata": { 155 | "id": "ye-hxJ4hr0Pl" 156 | } 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "source": [ 161 | "#**6-Conclusion**\n", 162 | "In this tutorial, we learned how to generate QR codes in Python using the qrcode library.\n", 163 | "\n", 164 | " QR codes have revolutionized the way we interact with digital content, providing a convenient and efficient way to access information with just a scan.\n", 165 | "\n", 166 | " The qrcode library provides a simple and straightforward way to create QR codes programmatically, making it easy to integrate QR code generation into your Python projects." 167 | ], 168 | "metadata": { 169 | "id": "_igQ7fs6sI5v" 170 | } 171 | } 172 | ] 173 | } -------------------------------------------------------------------------------- /Recommender System/Amazon_Recommendation_System_using_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Amazon Recommendation System using Python", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "7Mr86cuO-Fwz" 23 | }, 24 | "source": [ 25 | "# **Introduction**" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "id": "5ibm6OwR-Zcf" 32 | }, 33 | "source": [ 34 | "Recommendation Systems are one of the widely used applications of Data Science in most companies based on products and online services. Amazon is a great example of such companies. Being an online shopping website Amazon needs to generate personalised recommendations to provide a better user experience. In this article, I will take you through how to create an Amazon Recommendation System using Python." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "id": "p33lB-ne-l7m" 41 | }, 42 | "source": [ 43 | "The Recommendation System of Amazon follows the principle of generating product based recommendations which means measuring the similarities between two products and then recommend the most similar products to each user. The methods of measuring similarities between two products have always been a major focus of researchers.\n", 44 | "\n", 45 | "But when it comes to a website like Amazon, it needs to add more criteria to recommend products to the users such as the quality of the product. A good quality product will always have a good collection of reviews so we can use both the similarity score and product reviews to generate recommendations. In the section below, I will take you through how to create an Amazon Recommendation System using Python." 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": { 51 | "id": "DqpDmKkX-p43" 52 | }, 53 | "source": [ 54 | "# **Amazon Recommendation System using Python**" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": { 60 | "id": "4n0zcKQ7-yCo" 61 | }, 62 | "source": [ 63 | "I will try to use the fewer Python libraries I can for creating this recommendation system. To work with data I will be using only pandas and NumPy library in Python. So let’s import the data and see how to create an Amazon Recommendation System using Python:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": { 69 | "id": "H6yaBaPh_mum" 70 | }, 71 | "source": [ 72 | "# **Data Loading**\n" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "metadata": { 78 | "colab": { 79 | "base_uri": "https://localhost:8080/" 80 | }, 81 | "id": "yMk_rzke6Bb6", 82 | "outputId": "b51fd090-925d-479f-dc14-6859a6235378" 83 | }, 84 | "source": [ 85 | "from google.colab import drive\n", 86 | "drive.mount('/content/drive')" 87 | ], 88 | "execution_count": 1, 89 | "outputs": [ 90 | { 91 | "output_type": "stream", 92 | "text": [ 93 | "Mounted at /content/drive\n" 94 | ], 95 | "name": "stdout" 96 | } 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "metadata": { 102 | "id": "TF2NlY-5_3zm" 103 | }, 104 | "source": [ 105 | "import pandas as pd\n", 106 | "import numpy as np\n", 107 | "data = pd.read_csv(\"/content/drive/MyDrive/Datasets/ratings_Electronics.csv\")" 108 | ], 109 | "execution_count": 2, 110 | "outputs": [] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "metadata": { 115 | "id": "0DM0hCqpCyuh" 116 | }, 117 | "source": [ 118 | "print(data.head())" 119 | ], 120 | "execution_count": null, 121 | "outputs": [] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": { 126 | "id": "3NY1aQF4C4Mi" 127 | }, 128 | "source": [ 129 | "The dataset that I am using here does not have columns names, so let’s give the most appropriate names to these columns:" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "metadata": { 135 | "id": "v15uUPXgC-YR" 136 | }, 137 | "source": [ 138 | "data.columns = ['user_id', 'product_id','ratings','timestamp']" 139 | ], 140 | "execution_count": 4, 141 | "outputs": [] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": { 146 | "id": "izHW3nhmDKk5" 147 | }, 148 | "source": [ 149 | "This dataset is very large so I will select a sample:\n", 150 | "\n" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "metadata": { 156 | "id": "yhe1YLMpDQoY" 157 | }, 158 | "source": [ 159 | "df = data[:int(len(data) * .1)]" 160 | ], 161 | "execution_count": 6, 162 | "outputs": [] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": { 167 | "id": "VpFmvGtYDUqY" 168 | }, 169 | "source": [ 170 | "Now let’s prepare the dataset for creating a recommendation system:\n", 171 | "\n" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "metadata": { 177 | "id": "ZvUUcJCbDWQg" 178 | }, 179 | "source": [ 180 | "counts = df['user_id'].value_counts()\n", 181 | "data = df[df['user_id'].isin(counts[counts >= 50].index)]\n", 182 | "data.groupby('product_id')['ratings'].mean().sort_values(ascending=False) \n", 183 | "final_ratings = data.pivot(index = 'user_id', columns ='product_id', values = 'ratings').fillna(0)\n", 184 | "\n", 185 | "num_of_ratings = np.count_nonzero(final_ratings)\n", 186 | "possible_ratings = final_ratings.shape[0] * final_ratings.shape[1]\n", 187 | "density = (num_of_ratings/possible_ratings)\n", 188 | "density *= 100\n", 189 | "final_ratings_T = final_ratings.transpose()\n", 190 | "\n", 191 | "grouped = data.groupby('product_id').agg({'user_id': 'count'}).reset_index()\n", 192 | "grouped.rename(columns = {'user_id': 'score'},inplace=True)\n", 193 | "training_data = grouped.sort_values(['score', 'product_id'], ascending = [0,1]) \n", 194 | "training_data['Rank'] = training_data['score'].rank(ascending=0, method='first') \n", 195 | "recommendations = training_data.head()" 196 | ], 197 | "execution_count": 7, 198 | "outputs": [] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "metadata": { 203 | "id": "HeSHff6XDtyw" 204 | }, 205 | "source": [ 206 | "Now I will write a Python function to generate recommendations based on the score of the product reviews:" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "metadata": { 212 | "colab": { 213 | "base_uri": "https://localhost:8080/" 214 | }, 215 | "id": "7BHlaWZoDvah", 216 | "outputId": "c5815cf6-c879-45d3-ca14-ccdd4d0f8109" 217 | }, 218 | "source": [ 219 | "def recommend(id): \n", 220 | " recommend_products = recommendations \n", 221 | " recommend_products['user_id'] = id \n", 222 | " column = recommend_products.columns.tolist() \n", 223 | " column = column[-1:] + column[:-1] \n", 224 | " recommend_products = recommend_products[column] \n", 225 | " return recommend_products \n", 226 | "\n", 227 | "print(recommend(11))" 228 | ], 229 | "execution_count": 8, 230 | "outputs": [ 231 | { 232 | "output_type": "stream", 233 | "text": [ 234 | " user_id product_id score Rank\n", 235 | "113 11 B00004SB92 6 1.0\n", 236 | "1099 11 B00008OE6I 5 2.0\n", 237 | "368 11 B00005AW1H 4 3.0\n", 238 | "612 11 B0000645C9 4 4.0\n", 239 | "976 11 B00007KDVI 4 5.0\n" 240 | ], 241 | "name": "stdout" 242 | }, 243 | { 244 | "output_type": "stream", 245 | "text": [ 246 | "/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:3: SettingWithCopyWarning: \n", 247 | "A value is trying to be set on a copy of a slice from a DataFrame.\n", 248 | "Try using .loc[row_indexer,col_indexer] = value instead\n", 249 | "\n", 250 | "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", 251 | " This is separate from the ipykernel package so we can avoid doing imports until\n" 252 | ], 253 | "name": "stderr" 254 | } 255 | ] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "metadata": { 260 | "id": "Vjcs1eUuEDto" 261 | }, 262 | "source": [ 263 | "This is how we can create an Amazon Recommender System using Python. This dataset does not have names of products in it, it only had product id so the score of the product reviews becomes the most important feature for such kinds of datasets. I hope you like this article on how to create an Amazon Recommender System using Python. Feel free to ask your valuable questions in the comments section below" 264 | ] 265 | }, 266 | { 267 | "cell_type": "markdown", 268 | "metadata": { 269 | "id": "YyqdPTfP7MSK" 270 | }, 271 | "source": [ 272 | "# **References**\n" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "metadata": { 278 | "id": "o-sR7X7X7Zxi" 279 | }, 280 | "source": [ 281 | "[Amazon Recommendation System using Python](https://thecleverprogrammer.com/2021/03/23/amazon-recommendation-system-using-python/)" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": { 287 | "id": "vwdIvrmh7lJq" 288 | }, 289 | "source": [ 290 | "[215+ Machine Learning Projects Solved and Explained](https://medium.com/coders-camp/215-machine-learning-projects-solved-and-explained-7bd6fd478897)" 291 | ] 292 | } 293 | ] 294 | } -------------------------------------------------------------------------------- /Recommender System/Content_Based_Filtering_in_Machine_Learning.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Content-Based Filtering in Machine Learning.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | }, 16 | "accelerator": "GPU" 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "sjvNCvCVT9Dn" 23 | }, 24 | "source": [ 25 | "# **Introduction** " 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "id": "RoAWEMVeUCaY" 32 | }, 33 | "source": [ 34 | "Most recommendation systems use **content-based filtering and collaborative filtering** to show recommendations to the user to provide a better user experience. **Content-based filtering** generates recommendations based on a user’s behaviour. In this article, I will walk you through what content-based filtering is in machine learning and how to implement it using Python." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "id": "3VVu79ZgUYr0" 41 | }, 42 | "source": [ 43 | "A recommendation system is used to generate personalized recommendations by understanding a user’s preferences using data such as user history, time of viewing or reading etc. There are many applications based on recommendation systems. Most of the categories of these apps are:\n", 44 | "\n", 45 | "- Online Shopping (Amazon, Zomato, etc.)\n", 46 | "- Audio (Songs, Audiobooks, Podcast, etc.)\n", 47 | "- Video Recommendations (YouTube, Netflix, Amazon Prime, etc.)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": { 53 | "id": "smtTBIpeUnOj" 54 | }, 55 | "source": [ 56 | "So there are two types of recommendation systems:\n", 57 | "\n", 58 | "- Collaborative Filtering\n", 59 | "- Content-Based Filtering" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "id": "dWFgl9-1VL14" 66 | }, 67 | "source": [ 68 | "Collaborative filtering uses the behaviour of other users who have similar interests like you and based on the activities of those users, it shows you perfect recommendations. A recommendation system based on the content-based method will show you recommendations based on your behaviour. In the section below, I’ll walk you through how content-based filtering in machine learning works in detail, and then we’ll see how to implement it using Python." 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": { 74 | "id": "PE5K3A9BVb9X" 75 | }, 76 | "source": [ 77 | "A recommendation system based on content-based filtering provides recommendations to the user by analyzing the description of the content that has been rated by the user. In this method, the algorithm is trained to understand the context of the content and find similarities in other content to recommend the same class of content to a particular user." 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": { 83 | "id": "AX1y-WlbVs88" 84 | }, 85 | "source": [ 86 | "Let’s understand the process of content-based filtering by looking at all the steps that are involved in this method for generating recommendations for the user:\n", 87 | "\n", 88 | " - It begins by identifying the keywords to understand the context of the content. In this step, it avoids unnecessary words such as stop words.\n", 89 | "- Then it finds the same kind of context in other content to find the similarities. To determine the similarities between two or more contents, the content-based method uses cosine similarities.\n", 90 | "- It finds similarities by analyzing the correlation between two or more users.\n", 91 | "- Then finally it generates recommendations by calculating the weighted average of all user ratings for active users.\n", 92 | "\n", 93 | "Hope you now understand how content-based filtering works. Now in the section below, I will walk you through how to implement it using the Python programming language." 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "id": "whNLGDufWRo7" 100 | }, 101 | "source": [ 102 | "I hope till now you have understood what are recommendation systems and how content-based method is used to generate recommendations for a user. Now let’s see how to implement content-based method with Python. For this task, I will be using the dataset provided by MovieLens to create a movie recommendation system using content-based filtering with Python.\n", 103 | "\n", 104 | "Let’s start his task by importing the necessary Python libraries and the dataset:" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "metadata": { 110 | "colab": { 111 | "base_uri": "https://localhost:8080/" 112 | }, 113 | "id": "xplkUI3eTvRl", 114 | "outputId": "a63d505a-606e-40b7-e76a-64a17251fadb" 115 | }, 116 | "source": [ 117 | "from google.colab import drive\n", 118 | "drive.mount('/content/drive')" 119 | ], 120 | "execution_count": 2, 121 | "outputs": [ 122 | { 123 | "output_type": "stream", 124 | "text": [ 125 | "Mounted at /content/drive\n" 126 | ], 127 | "name": "stdout" 128 | } 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "metadata": { 134 | "colab": { 135 | "base_uri": "https://localhost:8080/" 136 | }, 137 | "id": "9KJAMYqDYAd0", 138 | "outputId": "91c04533-25c6-43bc-83a8-3c69c1b3122b" 139 | }, 140 | "source": [ 141 | "import numpy as np\n", 142 | "import pandas as pd\n", 143 | "from sklearn.metrics.pairwise import cosine_similarity\n", 144 | "from sklearn.metrics import mean_squared_error\n", 145 | "from sklearn.model_selection import train_test_split\n", 146 | "from sklearn.feature_extraction.text import TfidfVectorizer\n", 147 | "from sklearn.metrics.pairwise import linear_kernel\n", 148 | "movies = pd.read_csv('/content/drive/MyDrive/Datasets/Movie Recommendation/movies_metadata.csv')\n", 149 | "print(movies.head())" 150 | ], 151 | "execution_count": 1, 152 | "outputs": [ 153 | { 154 | "output_type": "stream", 155 | "text": [ 156 | " adult ... vote_count\n", 157 | "0 False ... 5415.0\n", 158 | "1 False ... 2413.0\n", 159 | "2 False ... 92.0\n", 160 | "3 False ... 34.0\n", 161 | "4 False ... 173.0\n", 162 | "\n", 163 | "[5 rows x 24 columns]\n" 164 | ], 165 | "name": "stdout" 166 | }, 167 | { 168 | "output_type": "stream", 169 | "text": [ 170 | "/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py:2718: DtypeWarning: Columns (10) have mixed types.Specify dtype option on import or set low_memory=False.\n", 171 | " interactivity=interactivity, compiler=compiler, result=result)\n" 172 | ], 173 | "name": "stderr" 174 | } 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": { 180 | "id": "ehJD07xcZsCp" 181 | }, 182 | "source": [ 183 | "Now, I’m going to implement all of the steps I talked about in the content-based filtering process mentioned above using Python. Here I will prepare the data first, then select the columns that we will use to understand the context of the content, then we will remove the stop words and finally, we will find the cosine similarities to generate recommendations:" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "metadata": { 189 | "id": "PFzgTfntZ5a-" 190 | }, 191 | "source": [ 192 | "from sklearn.feature_extraction.text import TfidfVectorizer\n", 193 | "tfidf = TfidfVectorizer(stop_words='english')\n", 194 | "movies['overview'] = movies['overview'].fillna('')\n", 195 | "overview_matrix = tfidf.fit_transform(movies['overview'])\n", 196 | "similarity_matrix = linear_kernel(overview_matrix,overview_matrix)\n", 197 | "mapping = pd.Series(movies.index,index = movies['title'])\n", 198 | "print(mapping)" 199 | ], 200 | "execution_count": null, 201 | "outputs": [] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": { 206 | "id": "wZVcdeIQbHS-" 207 | }, 208 | "source": [ 209 | "Now let’s create a function and have a look at how the recommendation system is working:" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "metadata": { 215 | "id": "UWanitCBbM6j" 216 | }, 217 | "source": [ 218 | "def recommend_movies(movie_input):\n", 219 | " movie_index = mapping[movie_input]\n", 220 | " similarity_score = list(enumerate(similarity_matrix[movie_index]))\n", 221 | " similarity_score = sorted(similarity_score, key=lambda x: x[1], reverse=True)\n", 222 | " similarity_score = similarity_score[1:15]\n", 223 | " movie_indices = [i[0] for i in similarity_score]\n", 224 | " return (movies['title'].iloc[movie_indices])\n", 225 | "\n", 226 | "print(recommend_movies('Life Begins for Andy Hardy'))" 227 | ], 228 | "execution_count": null, 229 | "outputs": [] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": { 234 | "id": "cr_bxqX0TwU5" 235 | }, 236 | "source": [ 237 | "# **References**" 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": { 243 | "id": "L6H5qa_CT3X_" 244 | }, 245 | "source": [ 246 | "[Content-Based Filtering in Machine Learning\n", 247 | "](https://thecleverprogrammer.com/2021/02/10/content-based-filtering-in-machine-learning/)" 248 | ] 249 | } 250 | ] 251 | } -------------------------------------------------------------------------------- /Recommender System/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Stress_Detection_with_Machine_Learning.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "toc_visible": true, 8 | "authorship_tag": "ABX9TyOWaAwXLNQm+0Stw1VO1zKT", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "id": "p8L3qgpH0zZg" 35 | }, 36 | "outputs": [], 37 | "source": [] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "source": [ 42 | "#**Referebces**" 43 | ], 44 | "metadata": { 45 | "id": "6nzF6BZf1Kdy" 46 | } 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "source": [ 51 | "[1-Stress Detection with Machine Learning](https://thecleverprogrammer.com/2021/12/20/stress-detection-with-machine-learning/)" 52 | ], 53 | "metadata": { 54 | "id": "BCrOn6Sc1SZC" 55 | } 56 | } 57 | ] 58 | } -------------------------------------------------------------------------------- /Text_Preprocessing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyPpgk0B2xCfTveVR1RZFlOR", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# **Introduction**" 33 | ], 34 | "metadata": { 35 | "id": "BXUn_-wsT7P8" 36 | } 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "source": [ 41 | "# **Install requirements**" 42 | ], 43 | "metadata": { 44 | "id": "sriupXN0UBcA" 45 | } 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": { 51 | "colab": { 52 | "base_uri": "https://localhost:8080/" 53 | }, 54 | "id": "jysi-ewXToZu", 55 | "outputId": "55cf98f0-8015-4954-b329-1bcbdd5ab854" 56 | }, 57 | "outputs": [ 58 | { 59 | "output_type": "stream", 60 | "name": "stdout", 61 | "text": [ 62 | "Collecting numpy==1.19.5\n", 63 | " Downloading numpy-1.19.5.zip (7.3 MB)\n", 64 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.3/7.3 MB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 65 | "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", 66 | " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "# To install only the requirements of this notebook, uncomment the lines below and run this cell\n", 72 | "\n", 73 | "# ===========================\n", 74 | "\n", 75 | "!pip install numpy==1.19.5\n", 76 | "!pip install nltk==3.2.5\n", 77 | "!pip install spacy==2.2.4\n", 78 | "\n", 79 | "# ===========================" 80 | ] 81 | } 82 | ] 83 | } -------------------------------------------------------------------------------- /Time Series Forecasting/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chatbot_in_Healthcare.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyPaJ7mTEjZiFxoIqJ9a1o1P", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "id": "hGiBemzytPov" 34 | }, 35 | "outputs": [], 36 | "source": [] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "source": [ 41 | "# **References**" 42 | ], 43 | "metadata": { 44 | "id": "va5EpWRztVn8" 45 | } 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "source": [ 50 | "[1-healthcare-chatbot](https://github.com/itachi9604/healthcare-chatbot/treemaster)" 51 | ], 52 | "metadata": { 53 | "id": "rJ2dh1JptaQ0" 54 | } 55 | } 56 | ] 57 | } -------------------------------------------------------------------------------- /emo.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dr-mushtaq/Projects/28f8dc0e8a0500af4610121178b70b5efedb87ee/emo.jfif -------------------------------------------------------------------------------- /emo2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dr-mushtaq/Projects/28f8dc0e8a0500af4610121178b70b5efedb87ee/emo2.jpg -------------------------------------------------------------------------------- /linkedIn_auto_jobs_applier_with_AI.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "toc_visible": true, 8 | "authorship_tag": "ABX9TyP3M3TgsEd7IXgNnkDAxSmU", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "id": "kSYicTJZJlF2" 35 | }, 36 | "outputs": [], 37 | "source": [] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "source": [ 42 | "# **References**" 43 | ], 44 | "metadata": { 45 | "id": "baEjpgQ-J_Kl" 46 | } 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "source": [ 51 | "[1-linkedIn_auto_jobs_applier_with_AI](https://github.com/feder-cr/linkedIn_auto_jobs_applier_with_AI/tree/main)" 52 | ], 53 | "metadata": { 54 | "id": "EAWoMpHIKDXO" 55 | } 56 | } 57 | ] 58 | } --------------------------------------------------------------------------------