python - 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 算法拟合到这个数据集吗?
解决方案
推荐阅读
- swift - 我正在尝试创建一个 UIbarButtonItem,其宽度和高度等于导航栏高度的 70%?
- filter - 基于前两个数字的 NAICS ID 的新列或度量
- c++ - 如何私下定义 lambda 函数?
- node.js - 检测对话结束并在 azure Bot 中寻求反馈
- xcode - Xcode 10.2.1 无法索引或构建任何项目
- ruby - 如何编写一个接受并返回带有条件的数组的方法
- python - 导入pyspark后如何恢复泡菜?
- forms - 模板驱动的验证需要在取消按钮中工作
- java - Java切换目录,然后用参数触发命令
- angular - 使用异步导入模块延迟 NgModule 声明