@[TOC](《Python机器学习基础教程》第二章笔记:ValueError: cannot reshape array of size 4000000 into shape (1000,1000))
成功解决:
增加命令
y = y % 2
一、报错
ValueError: cannot reshape array of size 4000000 into shape (1000,1000)
二、尝试解决
意思:ValueError:无法将大小为4000000的数组重塑为形状(1000,1000)
数组没有办法重塑
尝试解决的思路:
1、查看源码:
没有看懂!!!!
不过没有关系
2、其中centers为控制y中值类别的参数
默认为2
此时赋值为4
3、输出一下y
对比没有赋值为4是:
即此时为3
将centers赋值为2 时,成功输出
由此可见,需要对center或者y进行调整,由于需要center=4,因而调整y,使得y=y%2即可
X, y = make_blobs(centers=4,random_state=8)#centers为数据堆
print(y)##centers为数据堆改变了y的值
y = y % 2
print(y)
linear_svm = LinearSVC().fit(X, y)
mglearn.plots.plot_2d_separator(linear_svm, X)#classification可以
mglearn.discrete_scatter(X[:, 0], X[:, 1], y)
plt.xlabel("Feature 0")
plt.ylabel("Feature 1")
plt.show()
参考
[1]小书同学:《监督学习(九)——核支持向量机SVM》,链接: link.