首页 > 解决方案 > TypeError: '(slice(None, None, None), slice(1, None, None))' is an invalid key

问题描述

我试图在数据集中拟合 DBSCAN 聚类算法。数据集头如下所示:

[Summary    Severity    category    component   priority    Issues]

样本数据如下:

[aaa_bbb_ccc @ABC 2.0 @August Regression - XYZ - ABCD - We have got the Income Reasonability Rule (V60300) but we are not getting the SSR (Self Service) Page for ABCD in XYZ environment.  , 2-Major   ,Application - Code ,   ABCD    ,High   ,We have got the Income Reasonability Rule (V60300) but we are not getting the SSR (Self Service) Page for ABCD in XYZ environment.]
...........

这样做时,我遇到了 "ValueError: could not convert string to float:while scaler.fit_transform" ,我使用https://stackoverflow.com/a/53473541/13659094解决了这个问题

但从那以后,我面临一个新问题:

X1 = np.concatenate([transformed, X[:, 0:]], axis=1)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2927, in __getitem__
    indexer = self.columns.get_loc(key)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2657, in get_loc
    return self._engine.get_loc(key)

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

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

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

代码如下所示:

scaler = StandardScaler()
X = final_data
X_sum  = X.iloc[:,[0]]
onehotencoder = OneHotEncoder(handle_unknown='ignore')
transformed = onehotencoder.fit_transform(X_sum).toarray().reshape(1,-1)
X1 = np.concatenate([transformed, X[:, 1:]], axis=1)

X_scaled = scaler.fit_transform(X1).reshape(1,-1)

dbscan = DBSCAN(eps=0.123, min_samples = 2)
clusters = dbscan.fit_predict(X_scaled)

plt.scatter(X1[:, 0], X1[:, 1], c=clusters, cmap="plasma")
plt.xlabel("Feature 0")
plt.ylabel("Feature 1") 

谁能帮助我解决问题的解决方案,我可以将 DBSCAN 算法拟合到这个数据集吗?

标签: pythonnumpytypeerrordbscan

解决方案


推荐阅读