Skip to content

docs: use class_weight="balanced" in the logistic regression prediction tutorial #678

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

Merged
merged 4 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion samples/snippets/logistic_regression_prediction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,21 @@ def test_logistic_regression_prediction(random_model_id: str) -> None:
X = training_data.drop(columns=["income_bracket", "dataframe"])
y = training_data["income_bracket"]

census_model = bigframes.ml.linear_model.LogisticRegression()
census_model = bigframes.ml.linear_model.LogisticRegression(
# Balance the class labels in the training data by setting
# class_weight="balanced".
#
# By default, the training data is unweighted. If the labels
# in the training data are imbalanced, the model may learn to
# predict the most popular class of labels more heavily. In
# this case, most of the respondents in the dataset are in the
# lower income bracket. This may lead to a model that predicts
# the lower income bracket too heavily. Class weights balance
# the class labels by calculating the weights for each class in
# inverse proportion to the frequency of that class.
class_weight="balanced",
max_iterations=15,
)
census_model.fit(X, y)

census_model.to_gbq(
Expand Down