Skip to content

Conversation

@jeongyoonlee
Copy link
Collaborator

Summary

Implements BaseDRClassifier class to address issue #819 by providing a DR-learner that outputs probabilities for binary classification problems, similar to other S/T/X learner classifiers.

Test plan

  • Added comprehensive tests in test_meta_learners.py
  • Verified probability outputs are in [0,1] range
  • Tested both single learner and separate learner configurations
  • Ensured treatment effects are properly estimated
  • Followed existing classifier implementation patterns

Changes

Core Implementation

  • Added BaseDRClassifier class in causalml/inference/meta/drlearner.py
    • Inherits from BaseDRLearner for consistency
    • Uses predict_proba() for outcome models to return probabilities
    • Maintains doubly robust estimation framework
    • Supports flexible learner configuration

API Integration

  • Updated module exports in causalml/inference/meta/__init__.py
  • Added comprehensive tests in tests/test_meta_learners.py

Key Features

  • Probability outputs: Uses predict_proba()[:, 1] for binary classification
  • Classification metrics: Integrates with classification_metrics
  • Consistent API: Follows same pattern as other classifier implementations
  • Flexible configuration: Supports both single and separate learners

Usage Example

from causalml.inference.meta import BaseDRClassifier
from sklearn.linear_model import LogisticRegression, LinearRegression

# Initialize with binary classifiers for outcomes
learner = BaseDRClassifier(
    learner=LogisticRegression(),  # Uses predict_proba() for probabilities
    treatment_effect_learner=LinearRegression()
)

# Fit and predict treatment effects
te = learner.fit_predict(X=X, treatment=treatment, y=y)

# Get probability components
te, yhat_cs, yhat_ts = learner.fit_predict(
    X=X, treatment=treatment, y=y, return_components=True
)

Fixes #819

🤖 Generated with Claude Code

jeongyoonlee and others added 4 commits July 15, 2025 15:26
Implements BaseDRClassifier class to address issue #819 by providing
a DR-learner that outputs probabilities for binary classification problems,
similar to other S/T/X learner classifiers.

Key features:
- Uses predict_proba() for outcome models to return probabilities
- Maintains doubly robust estimation framework
- Supports both single learner and separate outcome/effect learners
- Includes comprehensive tests with classification data
- Follows existing classifier implementation patterns

Fixes #819

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add black as a dependency in pyproject.toml
- Format test_meta_learners.py with black
- Fix code style issues for CI/CD pipeline

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Update all commands to use uv instead of pip/pytest
- Add mandatory black formatting before push workflow
- Include complete development workflow with linting steps
- Emphasize code quality requirements for CI/CD

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Remove CLAUDE.md and .claude/ from git tracking
- Add Claude Code artifacts to .gitignore
- Keep repository clean of development tooling files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements BaseDRClassifier to provide doubly robust learning with probability outputs for binary classification problems, addressing issue #819. The implementation follows the existing pattern of other meta-learner classifiers in the codebase.

Key changes:

  • Added BaseDRClassifier class that uses predict_proba() for probabilistic binary classification
  • Updated module exports to include the new classifier
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

File Description
causalml/inference/meta/drlearner.py Implements the core BaseDRClassifier class with probabilistic prediction methods
causalml/inference/meta/init.py Exports the new BaseDRClassifier class
tests/test_meta_learners.py Adds comprehensive tests for the new classifier functionality
pyproject.toml Adds black dependency for code formatting

- Improve docstring completeness with detailed parameter descriptions
- Clarify usage of treatment/y parameters for classification metrics
- Explain return_components output format with probability details
- Separate DR learner imports for better readability
- Maintain API consistency with other meta-learners

Addresses comments in #844

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@jeongyoonlee
Copy link
Collaborator Author

Thank you for the detailed review! I've addressed the comments as follows:

Documentation Improvements

  • Enhanced docstring completeness: Added detailed descriptions for all parameters including p, return_components, treatment, and y
  • Clarified parameter usage: Explained that treatment and y are used for computing classification metrics when both are provided
  • Detailed return values: Specified the format of returned probability dictionaries when return_components=True

Import Style Improvement

  • Separated import lines: Split the DR learner imports into individual lines for better readability and minimal diff impact as suggested

🤔 API Consistency Decision

Regarding the first comment about removing treatment and y parameters - I've decided to maintain the current API for the following reasons:

  1. Consistency with parent class: BaseDRLearner.predict() uses the exact same signature
  2. Consistency across all meta-learners: BaseSLearner, BaseTLearner, BaseXLearner, BaseRLearner, and all their classifier variants use this same pattern
  3. Functional purpose: The treatment and y parameters serve a legitimate purpose - they enable automatic computation of classification metrics when both are provided, which is valuable for model validation
  4. Backward compatibility: Changing the API would break compatibility with existing code that expects this signature

The current implementation follows the established pattern across the entire CausalML meta-learner ecosystem, where optional parameters enable additional functionality without breaking the core prediction workflow.

All changes have been applied with proper black formatting. The implementation now provides comprehensive documentation while maintaining full API consistency with the existing codebase.

@jeongyoonlee jeongyoonlee merged commit 1a96e01 into master Jul 16, 2025
14 checks passed
@jeongyoonlee jeongyoonlee deleted the jeong/fix_819 branch July 16, 2025 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why not BaseDRClassifier?

3 participants