Index


Sr. No. Date Program List Pg. No Sign
Intro to Pandas DataFrame

Session 1 (Intro to Pandas DataFrame)


  1. How to Start Google Colab

    1. Open Chrome: Launch the Google Chrome browser on your computer.
    2. Login: Sign in to your Google account.
    3. Search for Colab: In the search bar, type "Google Colab" and navigate to the Colab website.
    4. Create New Notebook: Click on "New Notebook" to create a new project.
  2. How to Read CSV Datasets with Different Methods

    1. Method 1: Uploading Files Directly

      1. You can upload CSV files from your local machine.

        from google.colab import files
        import pandas as pd
        
        # Upload the CSV file
        upload = files.upload()
        
        # Load the uploaded CSV file into a DataFrame
        df = pd.read_csv('purchased_data.csv')
        print(df.to_string())
        
    2. Method 2: Loading Data from a URL

      1. You can load datasets directly from a URL, such as a GitHub raw link.

        url = "<https://raw.githubusercontent.com/YBI-Foundation/Dataset/refs/heads/main/Online%20Purchase.csv>"
        df2 = pd.read_csv(url)
        print(df2.to_string())
        
    3. Method 3: Using an Alternative Upload Method

      1. You can also read a CSV file by specifying its path.

        df = pd.read_csv('/content/purchased_data.csv', header=None)
        print(df.to_string())
        
  3. Association Rule Learning

    1. Step 1: Prepare the Data

      1. To perform association rule learning, you need to convert your DataFrame into a format suitable for the Apriori algorithm.

        import numpy as np
        
        # Convert DataFrame to records for association rule learning
        records = []
        for i in range(len(df)):
            row = []
            for j in range(len(df.columns)):
                value = df.values[i, j]
                if pd.notna(value):
                    row.append(str(value))
            records.append(row)
        
    2. Step 2: Install Required Libraries

      1. If you haven't already, install the apyori library.

        !pip install apyori
        
        
    3. Step 3: Apply the Apriori Algorithm

      1. Now you can use the Apriori algorithm to find association rules.

        from apyori import apriori
        
        # Perform Apriori with specified support and confidence
        association_rule = apriori(records, min_support=0.5, min_confidence=0.75)
        association_result = list(association_rule)
        print(association_result)
        

  4. Applying Association Rule Learning to a Different Dataset

    1. You can repeat the process for another dataset (e.g., Fashion.csv) with different support and confidence thresholds.

      # Load another dataset
      df2 = pd.read_csv('/content/Fashion.csv', header=None)
      print(df2.to_string())
      
      # Prepare records for the new dataset
      records2 = []
      for i in range(len(df2)):
          row = []
          for j in range(len(df2.columns)):
              value = df2.values[i, j]
              if pd.notna(value):
                  row.append(str(value))
          records2.append(row)
      
      # Apply the Apriori algorithm to the new dataset
      association_rule2 = apriori(records2, min_support=0.4, min_confidence=0.6)
      association_result2 = list(association_rule2)
      print(association_result2)
      

Session 2 (Association Rule)