[Python] Ridge Polynomial Regression: How to get parameters for equation found

Discussão em 'Python' iniciado por Stack, Julho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I've used sklearn for polynomial ridge regression. Using grid search, I am happy with the results. Now I would like to render it as a simple polynomial equation to run in a small python module. The sklearn function returns the degree and alpha parameter. The latter just sets regularization for training. The former tells me the maximum degree of the resulting equation. But what are the parameters of the equation it has found? I expect the equation to be of the form ax^3 + bx^2 + cx + d, to what are a,b,c,d?

    A search suggests that I should be able to use model.coef_ but I am not finding that. A dir on my model shows the following:

    ['__abstractmethods__',
    '__annotations__',
    '__class__',
    '__delattr__',
    '__dict__',
    '__dir__',
    '__doc__',
    '__eq__',
    '__format__',
    '__ge__',
    '__getattribute__',
    '__getitem__',
    '__getstate__',
    '__gt__',
    '__hash__',
    '__init__',
    '__init_subclass__',
    '__le__',
    '__len__',
    '__lt__',
    '__module__',
    '__ne__',
    '__new__',
    '__reduce__',
    '__reduce_ex__',
    '__repr__',
    '__setattr__',
    '__setstate__',
    '__sizeof__',
    '__sklearn_clone__',
    '__sklearn_is_fitted__',
    '__sklearn_tags__',
    '__slotnames__',
    '__str__',
    '__subclasshook__',
    '__weakref__',
    '_abc_impl',
    '_build_request_for_signature',
    '_can_fit_transform',
    '_can_inverse_transform',
    '_can_transform',
    '_check_feature_names',
    '_check_method_params',
    '_check_n_features',
    '_doc_link_module',
    '_doc_link_template',
    '_doc_link_url_param_generator',
    '_estimator_type',
    '_final_estimator',
    '_fit',
    '_get_default_requests',
    '_get_doc_link',
    '_get_metadata_for_step',
    '_get_metadata_request',
    '_get_param_names',
    '_get_params',
    '_get_tags',
    '_iter',
    '_log_message',
    '_more_tags',
    '_parameter_constraints',
    '_replace_estimator',
    '_repr_html_',
    '_repr_html_inner',
    '_repr_mimebundle_',
    '_set_params',
    '_sk_visual_block_',
    '_validate_data',
    '_validate_names',
    '_validate_params',
    '_validate_steps',
    'classes_',
    'decision_function',
    'feature_names_in_',
    'fit',
    'fit_predict',
    'fit_transform',
    'get_feature_names_out',
    'get_metadata_routing',
    'get_params',
    'inverse_transform',
    'memory',
    'n_features_in_',
    'named_steps',
    'predict',
    'predict_log_proba',
    'predict_proba',
    'score',
    'score_samples',
    'set_output',
    'set_params',
    'set_score_request',
    'steps',
    'transform',
    'transform_input',
    'verbose']


    What am I missing?

    Notes: Code for grid search pipeline:

    from sklearn.pipeline import Pipeline
    from sklearn.preprocessing import StandardScaler, PolynomialFeatures
    from sklearn.linear_model import Ridge, Lasso, SGDRegressor
    .
    .
    .
    # === 4. Polynomial Ridge ===
    poly_pipe = Pipeline([
    ('scaler', StandardScaler()),
    ('poly', PolynomialFeatures()),
    ('ridge', Ridge())
    ])
    poly_params = {
    'poly__degree': [2, 3],
    'ridge__alpha': [0.01, 0.1, 1]
    }
    evaluate_model('Polynomial Ridge', poly_pipe, poly_params, is_linear=False)

    Continue reading...

Compartilhe esta Página