Created
February 7, 2023 15:46
-
-
Save GarrettMooney/369cc23bfc3b23e04b212a5784a9cb0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union | |
import numpy as np | |
import pandas as pd | |
def create_sample_weights( | |
y_train: np.ndarray, | |
X_train: Union[np.ndarray, pd.DataFrame] | |
) -> pd.Series: | |
y_series = pd.DataFrame({"y": y_train})["y"] | |
class_weights = len(X_train) / y_series.value_counts() | |
sample_weights = y_series.map(class_weights) | |
return sample_weights | |
"""Example: | |
>>> sample_weights = create_sample_weights(y_train, X_train) | |
>>> model = HistGradientBoostingClassifier(**params) | |
>>> model.fit(X_train, y_train, sample_weight=sample_weights) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment