admin管理员组

文章数量:1389837

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

num_features, bin_features, cat_features = split_features(X)

preprocessor = ColumnTransformer([
    ('num', StandardScaler(), num_features),
    ('bin', 'passthrough', bin_features),
    ('cat', OneHotEncoder(drop='first', sparse_output=False, handle_unknown='ignore'), cat_features)
])

inner_pipeline = Pipeline([
    ('preprocessor', preprocessor),
    ('model', LinearRegression())
])

pipeline = TransformedTargetRegressor(
    regressor=inner_pipeline,
    transformer=QuantileTransformer(output_distribution='normal')
)

param_grid = {
    'transformer__n_quantiles': [10, 100, 1000]
}

optimizer = GridSearchCV(pipeline, param_grid, cv=10, scoring='neg_root_mean_squared_error', n_jobs=-1)
optimizer.fit(X_train, y_train)
y_pred = optimizer.best_estimator_.predict(X_test)

I tried:

optimizer.best_estimator_.regressor.named_steps['model'].coef_

I got: AttributeError: 'LinearRegression' object has no attribute 'coef_'

本文标签: linear regressionLinearRegression object has no attr coef (in pipeline)Stack Overflow