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

TypeError when calling add_edges with columns of type object #125

Open
AZeed18 opened this issue Dec 22, 2024 · 0 comments
Open

TypeError when calling add_edges with columns of type object #125

AZeed18 opened this issue Dec 22, 2024 · 0 comments

Comments

@AZeed18
Copy link

AZeed18 commented Dec 22, 2024

I have a BNClassifier class that inherits from HybridBN and ClassifierMixin

Its fit method includes add_edges method from HybridBN

I get the following error (with Hill Climbing only):

  File "<HIDE>", line 59, in fit
    self.add_edges(df, scoring_function=('BIC',), params={'init_edges': <HIDE>})
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/networks/base.py", line 193, in add_edges
    worker.build(
  File "<HIDE>/lib/python3.11/site-packages/bamt/builders/hc_builder.py", line 198, in build
    self.apply_group1(data=data, progress_bar=progress_bar, **self.params)
  File "<HIDE>/lib/python3.11/site-packages/bamt/builders/hc_builder.py", line 121, in apply_group1
    bn = hc_method(
         ^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/redef_HC.py", line 165, in hc
    cache[old_cols] = mutual_information(data[:, old_cols])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/redef_info_scores.py", line 130, in BIC_local
    log_score = log_lik_local(data, method=method)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/redef_info_scores.py", line 123, in log_lik_local
    mutual_information(data, method=method)
  File "<HIDE>/lib/python3.11/site-packages/bamt/mi_entropy_gauss.py", line 224, in mi_gauss
    return mi_gauss(loc_to_DataFrame(data), method, conditional)
                    ^^^^^^^^^^^^^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/preprocess/numpy_pandas.py", line 16, in loc_to_DataFrame
    nodes_type = get_type_numpy(data)
                 ^^^^^^^^^^^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/preprocess/numpy_pandas.py", line 50, in get_type_numpy
    all_row_is_integer = all(
                         ^^^^
  File "<HIDE>/lib/python3.11/site-packages/bamt/preprocess/numpy_pandas.py", line 51, in <genexpr>
    np.issubdtype(x, np.integer) or x.is_integer() for x in row
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<HIDE>/lib/python3.11/site-packages/numpy/core/numerictypes.py", line 417, in issubdtype
    arg1 = dtype(arg1).type
           ^^^^^^^^^^^
TypeError: Cannot interpret '39' as a data type

39 is the value of the second column (an np.dtypes.Int32DType column) in the first row

Datatypes in my DataFrame are:

  • np.dtypes.Float32DType for continuous data
  • np.dtypes.Int32DType for discrete numerical data
  • np.dtypes.ObjectDType for categorical data
@github-project-automation github-project-automation bot moved this to 📋 Backlog in BAMT backlog Dec 22, 2024
@AZeed18 AZeed18 changed the title Error when calling add_edges with columns of type object TypeError when calling add_edges Dec 22, 2024
@AZeed18 AZeed18 changed the title TypeError when calling add_edges TypeError when calling add_edges with columns of type object Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant