获取Scikit-learn估计器最大值的特征

我有以下非常简单的代码,尝试对一个简单的数据集进行建模:

from sklearn.pipeline import Pipelinefrom sklearn.impute import SimpleImputerfrom sklearn.preprocessing import StandardScalerfrom sklearn.linear_model import LinearRegressionfrom sklearn.model_selection import GridSearchCVdata = {'Feature_A': [1, 2, 3, 4], 'Feature_B': [7, 8, 9, 10], 'Feature_C': [2, 3, 4, 5], 'Label': [7, 7, 8, 9]}data = pd.DataFrame(data)data_labels = data['Label']data = data.drop(columns=['Label'])pipeline = Pipeline([('imputer', SimpleImputer()),                         ('std_scaler', StandardScaler())])data_prepared = pipeline.fit_transform(data)lin_reg = LinearRegression()lin_grid = {"n_jobs": [20, 50]}error = "max_error"grid_search = GridSearchCV(lin_reg, param_grid=lin_grid, verbose=3, cv=2, refit=True, scoring=error, return_train_score=True)grid_search.fit(data_prepared, data_labels)print(grid_search.best_estimator_.coef_)print(grid_search.best_estimator_.intercept_)print(list(data_labels))print(list(grid_search.best_estimator_.predict(data_prepared)))

这给我带来了以下结果:

[0.2608746 0.2608746 0.2608746]7.75[7, 7, 8, 9][6.7, 7.4, 8.1, 8.799999999999999]

从这里看,是否有办法计算出能够在数据集的边界内给我带来最大标签值的特征值?


回答:

如果我正确理解了你的问题,以下方法应该可行:

import numpy as npid_max = np.argmax(grid_search.predict(data)) # 查找预测标签最大值的IDprint(data.loc[id_max])

Related Posts

如何对SVC进行超参数调优?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

如何在初始训练后向模型添加训练数据?

我想在我的scikit-learn模型已经训练完成后再…

使用Google Cloud Function并行运行带有不同用户参数的相同训练作业

我正在寻找一种方法来并行运行带有不同用户参数的相同训练…

加载Keras模型,TypeError: ‘module’ object is not callable

我已经在StackOverflow上搜索并阅读了文档,…

在计算KNN填补方法中特定列中NaN值的”距离平均值”时

当我从头开始实现KNN填补方法来处理缺失数据时,我遇到…

使用巨大的S3 CSV文件或直接从预处理的关系型或NoSQL数据库获取数据的机器学习训练/测试工作

已关闭。此问题需要更多细节或更清晰的说明。目前不接受回…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注