Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use BaseXClassifier properly ? #222

Closed
LucasDresl opened this issue Jul 31, 2020 · 3 comments
Closed

How to use BaseXClassifier properly ? #222

LucasDresl opened this issue Jul 31, 2020 · 3 comments

Comments

@LucasDresl
Copy link

LucasDresl commented Jul 31, 2020

Description

I am trying to implement BaseXClassifier for a classification setting and when i used BaseXClassifier.fit() on a binary dependant variable (y) throws ValueError: Unknown label type: 'continuous'

To Reproduce

from causalml.inference.meta import BaseXClassifier , BaseXRegressor , BaseXLearner
from causalml.dataset.classification import make_uplift_classification 

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LogisticRegression

df , features = make_uplift_classification(n_samples=1000,
                               treatment_name=['control', 'treatment1', 'treatment2', 'treatment3'],
                               y_name='conversion',
                               n_classification_features=10,
                               n_classification_informative=5,
                               n_classification_redundant=0,
                               n_classification_repeated=0,
                               n_uplift_increase_dict={'treatment1': 2, 'treatment2': 2, 'treatment3': 2},
                               n_uplift_decrease_dict={'treatment1': 0, 'treatment2': 0, 'treatment3': 0},
                               delta_uplift_increase_dict={'treatment1': 0.02, 'treatment2': 0.05, 'treatment3': 0.1},
                               delta_uplift_decrease_dict={'treatment1': 0., 'treatment2': 0., 'treatment3': 0.},
                               n_uplift_increase_mix_informative_dict={'treatment1': 1, 'treatment2': 1, 'treatment3': 1},
                               n_uplift_decrease_mix_informative_dict={'treatment1': 0, 'treatment2': 0, 'treatment3': 0},
                               positive_class_proportion=0.65,
                               random_seed=20190101)

df_train , df_test = train_test_split(df , test_size = 0.2 , random_state = 44)

learner = BaseXClassifier(learner=LogisticRegression(),
                          control_outcome_learner=LogisticRegression(),
                          treatment_outcome_learner=LogisticRegression(),
                          control_effect_learner=LogisticRegression(),
                          treatment_effect_learner=LogisticRegression(),
                          ate_alpha=.05,
                          control_name='control')

learner.fit(df_train[features].values ,
                 treatment = df_train['treatment_group_key'],
                 y = df_train['conversion'].values) 

Environment:

  • Mac
  • Python 3.6.9
  • pandas==1.0.5, sklearn==0.22.2

Expected behaviour
I was expecting to classifier fit because my y is binary (0 or 1)

@yungmsh
Copy link
Contributor

yungmsh commented Jul 31, 2020

Hey @LucasDresl thanks for the question- you need to supply a regressor model (e.g. LinearRegression) to the control_effect_learner and treatment_effect_learner arguments. FYI we're updating the API for next release whereby you just have to provide 2 models (instead of 4 currently), probably in a couple weeks.

@LucasDresl
Copy link
Author

Hey @yungmsh ! thank you very much :) got it !

@ppstacy ppstacy closed this as completed Aug 5, 2020
@zzlin1003
Copy link

Hi @yungmsh , can we use this BaseXClassifier to output the probability for each class, like the output of some sklearn classifier.predict_proba()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants