ValueError:未知标签类型:尝试分类时“连续”

问题描述 投票:0回答:0

我尝试使用决策树分类器制作梯度提升 ML 模型。 训练时,出现此错误。但是我使用二进制(0 和 1)数据作为输出列。

这是我的代码部分

from sklearn import utils
# Generate a synthetic dataset
X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, random_state=42)

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print(y_train)
print(utils.multiclass.type_of_target(y_train))

# Train the Gradient Boosting algorithm
clf = GradientBoostingClassifier()
clf.fit(X_train, y_train)

# Make predictions on the testing set and evaluate the accuracy
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
这是我的目标变量并将它们显示为二进制。你能告诉我这段代码或数据有什么问题吗?

python-3.x machine-learning numpy-ndarray
© www.soinside.com 2019 - 2024. All rights reserved.