AnotherSamWilson / miceforest

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

AttributeError: module 'miceforest' has no attribute 'KernelDataSet' #5

Closed apavlo89 closed 3 years ago

apavlo89 commented 3 years ago

Hello,

I'm trying to impute missing values your miceforest for my database but I'm a bit at a loss how all this works. This is the code I have.

#miceforest
import miceforest as mf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

dataset = pd.read_csv('C:/Users/apavl/Dropbox/A+T/REEG/Mu_micro_var.csv')
dataset_list = list(dataset.columns)

# Create kernel. 
kds = mf.KernelDataSet(
  dataset,
  save_all_iterations=True,
  random_state=1991
)

# Run the MICE algorithm for 3 iterations
kds.mice(3)

# Return the completed kernel data
completed_data = kds.complete_data()

This results in the following error: AttributeError: module 'miceforest' has no attribute 'KernelDataSet'

What am I doing wrong? :/

AnotherSamWilson commented 3 years ago

Hmmm can you verify that you can run the following code:

cols = range(10)
rows = 2000
datdict = {f'S_{x}': np.random.randint(0,100000,rows) for x in cols}
dataset = pd.DataFrame(datdict)
dataset = mf.ampute_data(dataset,perc = 0.5)
kernel = mf.KernelDataSet(dataset)
kernel.mice(3,verbose=True,n_jobs=12)

Also can you verify the version of Python and miceforest you are using please.

docXmaier commented 3 years ago

The issue occurs when your script file has a file name like some module among the imported ones. Try renaming your script. See also: https://stackoverflow.com/questions/59762996/how-to-fix-attributeerror-partially-initialized-module