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

Explore estimator attribute exceptions #10

Open
Gnpd opened this issue Jun 13, 2024 · 1 comment
Open

Explore estimator attribute exceptions #10

Gnpd opened this issue Jun 13, 2024 · 1 comment
Assignees

Comments

@Gnpd
Copy link
Collaborator

Gnpd commented Jun 13, 2024

According to sklearn:

"Attributes that have been estimated from the data must always have a name ending with trailing underscore, for example the coefficients of some regression estimator would be stored in a coef_ attribute after fit has been called."

Those attributes can be easily obtained like so:

attribute_keys = [
        key
        for key in dir(model)
        if key.endswith("_")
        and not key.endswith("__")
    ]

However, in some estimators, we need other attributes that do not follow this convention to use predict/transform methods, like _n_threads in KMeans or _predict_1d and _x_mean in PLSRegression.

To circumvent this, we use a 'nearly all-in' approach that collects many other attributes we do not need in the final JSON file.

To maintain functionality while reducing the serialization of unnecessary attributes, we can build an exception dictionary collecting estimator attribute exceptions for each estimator.

@Gnpd Gnpd self-assigned this Jun 13, 2024
@Gnpd Gnpd added this to OpenModels Jun 13, 2024
@Gnpd Gnpd moved this to Backlog in OpenModels Jun 13, 2024
@Gnpd Gnpd moved this from Backlog to Ready in OpenModels Jun 13, 2024
@Gnpd
Copy link
Collaborator Author

Gnpd commented Nov 5, 2024

So far I have this exceptions:

# Dictionary of attribute exceptions
ATTRIBUTE_EXCEPTIONS: Dict[str, list] = {
    "BernoulliNB": [],
    "ComplementNB": [],
    # "DecisionTreeClassifier": [], # not suppoted
    # "DecisionTreeRegressor": [], # not suppoted
    "DummyClassifier": ["_strategy"],
    "GaussianNB": [],
    # "GradientBoostingClassifier": [], # not supported
    "GradientBoostingRegressor": [],
    # "Lasso": [], # not supported
    "LinearDiscriminantAnalysis": [],
    "LinearRegression": [],
    "LogisticRegression": [],
    "KMeans": ["_n_threads"],
    # "MLPClassifier": [], # not supported
    # "MLPRegressor": [], # not supported
    "MultinomialNB": [],
    "PCA": [],
    # "Perceptron": [], # not supported
    "PLSRegression": ["_x_mean", "_predict_1d"],
    "QuadraticDiscriminantAnalysis": [],
    # "RandomForestClassifier": [], # not supported
    # "RandomForestRegressor": [], # not supported
    "Ridge": [],
    "SVC": [
        "_sparse",
        "_n_support",
        "_dual_coef_",
        "_intercept_",
        "_probA",
        "_probB",
        "_gamma",
    ],
    "SVR": [
        "_sparse",
        "_n_support",
        "_dual_coef_",
        "_intercept_",
        "_probA",
        "_probB",
        "_gamma",
    ],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready
Development

No branches or pull requests

1 participant