这真的取决于您的数据、模型和您想要实现的目标。话虽这么说,最简单的方法是进行不同的实验并比较结果。所以先用 X_1、X_2 和 X_3 做一个模型,然后再用 X_1 和 X_2 做一个模型。
更复杂的解决方案可能是使用特征选择。 Here a short introduction.
例如,您可以使用feature importance 来了解每个特征对预测的贡献程度。 An easy example with code can be found here.
**Example with a random forest model:**
from sklearn.datasets import make_regression
from sklearn.ensemble import RandomForestRegressor
from matplotlib import pyplot
# define dataset
X, y = make_regression(n_samples=1000, n_features=3, n_informative=2, random_state=42)
# define the model
model = RandomForestRegressor()
# fit the model
model.fit(X, y)
# get importance
importance = model.feature_importances_
# summarize feature importance
for i,v in enumerate(importance):
print('Feature: X_ %0d, Score: %.5f' % (i+1,v))
在输出中,我们可以看到 X_3 比 X_1 对预测的贡献更大,因此创建另一个只有 X_1 和 X_2 的模型可能是一个想法(如果我们从一开始就怀疑的话,至少可以这样)。我们也可以考虑排除 X_1,因为如果我们担心数据的维度,它对预测的贡献不大。:
请记住,这不是唯一的方法,而是众多方法之一。这实际上取决于您拥有哪些数据,您正在使用哪些模型以及您正在尝试做什么。
编辑:
正如你现在问的关于预测的问题。您可以使用LIME 了解不同特征如何影响您的预测。由于我不知道您的代码,因此我无法为您的案例提供正确的代码。对于实施,您可以查看here 或简单地通过谷歌搜索。
示例代码如下所示:
import lime
import lime.lime_tabular
# LIME has one explainer for all the models
explainer = lime.lime_tabular.LimeTabularExplainer(X, verbose=True, mode='regression')
# Choose the 5th instance and use it to predict the results
j = 5
exp = explainer.explain_instance(X[j], model.predict, num_features=3)
# Show the predictions
exp.show_in_notebook(show_table=True)
输出看起来像这样:
所以这里的解释可能是,特征 0 和特征 2 对预测的贡献最大,而且特征 2 可能指向更负面的预测方向。