获取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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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