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

KeyError because of mismatch between outcome and positive label in data file #1

Open
KasperFyhn opened this issue Oct 6, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@KasperFyhn
Copy link

KasperFyhn commented Oct 6, 2023

I get a KeyError in supervised_classification.py:77 which you seem to have anticipated.

In the block below, **report[pos_label] gives an error if your data file (as the one I got my hands on from you) contains 1's and 0's in the column corresponding to the outcome variable, e.g. political, instead of the actual positive label which the code seems to assume.

classifier.fit(X[train_index], y[train_index])
y_pred = classifier.predict(X[test_index])
report = classification_report(
    y[test_index], y_pred, output_dict=True
)
# The positive label is the same as the column name.
# But THIS MIGHT CHANGE so beware that then
# we have to relax the assumption in the next line.
pos_label = outcome
record = {
    "model": model,
    "outcome": outcome,
    "fold": i_fold,
    "accuracy": report["accuracy"],
    **report[pos_label],
}
records.append(record)

Looks like an easy fix.

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

3 participants