我正在尝试使用此处的基本sklearn
iris
数据集代码:
http://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html
注意:为了避免第二行的编码问题,我从Ga {accent-e} l Varoquaux
改为Gaelprint(__doc__)
# Code source: Gael Varoquaux
# Modified for documentation by Jaques Grobler
# License: BSD 3 clause
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn import datasets
from sklearn.decomposition import PCA
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2] # we only take the first two features.
Y = iris.target
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
plt.figure(2, figsize=(8, 6))
plt.clf()
# Plot the training points
plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Paired)
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
plt.xticks(())
plt.yticks(())
# To getter a better understanding of interaction of the dimensions
# plot the first three PCA dimensions
fig = plt.figure(1, figsize=(8, 6))
ax = Axes3D(fig, elev=-150, azim=110)
X_reduced = PCA(n_components=3).fit_transform(iris.data)
ax.scatter(X_reduced[:, 0], X_reduced[:, 1], X_reduced[:, 2], c=Y,
cmap=plt.cm.Paired)
ax.set_title("First three PCA directions")
ax.set_xlabel("1st eigenvector")
ax.w_xaxis.set_ticklabels([])
ax.set_ylabel("2nd eigenvector")
ax.w_yaxis.set_ticklabels([])
ax.set_zlabel("3rd eigenvector")
ax.w_zaxis.set_ticklabels([])
plt.show()
如果我在中间选择一个任意点将代码分成两部分并分别剪切和粘贴 - 那么代码就可以了。
但是,当一次粘贴整个代码段时,后面的行会出现乱码:
In [267]: ax.set_title("First three PCA directions")
Out[267]: <matplotlib.text.Text at 0x113726250>
tor")68]: ax.seax.seax.seax.seax.seax.seax.se.wax.seax.seax.seax.seax.seax.seax.se.wal("2nd eigenvec
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-268-81e33d4e9263> in <module>()
----> 1 ax.seax.seax.seax.seax.seax.seax.se.wax.seax.seax.seax.seax.seax.seax.se.wal("2nd eigenvector")
AttributeError: 'Axes3D' object has no attribute 'seax'
这里有一个技巧可以将大量文本粘贴到ipython
吗?请注意代码中有 无标签 。这适用于ipython 4.2.1
python 2.7.3
另外:我在OS / X上使用iterm2
:不确定是否会发挥作用。
更新,这也是通过%cpaste
尝试的。结果是相同的:将整个金额作为一个单元粘贴时文本被破坏。
答案 0 :(得分:0)
这已在ipython 5.3
中修复。要从(损坏的)ipython 4.X升级:
pip install -U ipython
然后一切都是kopacetic。