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

[Bug]: Classification Model always predicting 0 #217

Open
1 task done
yc-um opened this issue Nov 2, 2023 · 1 comment
Open
1 task done

[Bug]: Classification Model always predicting 0 #217

yc-um opened this issue Nov 2, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@yc-um
Copy link

yc-um commented Nov 2, 2023

Contact Details

yhcho@umich.edu

Short description of the problem here.

Hi, I built a classification model based on the hybrid structural model learned from a dataset with 6 features and ~40k records following the tutorial, Evaluated the model on the test set, and got 0 for precision and recall for class 1. I tried constructing the model with different parameters, but this won't seem to fix the issue and I keep getting 0 for precision and recall, even though the full dataset includes ~20% of class 1. What might be wrong here? I would appreciate any feedback or suggestions.

{'Target_0': {'precision': 0.8104828298476633, 'recall': 1.0, 'f1-score': 0.8953223046206502, 'support': 3139.0}, 'Target_1': {'precision': 0.0, 'recall': 0.0, 'f1-score': 0.0, 'support': 734.0}, 'accuracy': 0.8104828298476633, 'macro avg': {'precision': 0.40524141492383164, 'recall': 0.5, 'f1-score': 0.4476611523103251, 'support': 3873.0}, 'weighted avg': {'precision': 0.6568824174778763, 'recall': 0.8104828298476633, 'f1-score': 0.7256433550746763, 'support': 3873.0}}

CausalNex Version

0.12.1

Python Version

3.9.18

Relevant code snippet

sm = from_pandas(df, tabu_edges=[("Target","X1"),("Target","X2"),("Target","X3"),("Target","X4"),("Target","X5")], w_threshold=0.8)
#MANUAL ADJUSTMENT OF CONNECTIONS
sm.add_edge("X1", "Target")
sm.add_edge("X2", "X3")

from causalnex.network import BayesianNetwork

bn = BayesianNetwork(sm)

discretised_data = df.copy()

columns_to_bin = ['X1', 'X2', 'X3', 'X4', 'X5']

# Bin input data
num_bins = 5
bin_range = (0, 10)

# Loop through the columns and apply qcut to create buckets
for column in columns_to_bin:
    discretised_data[f'{column}'] = pd.cut(discretised_data[column], bins=num_bins, labels=False, retbins=False, right=True, include_lowest=True)


# Split 90% train and 10% test
from sklearn.model_selection import train_test_split
train, test = train_test_split(discretised_data, train_size=0.9, test_size=0.1, random_state=7)

bn = bn.fit_node_states(discretised_data)
bn = bn.fit_cpds(train, method="BayesianEstimator", bayes_prior="K2")

from causalnex.evaluation import classification_report
classification_report(bn, test, "Target")

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@yc-um yc-um added the bug Something isn't working label Nov 2, 2023
@SarthakNikhal
Copy link

Can I work on this issue?

Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt
Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement
Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* Replacing Pygraphviz with Pyvis

* Replacing Pygraphviz with Pyvis

* Replacing Pygraphviz with Pyvis

* temp (#242)

* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* adding cython to config

* adding cython to config

* adding cython to config

* adding cython to config

---------

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* temp (#242)

* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release Notes

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Jimmy-INL pushed a commit to Jimmy-INL/causalnex that referenced this issue May 17, 2024
* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Replacing Pygraphviz with Pyvis (mckinsey#237)

* Replacing Pygraphviz with Pyvis

* Replacing Pygraphviz with Pyvis

* Replacing Pygraphviz with Pyvis

* temp (#242)

* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* adding cython to config

* adding cython to config

* adding cython to config

* adding cython to config

---------

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* Replace pygraphviz plotting with pyvis (mckinsey#228)

* initial draft for pyvis plotting

* modify edge length and mass for strong style and return pyvis object

* add pytests and fix sklearn plotting function

* update to include pyvis in requirements

* add in notebook check tests for test_plot_dag

* downgrade pyvis for compatibility

* update to latest plotting functions

* update requirements to exclude pygraphviz

* upgrading ipython

* moving ipython as main requirement

* simplify plot_structure function

* remove unused code and add test cases when needed

* reset pyvis version to see if .show() is working on v0.3.1

* set ipython and python versions

* undo previous change (ipython version change)

* remove ipython version from requirements

* re-add ipython version to requirements

* change ipython+python version

* undo change ipython+python version

* check for different ipython versions

* add quotation marks in requirements.txt

* revert back to ipython>=8.10.0

* try out ipython requirements from kedro

* revert back to ipython>=8.10

* change ipython requirements to successfully create environments

* Updated pyvis tutorials (mckinsey#232)

* update tutorials and adjust default values to improve output

* allow user to change layout in plot_dag function before calling .show()

* display df without dataframe_image

* fix dataframe_image No such file or directory

* remove one cell beacause unused

* incorporate windows solution from Kyle

* fix typo

* change plot_structure documentation

* change plot_dag documentation

* check and correct all notebooks

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* refactoring plot syntax and changing logic in plot_dag

* addressing Gabriel's comments

* removing unused IPython conditional import

* refactoring code to use display

* Docs - update 01-tutorial

* updating first tutotiral

* updating plotting tutorial

* updating plotting tutorial

* updating display api

* fixing bug - displau

* fixing notebooks

* fixing notebooks

* fixing notebooks

* fixing notebooks

* Replacing Pygraphviz with Pyvis

* Replacing Pygraphviz with Pyvis

* Replacing Pygraphviz with Pyvis

* updating pyvis version

* updating notebook

* Richard Comments - batch 1

* Update tests/test_plotting.py

Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>

* Update tests/test_plotting.py

Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>

* Richard Comments - batch 2

* adjust node color test to include background color

* docs

* docs

* test

* fixing mdlp with cython

* fixing mdlp with cython

* test

* removing cython from requirements

* adding cython to config

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>

* fix: requirements.txt to reduce vulnerabilities (#247)

The following vulnerabilities are fixed by pinning transitive dependencies:
- https://snyk.io/vuln/SNYK-PYTHON-IPYTHON-3318382

Co-authored-by: snyk-bot <snyk-bot@snyk.io>

* test

* Release Notes 0.12.0 (#249)

* temp (#242)

* Limiting numpy version (mckinsey#217)

* adding line on yml - no effect

* adding line on yml - no effect

* changing req.txt

* changing req.txt

* changing req.txt

* adding setuptools requirement (mckinsey#218)

* adding setuptools requirement

* adding setuptools requirement

* update dictionaries to pass linting (mckinsey#230)

* Refactor/unlock numpy kl (mckinsey#235)

* unlocking numpy

* unlocking numpy

* unlocking numpy

* dependency fixes for docs and linters

* requirement fixes : numpy <1.24 for all python versions

---------

Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>

* Simplifying requirements - Numpy version range (mckinsey#236)

* Remove python 3.6 and 3.7 support (mckinsey#234)

* remove python 3.6 and 3.7 support

* update documentation

* remove comment regarding ignoring a warning when running `make build-docs`

* removing ipython from test requiremnets

* Update README.md

Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release Notes

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: Serene Yeo <118331898+SereneYeo@users.noreply.github.com>
Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>
Co-authored-by: Leon Nallamuthu <38660312+leonnallamuthu@users.noreply.github.com>
Co-authored-by: snyk-bot <snyk-bot@snyk.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants