Python 分类算法的图散点法

Python 分类算法的图散点法,python,matplotlib,decision-tree,scatter,Python,Matplotlib,Decision Tree,Scatter,请帮助我为这个分类算法创建散点图。这里在y中有一列标签(0,1),我希望两个标签都有两种不同颜色的预测标签 X = np.array(df.iloc[: , [0, 1,2,3,4,5,6,7,8,9,10,]].values) y = df.iloc[: , 17].values dtc = DecisionTreeClassifier() train_x, test_x, train_y, test_y = train_test_split(X, y, train_size = 0.8,

请帮助我为这个分类算法创建散点图。这里在y中有一列标签(0,1),我希望两个标签都有两种不同颜色的预测标签

X = np.array(df.iloc[: , [0, 1,2,3,4,5,6,7,8,9,10,]].values)
y = df.iloc[: , 17].values 
dtc = DecisionTreeClassifier()
train_x, test_x, train_y, test_y = train_test_split(X, y, train_size = 0.8, shuffle = True)
kf = KFold(n_splits = 5)
dtc=dtc.fit(train_x, train_y)
dtc_labels = dtc.predict(test_x)

我没有访问您的数据帧的权限,但这里有一个最低限度的工作示例,假设我理解正确的话

关键是,在打印过程中,必须对numpy数组使用逻辑索引。最后两行举例说明了这一点

import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split, KFold
import matplotlib.pyplot as plt
X = np.zeros((100,2))
X[:,0] = np.array(list(range(100)))
X[:,1] = np.array(list(range(100)))
y = list([0] * 50 + [1] * 50)
dtc = DecisionTreeClassifier()
train_x, test_x, train_y, test_y = train_test_split(X, y, train_size = 0.8, shuffle = True)
kf = KFold(n_splits = 5)
dtc=dtc.fit(train_x, train_y)
dtc_labels = dtc.predict(test_x)

plt.scatter(test_x[dtc_labels == 0,0],test_x[dtc_labels == 0,1])
plt.scatter(test_x[dtc_labels == 1,0],test_x[dtc_labels == 1,1])

我总共有17列,1150行X代表17列,y是1个标签列。这应该仍然有效,但您需要决定打印哪2列,或者需要使用某种形式的降维。错误:索引1超出轴1的范围,大小为1,请解释这意味着测试X是形状nx1。如果打印(test_x.shape)和打印(len(dtc_标签))或打印(dtc_labels.shape)(如果前者失败),它会做什么?十、 y和y是你的东西的占位符。我认为,只要你的东西有相同的数据类型,但不同的列形状,它就应该可以工作。