Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试将Kmeans与Seaborn的Iris数据集一起使用时出现问题_Python_Spyder - Fatal编程技术网

Python 尝试将Kmeans与Seaborn的Iris数据集一起使用时出现问题

Python 尝试将Kmeans与Seaborn的Iris数据集一起使用时出现问题,python,spyder,Python,Spyder,嗨,我想知道为什么会出现这个错误消息。我在这里看到了其他类似的东西,但对这些东西的反应对我来说不起作用。我正在使用Spyder(python 3.8) 错误消息: data = sns.load_dataset('iris', delimiter= ',') X = normalize(data[:,1:],axis=0,norm='max') Y = data[:,0] X = data.iloc[:,1:].values Y = data.iloc[:,0].values pca = PCA

嗨,我想知道为什么会出现这个错误消息。我在这里看到了其他类似的东西,但对这些东西的反应对我来说不起作用。我正在使用Spyder(python 3.8)

错误消息:

data = sns.load_dataset('iris', delimiter= ',')
X = normalize(data[:,1:],axis=0,norm='max')
Y = data[:,0]
X = data.iloc[:,1:].values
Y = data.iloc[:,0].values
pca = PCA(n_components=2)
X2d = pca.fit_transform(X)
fig = plt.figure()
colors = ['red', 'yellow', 'blue']
plt.scatter(X2d[:,0],X2d[:,1],c=Y,cmap=matplotlib.color.ListedColormap(colors))
plt.axis('equal')
plt.show()
Traceback (most recent call last):

  File "<ipython-input-127-3672f057e666>", line 2, in <module>
    X = normalize(data[:,1:],axis=0,norm='max')

  File "/Users/Faith/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 2902, in __getitem__
    indexer = self.columns.get_loc(key)

  File "/Users/Faith/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2895, in get_loc
    return self._engine.get_loc(casted_key)

  File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc

  File "pandas/_libs/index.pyx", line 75, in pandas._libs.index.IndexEngine.get_loc

TypeError: '(slice(None, None, None), slice(1, None, None))' is an invalid key
data=sns.load_数据集('iris',分隔符=','))
X=规格化(数据[:,1:],轴=0,norm='max')
Y=数据[:,0]
X=data.iloc[:,1::]值
Y=data.iloc[:,0]。值
pca=pca(n_分量=2)
X2d=pca.fit_变换(X)
图=plt.图()
颜色=[“红色”、“黄色”、“蓝色”]
plt.scatter(X2d[:,0],X2d[:,1],c=Y,cmap=matplotlib.color.ListedColormap(colors))
plt.轴(“相等”)
plt.show()
回溯(最近一次呼叫最后一次):
文件“”,第2行,在
X=规格化(数据[:,1:],轴=0,norm='max')
文件“/Users/Faith/opt/anaconda3/lib/python3.8/site packages/pandas/core/frame.py”,第2902行,在__
indexer=self.columns.get_loc(键)
文件“/Users/Faith/opt/anaconda3/lib/python3.8/site packages/pandas/core/index/base.py”,第2895行,在get_loc中
返回自我。引擎。获取定位(铸造钥匙)
文件“pandas/_libs/index.pyx”,第70行,在pandas._libs.index.IndexEngine.get_loc中
文件“pandas/_libs/index.pyx”,第75行,在pandas._libs.index.IndexEngine.get_loc中
TypeError:“(slice(None,None,None),slice(1,None,None))”是无效的键

sns.load\u dataset
返回一个
pandas.DataFrame
,而不是
numpy.ndarray
。不过你可以。非常感谢你!我仍然得到一些错误,但我正在努力找出他们!没问题,如果你想的话,你可以更新这个问题,这样我们就可以尝试解决它们。我刚刚发布了一个新的,我不知道我可以更新这个问题!但是谢谢你!我的新问题是TypeError:“numpy.ndarray”对象不可调用。而且我用的是mac电脑,我觉得有时候会有所不同。
data = sns.load_dataset('iris', delimiter= ',')
X = normalize(data[:,1:],axis=0,norm='max')
Y = data[:,0]
X = data.iloc[:,1:].values
Y = data.iloc[:,0].values
pca = PCA(n_components=2)
X2d = pca.fit_transform(X)
fig = plt.figure()
colors = ['red', 'yellow', 'blue']
plt.scatter(X2d[:,0],X2d[:,1],c=Y,cmap=matplotlib.color.ListedColormap(colors))
plt.axis('equal')
plt.show()
Traceback (most recent call last):

  File "<ipython-input-127-3672f057e666>", line 2, in <module>
    X = normalize(data[:,1:],axis=0,norm='max')

  File "/Users/Faith/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 2902, in __getitem__
    indexer = self.columns.get_loc(key)

  File "/Users/Faith/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2895, in get_loc
    return self._engine.get_loc(casted_key)

  File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc

  File "pandas/_libs/index.pyx", line 75, in pandas._libs.index.IndexEngine.get_loc

TypeError: '(slice(None, None, None), slice(1, None, None))' is an invalid key