我目前正在使用从sklearn加载的乳腺癌数据集。我以这种方式将其变成了数据框:
data = load_breast_cancer()
#Load cancer dataset as dataframe
cancer = pd.DataFrame(np.c_[data['data'], data['target']], columns= np.append(data['feature_names'], ['target']))
我建立了KNN邻居分类模型并进行了测试。现在,我想使用mglearn
来绘制决策边界,但我不断遇到此错误:
TypeError: unhashable type: 'slice'
这是我的代码:
import mglearn
fig, axes = plt.subplots(1, 3, figsize = (14, 5))
for n_neighbors, ax in zip([1, 7, 15], axes):
clf = KNeighborsClassifier(n_neighbors = n_neighbors).fit(cancer, cancer["target"])
mglearn.plots.plot_2d_separator(knn, cancer, fill = True, eps = 0.5, ax = ax, alpha = 0.4)
mglearn.discrete_scatter(cancer.iloc[:, 0], cancer.iloc[:, 1], cancer["target"], ax = ax)
ax.set_title("{} neighbor(s)".format(n_neighbors))
ax.set_xlabel("feature 0")
ax.set_ylabel("feature 1")
axes[0].legend(loc=3)
有什么建议吗?