Language English हिंदी Text size

Step 8 of 15

Interactive Notebook 2: Probabilistic Reasoning & Naive Bayes Classifier

Hands-on Python experiments calculating Bayes Rule and categorizing community text messages automatically.

Welcome to Step 8! Now that you have mastered the basics of Jupyter code cells from Step 5 and learned about uncertainty in Chapter 3, this interactive notebook lets you experiment with probability and text classification hands-on.

Updating Beliefs with Bayes' Rule in Python

Real-world weather, agricultural data, and community signals are never 100% certain. In the first half of Notebook 2, you run Python code that implements Bayes' Rule (`P(A|B) = P(B|A)*P(A)/P(B)`).

You will input known weather probabilities—like how often dark clouds appear before a monsoon storm (Sunto)—and watch the computer instantly update the exact probability of rain when clouds are observed today.

Categorizing Village Messages with Naive Bayes

In the second half, you build a miniature Naive Bayes Classifier. When a community member sends a feedback message in plain text, how does an automated system know which department should handle it?

By counting keywords related to water (`pipe`, `well`, `naka`, `kyari`) versus electricity (`wire`, `pole`, `bijli`), your code automatically sorts real village sentences into the correct category.

How to Open and Run Notebook 2

There are two easy ways to run the notebook: on your own computer if Jupyter is installed, or free in the browser with Google Colab, where nothing needs to be installed. The steps for Google Colab:

  1. Download the notebook file with the button below.
  2. Open colab.research.google.com in your browser and sign in with a Google account.
  3. Click File, then Upload notebook, and choose the downloaded file loktech-notebook-1.ipynb.
  4. Read each text cell, and run each code cell by pressing the play button on its left (or Shift+Enter).
  5. Run the cells from top to bottom. Change the examples and run them again; nothing can break.

Download Notebook 2 - Probability (.ipynb) Download Notebook 2 - Hindi (.ipynb) Open Google Colab ↗