AnotherSamWilson / miceforest

Multiple Imputation with LightGBM in Python
MIT License
353 stars 31 forks source link

TypeError: __init__() got an unexpected keyword argument 'balanced_tree' #74

Closed LMS233 closed 1 year ago

LMS233 commented 1 year ago

When I passed in the parameter 'kernel.mice(2)', the above error occurred, which was caused by my data or the parameter setting?

LMS233 commented 1 year ago

The same problem occurs even if I use a publicly available data set

Python code: import miceforest as mf from sklearn.datasets import load_iris import pandas as pd import numpy as np

Load data and introduce missing values

iris = pd.concat(load_iris(as_frame=True,return_X_y=True),axis=1) iris['target'] = iris['target'].astype('category') iris_amp = mf.ampute_data(iris,perc=0.25,random_state=1991)

Create kernel.

kernel = mf.ImputationKernel( iris_amp, datasets=4, save_all_iterations=True, random_state=1991 )

Run the MICE algorithm for 3 iterations on each of the datasets

kernel.mice(3)

occurred: TypeError Traceback (most recent call last) Cell In[6], line 20 12 kernel = mf.ImputationKernel( 13 iris_amp, 14 datasets=4, 15 save_all_iterations=True, 16 random_state=1991 17 ) 19 # Run the MICE algorithm for 3 iterations on each of the datasets ---> 20 kernel.mice(3)

File d:\Tools\conda\envs\ml_3.8\lib\site-packages\miceforest\ImputationKernel.py:1189, in ImputationKernel.mice(self, iterations, verbose, variable_parameters, compile_candidates, kwlgb) 1186 mm_kwargs["hashed_seeds"] = None 1188 logger.set_start_time() -> 1189 imp_values = self.mean_match_scheme._mean_match( 1190 variable, objective, mm_kwargs 1191 ) 1192 logger.record_time(timed_event="mean_matching", **log_context) 1194 assert imp_values.shape == ( 1195 self.na_counts[variable], 1196 ), f"{variable} mean matching returned malformed array"

File d:\Tools\conda\envs\ml_3.8\lib\site-packages\miceforest\MeanMatchScheme.py:388, in MeanMatchScheme._mean_match(self, variable, objective, **kwargs) 383 assert oa in list( ... 41 bachelor_preds, k=mean_match_candidates, workers=-1 42 ) 44 # We can skip the random selection process if mean_match_candidates == 1

TypeError: init() got an unexpected keyword argument 'balanced_tree'

LMS233 commented 1 year ago

This problem pops up when miceforest==5.6.3 (pip install miceforest). This problem does not occur when I change to miceforest=5.6.0

AnotherSamWilson commented 1 year ago

You are probably running into this issue: https://github.com/AnotherSamWilson/miceforest/issues/35

LMS233 commented 1 year ago

Thank you very much. The problem has been solved.