11import warnings
2+
23import numpy as np
34import pandas as pd
45from sklearn .base import BaseEstimator
5- from sklearn .utils .validation import check_consistent_length
66from sklearn .utils .multiclass import type_of_target
7+ from sklearn .utils .validation import check_consistent_length
78
89
910class SoloModel (BaseEstimator ):
@@ -92,23 +93,23 @@ def fit(self, X, y, treatment, estimator_fit_params=None):
9293 if self .method == 'dummy' :
9394 if isinstance (X , np .ndarray ):
9495 X_mod = np .column_stack ((X , treatment ))
95- elif isinstance (X , pd .core . frame . DataFrame ):
96+ elif isinstance (X , pd .DataFrame ):
9697 X_mod = X .assign (treatment = treatment )
9798 else :
9899 raise TypeError ("Expected numpy.ndarray or pandas.DataFrame in training vector X, got %s" % type (X ))
99100
100101 if self .method == 'treatment_interaction' :
101102 if isinstance (X , np .ndarray ):
102103 X_mod = np .column_stack ((X , np .multiply (X , np .array (treatment ).reshape (- 1 , 1 )), treatment ))
103- elif isinstance (X , pd .core . frame . DataFrame ):
104+ elif isinstance (X , pd .DataFrame ):
104105 X_mod = pd .concat ([
105106 X ,
106107 X .apply (lambda x : x * treatment )
107108 .rename (columns = lambda x : str (x ) + '_treatment_interaction' )
108- ], axis = 1 )\
109+ ], axis = 1 ) \
109110 .assign (treatment = treatment )
110111 else :
111- raise TypeError ("Expected numpy.ndarray or pandas.DataFrame in training vector X, got %s" % type (X ))
112+ raise TypeError ("Expected numpy.ndarray or pandas.DataFrame in training vector X, got %s" % type (X ))
112113
113114 self ._type_of_target = type_of_target (y )
114115
@@ -132,7 +133,7 @@ def predict(self, X):
132133 if isinstance (X , np .ndarray ):
133134 X_mod_trmnt = np .column_stack ((X , np .ones (X .shape [0 ])))
134135 X_mod_ctrl = np .column_stack ((X , np .zeros (X .shape [0 ])))
135- elif isinstance (X , pd .core . frame . DataFrame ):
136+ elif isinstance (X , pd .DataFrame ):
136137 X_mod_trmnt = X .assign (treatment = np .ones (X .shape [0 ]))
137138 X_mod_ctrl = X .assign (treatment = np .zeros (X .shape [0 ]))
138139 else :
@@ -142,18 +143,18 @@ def predict(self, X):
142143 if isinstance (X , np .ndarray ):
143144 X_mod_trmnt = np .column_stack ((X , np .multiply (X , np .ones ((X .shape [0 ], 1 ))), np .ones (X .shape [0 ])))
144145 X_mod_ctrl = np .column_stack ((X , np .multiply (X , np .zeros ((X .shape [0 ], 1 ))), np .zeros (X .shape [0 ])))
145- elif isinstance (X , pd .core . frame . DataFrame ):
146+ elif isinstance (X , pd .DataFrame ):
146147 X_mod_trmnt = pd .concat ([
147148 X ,
148149 X .apply (lambda x : x * np .ones (X .shape [0 ]))
149150 .rename (columns = lambda x : str (x ) + '_treatment_interaction' )
150- ], axis = 1 )\
151+ ], axis = 1 ) \
151152 .assign (treatment = np .ones (X .shape [0 ]))
152153 X_mod_ctrl = pd .concat ([
153154 X ,
154155 X .apply (lambda x : x * np .zeros (X .shape [0 ]))
155156 .rename (columns = lambda x : str (x ) + '_treatment_interaction' )
156- ], axis = 1 )\
157+ ], axis = 1 ) \
157158 .assign (treatment = np .zeros (X .shape [0 ]))
158159 else :
159160 raise TypeError ("Expected numpy.ndarray or pandas.DataFrame in training vector X, got %s" % type (X ))
@@ -208,6 +209,7 @@ class ClassTransformation(BaseEstimator):
208209 .. _ClassTransformation in documentation:
209210 https://scikit-uplift.readthedocs.io/en/latest/api/models.html#class-transformation
210211 """
212+
211213 def __init__ (self , estimator ):
212214 self .estimator = estimator
213215 self ._type_of_target = None
0 commit comments