PyBNesian icon indicating copy to clipboard operation
PyBNesian copied to clipboard

Conditional independence tests with mixed data

Open kenneth-lee-ch opened this issue 6 months ago • 0 comments

Can someone show an example how to use this library to conduct conditional independence tests with mixed data? Suppose I have the following data. I am confused on how to use MutualInformation as it says it can take continuous and categorical data, but I got an error once I pass the df into it.

Set seed for reproducibility

Screenshot 2024-08-16 at 11 08 56 PM

import pandas as pd
import numpy as np
from pybnesian import MutualInformation

np.random.seed(42)

# Generate continuous data
data_size = 100
continuous_data_1 = np.random.normal(loc=50, scale=10, size=data_size)
continuous_data_2 = np.random.normal(loc=30, scale=5, size=data_size)

# Generate categorical data
categories = np.random.choice(['Category A', 'Category B', 'Category C'], size=data_size)

# Create DataFrame
df = pd.DataFrame({
    'Continuous_1': continuous_data_1,
    'Continuous_2': continuous_data_2,
    'Category': categories
})

kmi = MutualInformation(df=data)
Screenshot 2024-08-16 at 11 18 58 PM

kenneth-lee-ch avatar Aug 17 '24 02:08 kenneth-lee-ch