成功解决 ValueError: feature_names mismatch training data did not have the following fields

简介: 成功解决 ValueError: feature_names mismatch training data did not have the following fields

解决问题


ValueError: feature_names mismatch: ['crim', 'zn', 'indus', 'chas', 'nox', 'rm', 'age', 'dis', 'rad', 'tax', 'ptratio', 'black', 'lstat', 'crim_(0, 10_', 'crim_(10, 20_', 'crim_(20, 100_', 'zn_(-1, 5_', 'zn_(5, 18_', 'zn_(18, 20_', 'zn_(20, 40_', 'zn_(40, 80_', 'zn_(80, 86_', 'zn_(86, 100_', 'indus_(-1, 7_', 'indus_(7, 15_', 'indus_(15, 23_', 'indus_(23, 40_', 'nox_(0.0, 0.51_', 'nox_(0.51, 0.6_', 'nox_(0.6, 0.7_', 'nox_(0.7, 0.8_', 'nox_(0.8, 1.0_', 'rm_(0, 4_', 'rm_(4, 5_', 'rm_(5, 6_', 'rm_(6, 7_', 'rm_(7, 8_', 'rm_(8, 9_', 'age_(0, 60_', 'age_(60, 80_', 'age_(80, 100_', 'dis_(0, 2_', 'dis_(2, 6_', 'dis_(6, 14_', 'rad_(0, 5_', 'rad_(5, 10_', 'rad_(10, 25_', 'tax_(0, 200_', 'tax_(200, 400_', 'tax_(400, 500_', 'tax_(500, 800_', 'ptratio_(0, 14_', 'ptratio_(14, 20_', 'ptratio_(20, 23_', 'black_(0, 100_', 'black_(100, 350_', 'black_(350, 450_', 'lstat_(0, 5_', 'lstat_(5, 10_', 'lstat_(10, 20_', 'lstat_(20, 40_'] ['f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f20', 'f21', 'f22', 'f23', 'f24', 'f25', 'f26', 'f27', 'f28', 'f29', 'f30', 'f31', 'f32', 'f33', 'f34', 'f35', 'f36', 'f37', 'f38', 'f39', 'f40', 'f41', 'f42', 'f43', 'f44', 'f45', 'f46', 'f47', 'f48', 'f49', 'f50', 'f51', 'f52', 'f53', 'f54', 'f55', 'f56', 'f57', 'f58', 'f59', 'f60']

expected rad_(0, 5_, indus_(-1, 7_, dis, rad_(10, 25_, tax, nox, dis_(0, 2_, tax_(400, 500_, zn_(5, 18_, lstat, nox_(0.7, 0.8_, rm_(5, 6_, ptratio_(14, 20_, indus_(7, 15_, age, zn_(-1, 5_, tax_(0, 200_, lstat_(5, 10_, lstat_(10, 20_, crim_(10, 20_, zn_(18, 20_, indus, nox_(0.6, 0.7_, rm_(6, 7_, dis_(2, 6_, tax_(500, 800_, indus_(15, 23_, crim_(0, 10_, zn_(20, 40_, rad_(5, 10_, ptratio, chas, rm_(0, 4_, black, age_(0, 60_, black_(350, 450_, crim, crim_(20, 100_, black_(0, 100_, rm, rm_(7, 8_, zn_(86, 100_, nox_(0.51, 0.6_, black_(100, 350_, ptratio_(0, 14_, lstat_(0, 5_, zn, zn_(80, 86_, rm_(8, 9_, nox_(0.8, 1.0_, dis_(6, 14_, tax_(200, 400_, rad, indus_(23, 40_, lstat_(20, 40_, age_(80, 100_, rm_(4, 5_, ptratio_(20, 23_, age_(60, 80_, zn_(40, 80_, nox_(0.0, 0.51_ in input data

training data did not have the following fields: f47, f18, f51, f33, f49, f9, f5, f32, f43, f26, f39, f55, f6, f57, f54, f44, f3, f14, f40, f48, f59, f24, f46, f17, f21, f31, f53, f2, f37, f42, f60, f8, f50, f58, f22, f45, f52, f20, f16, f36, f0, f10, f12, f19, f41, f11, f4, f27, f7, f34, f56, f1, f15, f38, f35, f13, f25, f29, f23, f30, f28





解决思路


值错误:feature_names不匹配:['crim', 'zn', 'indus', 'chas', 'nox', 'rm', 'age', 'dis', 'rad', 'tax', 'ptratio', 'black', 'lstat', 'crim_(0, 10_', 'crim_(10, 20_', 'crim_(20, 100_', 'zn_(-1, 5_', 'zn_(5, 18_', 'zn_(18, 20_', 'zn_(20, 40_', 'zn_(40, 80_', 'zn_(80, 86_', 'zn_(86, 100_', 'indus_(-1, 7_', 'indus_(7, 15_', 'indus_(15, 23_', 'indus_(23, 40_', 'nox_(0.0, 0.51_', 'nox_(0.51, 0.6_', 'nox_(0.6, 0.7_', 'nox_(0.7, 0.8_', 'nox_(0.8, 1.0_', 'rm_(0, 4_', 'rm_(4, 5_', 'rm_(5, 6_', 'rm_(6, 7_', 'rm_(7, 8_', 'rm_(8, 9_', 'age_(0, 60_', 'age_(60, 80_', 'age_(80, 100_', 'dis_(0, 2_', 'dis_(2, 6_', 'dis_(6, 14_', 'rad_(0, 5_', 'rad_(5, 10_', 'rad_(10, 25_', 'tax_(0, 200_', 'tax_(200, 400_', 'tax_(400, 500_', 'tax_(500, 800_', 'ptratio_(0, 14_', 'ptratio_(14, 20_', 'ptratio_(20, 23_', 'black_(0, 100_', 'black_(100, 350_', 'black_(350, 450_', 'lstat_(0, 5_', 'lstat_(5, 10_', 'lstat_(10, 20_', 'lstat_(20, 40_'] ['f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f20', 'f21', 'f22', 'f23', 'f24', 'f25', 'f26', 'f27', 'f28', 'f29', 'f30', 'f31', 'f32', 'f33', 'f34', 'f35', 'f36', 'f37', 'f38', 'f39', 'f40', 'f41', 'f42', 'f43', 'f44', 'f45', 'f46', 'f47', 'f48', 'f49', 'f50', 'f51', 'f52', 'f53', 'f54', 'f55', 'f56', 'f57', 'f58', 'f59', 'f60']

training data 数据中没有以下字段:f47, f18, f51, f33, f49, f9, f5, f32, f43, f26, f39, f55, f6, f57, f54, f44, f3, f14, f40, f48, f59, f24, f46, f17, f21, f31, f53, f2, f37, f42, f60, f8, f50, f58, f22, f45, f52, f20, f16, f36, f0, f10, f12, f19, f41, f11, f4, f27, f7, f34, f56, f1, f15, f38, f35, f13, f25, f29, f23, f30, f28





解决方法


去掉 .values



boston_train_all = pd.read_csv('boston_train.csv')

boston_test = boston_train_all.values

LiR.predict(boston_test)

改为


boston_train_all = pd.read_csv('boston_train.csv')

boston_test = boston_train_all

LiR.predict(boston_test)

大功告成,哈哈!



相关文章
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
2361 0
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
2243 0
|
8月前
|
Linux
Specified sample format -1 is invalid or not supported
Specified sample format -1 is invalid or not supported
134 0
Specified sample format -1 is invalid or not supported
|
机器学习/深度学习 数据采集
ValueError: Found input variables with inconsistent numbers of samples: [140, 1120] 怎么解决?
这个错误通常发生在机器学习模型的训练中,它表示输入数据的样本数量不一致。在你的情况下,你的输入数据中有两个变量,一个变量的样本数量为140,另一个变量的样本数量为1120,因此这个错误就出现了。 为了解决这个问题,你需要确保所有输入变量的样本数量是相同的。你可以通过以下几种方式来解决这个问题: 检查数据:检查数据是否正确加载,可能会导致数据样本数量不一致。 数据清洗:检查是否有重复的样本或者缺失的样本,如果有则需要对数据进行清洗。 数据对齐:如果你使用了多个数据源,那么你需要对它们进行对齐以确保它们的样本数量一致。 数据重采样:如果数据中有不均衡的样本数量,你可以考虑使用数据重采样方
641 0
|
编译器
error: pasting “(“ and “1“ does not give a valid preprocessing token
error: pasting “(“ and “1“ does not give a valid preprocessing token
170 0
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
230 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
|
Python
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
546 0
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2421 0
|
Python
解决办法:RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96
解决办法:RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96
137 0
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]