我对Tenessee Eastmann流程中的XGBoost感到怀疑。我已经完成了数据预处理,当我拟合模型时,它显示了一些错误。 “错误的输入形状(980,2)” 而且如果我更改目标值并拟合模型,也没有问题,但是现在显示出另一个错误。 “分类指标不能同时处理连续目标和二进制目标” 有人熟悉Tenessee Eastman流程吗?
我的代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
from xgboost import XGBClassifier, plot_tree
from sklearn.metrics import accuracy_score
Training_data = pd.read_excel ('X_train.xlsx')
Testing_data = pd.read_excel ('X_test.xlsx')
X_train, y_train = Training_data.iloc[:,:-1].values , Training_data.iloc[:,-1].values
X_test, y_test = Testing_data.iloc[:,:-1] , Testing_data.iloc[:,-1]
#from sklearn.preprocessing import OneHotEncoder
#enc = OneHotEncoder(categorical_features=[0]
#y_train_new = enc.fit_transform(y_train).toarray()
y_enc_train = pd.get_dummies(y_train)
y_enc_test = pd.get_dummies(y_test)
scaler = StandardScaler()
#training set
scaler.fit(X_train)
scaled_features_X_train = scaler.transform(X_train)
df_feat = pd.DataFrame(scaled_features_X_train)
#testing set
scaler.fit(X_test)
scaled_features_X_test = scaler.transform(X_test)
df_feat_test = pd.DataFrame(scaled_features_X_test)
#xgb model
classifier = XGBClassifier()
classifier.fit(df_feat,y_enc_train)
# make predictions for test data
y_pred = classifier.predict(df_feat_test)
predictions = [round(value) for value in y_pred]
# evaluate predictions
accuracy = accuracy_score(y_enc_test, predictions)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
错误:ValueError: bad input shape (980, 2)