解决问题
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)
大功告成,哈哈!