xgboost-feature_names不匹配-训练数据没有以下字段:f77

时间:2019-06-13 13:33:32

标签: python machine-learning xgboost

我的代码与此类似:

train = read_csv('data/train.csv')
print(train.shape)

test = read_csv('data/test.csv')
print(test.shape)

treino = train
teste = test

我绘制了一些NA和NaN并转换了一些“对象”列以使其浮点,因为算法没有抱怨(无法将字符串转换为浮点),我使用:

treino[i] = Categorical(treino[i]).codes + 1

em todas作为colunas que quero转换器,并且:

del teste['Id']
del treino['Id']

机器学习算法如下:

treino.shape
(1459, 79)    

array = treino.values
X = array[:,0:77]
Y = array[:,78]

modelo = XGBClassifier()
modelo.fit(X, Y)

但是当我使用模板预测测试数据时,出现以下错误:

teste.shape
(1459, 78)    

arrayT = teste.values
xT = arrayT[:,:]

y_pred = modelo.predict(xT)
previsoes = [round(value) for value in y_pred]

ValueError:feature_names不匹配:['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','f61','f62','f63','f64','f65','f66','f67','f68','f69','f70','f71','f72' ,'f73','f74','f75','f76'] ['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','f61','f62', 'f63','f64','f65','f66','f67','f68','f69','f70','f71','f72','f73','f74','f75 ','f76','f77'] 训练数据没有以下字段:f77

enter image description here

0 个答案:

没有答案