当您尝试使用已训练好的模型进行预测时,如果输入n_features与模型n_features不匹配,则会引发以下错误:
ValueError: Number of features of the model must match the input. Model n_features is 140 and input n_features is 130
我想要的是知道模型n_features = 140,在它引发错误之前。有没有什么方法可以让我访问模型的“特征”,以便提取n_features值?我正在尝试构建一个单元测试,我需要这个数字来进行验证。
提前谢谢。
发布于 2021-01-20 02:49:40
在sklearn的最新版本中,已经有了标准化使用the attribute n_features_in_
的努力,BaseEstimator
包括用于设置和检查该参数的the method _check_n_features
。
因此,对于大多数估计者来说,model_variable.n_features_in_
应该包含您想要的内容。
https://stackoverflow.com/questions/65797393
复制相似问题