好吧,我仍然有这个问题,我不知道哪里出了问题。我以为我有一个可行的解决办法,但我错了。你知道吗
通过TPOT找到回归管道后,我使用.predict(X_test)
函数,得到以下错误消息:
ValueError: Number of features of the model must match the input. Model n_features is 117 and input n_features is 118
我read somewhere on GithubXGBoost喜欢将X特性以Numpy数组的形式传递给它,而不是数据帧。所以我做到了这一点,现在每当一个randomforestressor出现在我的管道中时,我就会收到这个错误消息。你知道吗
所以我调查:
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_size, random_state=seed, shuffle=False)
# Here is where I convert the features to numpy arrays
X_train=X_train.values
X_test=X_test.values
print('[INFO] Printing the shapes of the training/testing feature/label sets...')
print(X_train.shape)
print(X_test.shape)
print(Y_train.shape)
print(Y_test.shape)
[INFO] Printing the shapes of the training/testing feature/label sets...
(1366, 117)
(456, 117)
(1366,)
(456,)
# Notice 117 rows for X columns...
# Now print the X_test shape just before the predict function...
print(X_test.shape)
(456, 117)
# Still 117 columns, so call predict:
predictions = best_model.predict(X_test)
ValueError: Number of features of the model must match the input. Model n_features is 117 and input n_features is 118
为什么!!!!!!?????
现在棘手的是,我正在使用一个定制的tpot_配置来只使用回归器XGBRegressor、ExtraTreesRegressor、gradientboostingressor、AdaBoostRegressor、DecisionTreeRegressor和RandomForestRegressor,所以我需要想出一种方法来训练和预测这些特性,使它们以相同的方式处理数据,因此,无论它使用什么管道,每次运行代码时都不会出现这个问题!你知道吗
在这些链接上也有类似的问题,所以:
。。。但我不明白为什么我的模型没有预测,当我传递给它相同数量的(X)功能时,在训练模型时使用的!?我哪里做错了???你知道吗
编辑 我还应该提到,当XGBRegressor也在管道中时,将特性保留为数据帧而不将它们转换为numpy数组有时会导致“特性名称不匹配”错误。所以我不知道如何处理树回归器列表(类似Dataframes)和XGBoost(类似Numpy数组)。我也尝试过“重新安排”专栏(?)确保X\u train和X\u test数据帧的顺序与一些人建议的相同,但这没有起到任何作用。你知道吗
我已经在Google Colab notebook here中发布了我的完整代码,您可以在那里对其进行评论。无论TPOT提供什么样的管道,如何将测试数据传递给.predict()函数??????你知道吗
多亏了GitHub的weixuanfu,我可能已经找到了一个解决方案,将feature\u重要性代码部分移到了代码的底部,是的,使用numpy数组作为特性。如果我再次遇到这个问题,我会把它贴在下面:
https://github.com/EpistasisLab/tpot/issues/738
相关问题 更多 >
编程相关推荐