Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 19, 2024
1 parent 8d24755 commit 3d90ab0
Show file tree
Hide file tree
Showing 84 changed files with 1,071 additions and 1,316 deletions.
6 changes: 3 additions & 3 deletions econml/_cate_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from copy import deepcopy
from warnings import warn
from .inference import BootstrapInference
from .utilities import (tensordot, ndim, reshape, shape, parse_final_model_params, get_feature_names_or_default,
inverse_onehot, Summary, get_input_columns, check_input_arrays, jacify_featurizer)
from .utilities import (ndim, shape, parse_final_model_params, get_feature_names_or_default,
inverse_onehot, Summary, get_input_columns, check_input_arrays)
from .inference import StatsModelsInference, StatsModelsInferenceDiscrete, LinearModelFinalInference, \
LinearModelFinalInferenceDiscrete, NormalInferenceResults, GenericSingleTreatmentModelFinalInference, \
LinearModelFinalInferenceDiscrete, GenericSingleTreatmentModelFinalInference, \
GenericModelFinalInferenceDiscrete
from ._shap import _shap_explain_cme, _shap_explain_joint_linear_model_cate
from .dowhy import DoWhyWrapper
Expand Down
1 change: 0 additions & 1 deletion econml/_ensemble/_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import numpy as np
from abc import ABCMeta, abstractmethod
from sklearn.base import BaseEstimator, clone
from sklearn.utils import check_random_state
from joblib import effective_n_jobs
from packaging.version import parse
import sklearn
Expand Down
14 changes: 4 additions & 10 deletions econml/_ortho_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,22 @@ class in this module implements the general logic in a very versatile way
"""

import copy
from collections import namedtuple
from warnings import warn
from abc import abstractmethod
from typing import List, Union
import inspect
from collections import defaultdict
import re

import numpy as np
from sklearn.base import clone
from sklearn.model_selection import KFold, StratifiedKFold, GroupKFold, StratifiedGroupKFold, check_cv
from sklearn.preprocessing import (FunctionTransformer, LabelEncoder,
OneHotEncoder)
from sklearn.preprocessing import (LabelEncoder)
from sklearn.utils import check_random_state

from ._cate_estimator import (BaseCateEstimator, LinearCateEstimator,
TreatmentExpansionMixin)
from .inference import BootstrapInference
from .utilities import (_deprecate_positional, check_input_arrays,
cross_product, filter_none_kwargs, one_hot_encoder, strata_from_discrete_arrays,
inverse_onehot, jacify_featurizer, ndim, reshape, shape, transpose)
from .utilities import (check_input_arrays,
filter_none_kwargs, one_hot_encoder, strata_from_discrete_arrays,
jacify_featurizer, reshape, shape)
from .sklearn_extensions.model_selection import ModelSelector

try:
Expand Down
3 changes: 1 addition & 2 deletions econml/cate_interpreter/_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import abc
import numbers
import numpy as np
import sklearn
from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier
from sklearn.tree import DecisionTreeRegressor
from sklearn.utils import check_array
from ..policy import PolicyTree
from .._tree_exporter import (_SingleTreeExporterMixin,
Expand Down
2 changes: 1 addition & 1 deletion econml/data/dynamic_panel_dgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class SemiSynthetic:

def create_instance(self):
# get new covariance matrix
self.cov_new = joblib.load(os.path.join(dir, f"input_dynamicdgp/cov_new.jbl"))
self.cov_new = joblib.load(os.path.join(dir, "input_dynamicdgp/cov_new.jbl"))

# get coefs
self.index = ["proxy1", "proxy2", "proxy3", "proxy4",
Expand Down
6 changes: 1 addition & 5 deletions econml/dml/_rlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@

from abc import abstractmethod
import numpy as np
import copy
from warnings import warn

from ..sklearn_extensions.model_selection import ModelSelector
from ..utilities import (shape, reshape, ndim, hstack, filter_none_kwargs, _deprecate_positional)
from sklearn.linear_model import LinearRegression
from sklearn.base import clone
from ..utilities import (filter_none_kwargs)
from .._ortho_learner import _OrthoLearner


Expand Down
11 changes: 3 additions & 8 deletions econml/dml/causal_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
from warnings import warn

import numpy as np
from sklearn.linear_model import LogisticRegressionCV
from sklearn.base import clone, BaseEstimator
from sklearn.preprocessing import FunctionTransformer
from sklearn.pipeline import Pipeline
from sklearn.base import clone
from sklearn.model_selection import train_test_split
from itertools import product
from .dml import _BaseDML
from .dml import _make_first_stage_selector
from ..sklearn_extensions.linear_model import WeightedLassoCVWrapper
from ..sklearn_extensions.model_selection import WeightedStratifiedKFold
from ..inference import NormalInferenceResults
from ..inference._inference import Inference
from ..utilities import (add_intercept, shape, check_inputs, check_input_arrays,
_deprecate_positional, cross_product, Summary)
from ..utilities import (shape, check_input_arrays,
cross_product, Summary)
from ..grf import CausalForest, MultiOutputGRF
from .._cate_estimator import LinearCateEstimator
from .._shap import _shap_explain_multitask_model_cate
Expand Down
25 changes: 7 additions & 18 deletions econml/dml/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,25 @@

import numpy as np
from sklearn.base import TransformerMixin, clone
from sklearn.exceptions import NotFittedError
from sklearn.linear_model import (ElasticNetCV, LassoCV, LogisticRegressionCV)
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import KFold, StratifiedKFold, check_cv
from sklearn.linear_model import (ElasticNetCV)
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import (FunctionTransformer, LabelEncoder,
OneHotEncoder)
from sklearn.preprocessing import (FunctionTransformer)
from sklearn.utils import check_random_state
import copy

from .._ortho_learner import _OrthoLearner
from ._rlearner import _RLearner
from .._cate_estimator import (DebiasedLassoCateEstimatorMixin,
ForestModelFinalCateEstimatorMixin,
LinearModelFinalCateEstimatorMixin,
StatsModelsCateEstimatorMixin,
LinearCateEstimator)
from ..inference import StatsModelsInference, GenericSingleTreatmentModelFinalInference
from ..inference import GenericSingleTreatmentModelFinalInference
from ..sklearn_extensions.linear_model import (MultiOutputDebiasedLasso,
StatsModelsLinearRegression,
WeightedLassoCVWrapper)
from ..sklearn_extensions.model_selection import WeightedStratifiedKFold
from ..utilities import (_deprecate_positional, add_intercept,
StatsModelsLinearRegression)
from ..utilities import (add_intercept,
broadcast_unit_treatments, check_high_dimensional,
cross_product, deprecated,
hstack, inverse_onehot, ndim, reshape,
reshape_treatmentwise_effects, shape, transpose,
get_feature_names_or_default, filter_none_kwargs)
cross_product, hstack, inverse_onehot, reshape_treatmentwise_effects, shape, get_feature_names_or_default, filter_none_kwargs)
from .._shap import _shap_explain_model_cate
from ..sklearn_extensions.model_selection import get_selector, ModelSelector, SingleModelSelector
from ..sklearn_extensions.model_selection import get_selector, SingleModelSelector


def _combine(X, W, n_samples):
Expand Down
11 changes: 3 additions & 8 deletions econml/dr/_drlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,20 @@
"""

from warnings import warn
from copy import deepcopy

import numpy as np
from sklearn.base import clone
from sklearn.linear_model import (LassoCV, LinearRegression,
LogisticRegressionCV)
from sklearn.ensemble import RandomForestRegressor


from .._ortho_learner import _OrthoLearner
from .._cate_estimator import (DebiasedLassoCateEstimatorDiscreteMixin, BaseCateEstimator,
ForestModelFinalCateEstimatorDiscreteMixin,
from .._cate_estimator import (DebiasedLassoCateEstimatorDiscreteMixin, ForestModelFinalCateEstimatorDiscreteMixin,
StatsModelsCateEstimatorDiscreteMixin, LinearCateEstimator)
from ..inference import GenericModelFinalInferenceDiscrete
from ..grf import RegressionForest
from ..sklearn_extensions.linear_model import (
DebiasedLasso, StatsModelsLinearRegression, WeightedLassoCVWrapper)
DebiasedLasso, StatsModelsLinearRegression)
from ..sklearn_extensions.model_selection import ModelSelector, SingleModelSelector, get_selector
from ..utilities import (_deprecate_positional, check_high_dimensional,
from ..utilities import (check_high_dimensional,
filter_none_kwargs, inverse_onehot, get_feature_names_or_default)
from .._shap import _shap_explain_multitask_model_cate, _shap_explain_model_cate

Expand Down
1 change: 0 additions & 1 deletion econml/federated_learning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) PyWhy contributors. All rights reserved.
# Licensed under the MIT License.

import numpy as np
from sklearn import clone

from econml.utilities import check_input_arrays
Expand Down
8 changes: 4 additions & 4 deletions econml/grf/_base_grf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
# All rights reserved.

import numbers
from warnings import catch_warnings, simplefilter, warn
from warnings import warn
from abc import ABCMeta, abstractmethod
import numpy as np
import threading
from .._ensemble import (BaseEnsemble, _partition_estimators, _get_n_samples_subsample,
_accumulate_prediction, _accumulate_prediction_var, _accumulate_prediction_and_var,
_accumulate_prediction, _accumulate_prediction_and_var,
_accumulate_oob_preds)
from ..utilities import check_inputs, cross_product
from ..utilities import check_inputs
from ..tree._tree import DTYPE, DOUBLE
from ._base_grftree import GRFTree
from joblib import Parallel, delayed
from scipy.sparse import hstack as sparse_hstack
from sklearn.utils import check_random_state, compute_sample_weight
from sklearn.utils import check_random_state
from sklearn.utils.validation import _check_sample_weight, check_is_fitted
from sklearn.utils import check_X_y
import scipy.stats
Expand Down
3 changes: 0 additions & 3 deletions econml/grf/_base_grftree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
import numpy as np
from ._criterion import LinearMomentGRFCriterionMSE, LinearMomentGRFCriterion
from ..tree import BaseTree
from sklearn.model_selection import train_test_split
from sklearn.utils import check_array
from sklearn.utils import check_random_state
from sklearn.utils.validation import check_is_fitted
import copy

# =============================================================================
# Types and constants
Expand Down
1 change: 0 additions & 1 deletion econml/grf/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT License.

import numpy as np
from warnings import warn
from ..utilities import cross_product
from ._base_grf import BaseGRF
from ..utilities import check_inputs
Expand Down
2 changes: 0 additions & 2 deletions econml/inference/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from joblib import Parallel, delayed
from sklearn.base import clone
from scipy.stats import norm
from collections import OrderedDict
import pandas as pd


class BootstrapEstimator:
Expand Down
5 changes: 1 addition & 4 deletions econml/inference/_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
import pandas as pd
import scipy
from scipy.stats import norm
from statsmodels.iolib.table import SimpleTable

from ._bootstrap import BootstrapEstimator
from ..sklearn_extensions.linear_model import StatsModelsLinearRegression
from ..utilities import (Summary, _safe_norm_ppf, broadcast_unit_treatments,
cross_product, inverse_onehot, ndim,
parse_final_model_params, jacify_featurizer,
reshape_treatmentwise_effects, shape, filter_none_kwargs)
parse_final_model_params, reshape_treatmentwise_effects, shape, filter_none_kwargs)

"""Options for performing inference in estimators."""

Expand Down
13 changes: 5 additions & 8 deletions econml/iv/dml/_dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

import numpy as np
from sklearn.base import clone
from sklearn.linear_model import LinearRegression, LogisticRegressionCV
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import FunctionTransformer
from itertools import product

from ..._ortho_learner import _OrthoLearner
from ..._cate_estimator import LinearModelFinalCateEstimatorMixin, StatsModelsCateEstimatorMixin, LinearCateEstimator
from ...inference import StatsModelsInference, GenericSingleTreatmentModelFinalInference
from ...sklearn_extensions.linear_model import StatsModels2SLS, StatsModelsLinearRegression, WeightedLassoCVWrapper
from ...sklearn_extensions.model_selection import (ModelSelector, SingleModelSelector,
WeightedStratifiedKFold, get_selector)
from ...utilities import (_deprecate_positional, get_feature_names_or_default, filter_none_kwargs, add_intercept,
from ..._cate_estimator import LinearModelFinalCateEstimatorMixin, LinearCateEstimator
from ...sklearn_extensions.linear_model import StatsModels2SLS, StatsModelsLinearRegression
from ...sklearn_extensions.model_selection import (ModelSelector, SingleModelSelector)
from ...utilities import (get_feature_names_or_default, filter_none_kwargs, add_intercept,
cross_product, broadcast_unit_treatments, reshape_treatmentwise_effects, shape,
parse_final_model_params, deprecated, Summary)
parse_final_model_params, Summary)
from ...dml.dml import _make_first_stage_selector, _FinalWrapper
from ...dml._rlearner import _ModelFinal
from ..._shap import _shap_explain_joint_linear_model_cate, _shap_explain_model_cate
Expand Down
10 changes: 4 additions & 6 deletions econml/iv/dr/_dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import numpy as np
from sklearn.base import clone
from sklearn.linear_model import LinearRegression, LogisticRegressionCV
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import FunctionTransformer
from sklearn.dummy import DummyClassifier
Expand All @@ -25,13 +24,12 @@
from ..._cate_estimator import (StatsModelsCateEstimatorMixin, DebiasedLassoCateEstimatorMixin,
ForestModelFinalCateEstimatorMixin, GenericSingleTreatmentModelFinalInference,
LinearCateEstimator)
from ...inference import StatsModelsInference
from ...sklearn_extensions.linear_model import StatsModelsLinearRegression, DebiasedLasso, WeightedLassoCVWrapper
from ...sklearn_extensions.model_selection import ModelSelector, SingleModelSelector, WeightedStratifiedKFold
from ...utilities import (_deprecate_positional, add_intercept, filter_none_kwargs,
from ...sklearn_extensions.linear_model import StatsModelsLinearRegression, DebiasedLasso
from ...sklearn_extensions.model_selection import ModelSelector, SingleModelSelector
from ...utilities import (add_intercept, filter_none_kwargs,
inverse_onehot, get_feature_names_or_default, check_high_dimensional, check_input_arrays)
from ...grf import RegressionForest
from ...dml.dml import _make_first_stage_selector, _FinalWrapper
from ...dml.dml import _make_first_stage_selector
from ...iv.dml import NonParamDMLIV
from ..._shap import _shap_explain_model_cate

Expand Down
2 changes: 1 addition & 1 deletion econml/iv/nnet/_deepiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
from ..._cate_estimator import BaseCateEstimator
from ...utilities import check_input_arrays, _deprecate_positional, deprecated, MissingModule
from ...utilities import check_input_arrays, MissingModule
try:
import keras
from keras import backend as K
Expand Down
5 changes: 2 additions & 3 deletions econml/iv/sieve/_tsls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"""Provides a non-parametric two-stage least squares instrumental variable estimator."""

import numpy as np
from copy import deepcopy
from sklearn import clone
from sklearn.linear_model import LinearRegression
from ...utilities import (shape, transpose, reshape, cross_product, ndim, size,
_deprecate_positional, check_input_arrays)
from ..._cate_estimator import BaseCateEstimator, LinearCateEstimator
check_input_arrays)
from ..._cate_estimator import BaseCateEstimator
from numpy.polynomial.hermite_e import hermeval
from sklearn.base import TransformerMixin
from sklearn.preprocessing import PolynomialFeatures
Expand Down
7 changes: 2 additions & 5 deletions econml/metalearners/_metalearners.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"""

import numpy as np
import warnings
from .._cate_estimator import BaseCateEstimator, LinearCateEstimator, TreatmentExpansionMixin
from sklearn import clone
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.utils import check_array, check_X_y
from sklearn.preprocessing import OneHotEncoder, FunctionTransformer
from ..utilities import (check_inputs, check_models, broadcast_unit_treatments, reshape_treatmentwise_effects,
one_hot_encoder, inverse_onehot, transpose, _deprecate_positional)
from sklearn.utils import check_array
from ..utilities import (check_inputs, check_models, broadcast_unit_treatments, one_hot_encoder, inverse_onehot, transpose)
from .._shap import _shap_explain_model_cate


Expand Down
12 changes: 4 additions & 8 deletions econml/orf/_ortho_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,24 @@
For more details on these methods, see our paper [Oprescu2019]_.
"""

import abc
import inspect
import numpy as np
import warnings
from joblib import Parallel, delayed
from sklearn import clone
from scipy.stats import norm
from sklearn.exceptions import NotFittedError
from sklearn.linear_model import LassoCV, Lasso, LinearRegression, LogisticRegression, \
LogisticRegressionCV, ElasticNet
from sklearn.linear_model import LinearRegression, LogisticRegression, \
LogisticRegressionCV
from sklearn.model_selection import KFold, StratifiedKFold
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import OneHotEncoder, LabelEncoder, PolynomialFeatures, FunctionTransformer
from sklearn.utils import check_random_state, check_array, column_or_1d
from ..sklearn_extensions.linear_model import WeightedLassoCVWrapper
from .._cate_estimator import BaseCateEstimator, LinearCateEstimator, TreatmentExpansionMixin
from ._causal_tree import CausalTree
from ..inference import NormalInferenceResults
from ..inference._inference import Inference
from ..utilities import (one_hot_encoder, reshape, reshape_Y_T, MAX_RAND_SEED, check_inputs, _deprecate_positional,
cross_product, inverse_onehot, check_input_arrays, jacify_featurizer,
_RegressionWrapper, deprecated, ndim)
from ..utilities import (one_hot_encoder, reshape_Y_T, MAX_RAND_SEED, check_inputs, cross_product, check_input_arrays, jacify_featurizer,
_RegressionWrapper, ndim)
from sklearn.model_selection import check_cv
# TODO: consider working around relying on sklearn implementation details
from ..sklearn_extensions.model_selection import _cross_val_predict
Expand Down
Loading

0 comments on commit 3d90ab0

Please sign in to comment.