解决:TypeError: ‘(slice(None, None, None), 1)‘ is an invalid key
使用matplotlib将DBSCAN分类结果散点图可视化时提示此TypeError
源代码:
from sklearn.cluster import DBSCAN
import pandas as pd
import matplotlib.pyplot as plt
def devicesDbscan():
path="./unique_deviceID_lng_lat.csv"
df=pd.read_csv(path,header=None,names=["DEVICE_ID","LNG","LAT"])
print(df.shape())
X_df=df.drop("DEVICE_ID",axis=1) #去掉ID
y_pred=DBSCAN(eps=0.1,min_samples=1,n_jobs=20).fit_predict(X_df) #拟合并返回预测标签
count_clusters = len(set(y_pred)) #聚类簇的数目
print("clusters的数目:"+str(count_clusters))
plt.scatter(X_df[:,0],X_df[:,1],c=y_pred) #–>提示错误地方
plt.show()
if name=="main":
devicesDbscan()
解决
将DataFrame对象X_df转成ndarray数组即可
from sklearn.cluster import DBSCAN
import pandas as pd
import matplotlib.pyplot as plt
def devicesDbscan():
path="./unique_deviceID_lng_lat.csv"
df=pd.read_csv(path,header=None,names=["DEVICE_ID","LNG","LAT"])
print(df.shape())
X_df=df.drop("DEVICE_ID",axis=1)
y_pred=DBSCAN(eps=0.1,min_samples=1,n_jobs=20).fit_predict(X_df)
count_clusters = len(set(y_pred))
print("clusters的数目:"+str(count_clusters))
plt.scatter(X_df.values[:,0],X_df.values[:,1],c=y_pred)
plt.show()
if name=="main":
devicesDbscan()
解决:TypeError: ‘(slice(None, None, None), 1)‘ is an invalid key相关推荐
- 成功解决TypeError: ‘(slice(None, None, None), 1)‘ is an invalid key
成功解决TypeError: '(slice(None, None, None), 1)' is an invalid key 目录 解决问题 解决思路 解决方法 解决问题 TypeError: '( ...
- 成功解决TypeError: slice indices must be integers or None or have an __index__ method
成功解决TypeError: slice indices must be integers or None or have an __index__ method 目录 解决问题 解决思路 解决方法 ...
- Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法
Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法 ...
- 成功解决TypeError: ‘tuple‘ object is not callable
成功解决TypeError: 'tuple' object is not callable 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'tuple' object is no ...
- 成功解决TypeError: data type ‘category‘ not understood
成功解决TypeError: data type 'category' not understood 目录 解决问题 解决思路 解决方法 解决问题 TypeError: data type 'cate ...
- 成功解决TypeError: ‘str‘ object is not callable
成功解决TypeError: 'str' object is not callable 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'st
- 成功解决TypeError: read_excel() got an unexpected keyword argument ‘parse_cols or ‘sheetname‘
成功解决TypeError: read_excel() got an unexpected keyword argument 'parse_cols' TypeError: read_excel() ...
- 成功解决TypeError: take() got an unexpected keyword argument ‘fill_value‘
成功解决TypeError: take() got an unexpected keyword argument 'fill_value' 目录 解决问题 解决思路 解决方法 解决问题 Traceba ...
- 成功解决TypeError: Encoders require their input to be uniformly strings or numbers. Got [‘float‘, ‘int‘,
成功解决TypeError: Encoders require their input to be uniformly strings or numbers. Got ['float', 'int', ...
最新文章
- vs2005什么时候能出正式版
- SQL Server:APPLY表运算符
- 【Python】xlwt基础:excel存取读写
- 介绍Python中方法ljust(),rjust(),center()和zfill()
- SDOI2020游记
- ES6语法大全 export,import,for.of循环,promise等等
- form-validation-engine中的正则表达式
- 这年头「野路子」产品太多了
- 一张图学会python 3_一张图学会Python?想啥呢?!
- Git笔记(28) 签署工作
- VC下几种转换为UNICODE字符串的方法
- Linux 命令(72)—— ulimit 命令(builtin)
- ORM框架之Mybatis(三)延迟加载、开启一二级缓存及使用注解增删改查
- 数据结构上机实践第五周项目2 - 建立链栈算法库
- 基于SSM的废品商城
- 流程图神器——代码转流程图软件、在线流程图绘制软件
- 不忘初心,砥砺前行;只争朝夕,不负韶华——国家开放大学2018年度首届优秀青年教师总结报告
- 双十一大促客服必备话术
- 电脑软件打不开,提示缺失某个.dll文件的原因及解决办法(亲测能用)
- ThinkPHP框架总结之配置及使用
热门文章
- 通信与信号处理杂文目录
- Node安装node-sass总是下载超时问题解决
- 「深度」想当有实体的“贾维斯”,智能家居机器人还需跨越多个桎梏
- ORACLE 12C安装
- 自己封装JSTL 自定义标签
- 好分数a1a5_好分数怎么查看班级排名 七年级学生成绩查询
- numpy找到数组中符合条件的数
- Vivado清理和压缩工程的方法
- 中兴手机数据通道打不开_我用的是中兴手机,里面有流量,但是数据开不了,应该怎么办呢?...
- spring 定时器设置停止_单片机MSP430入门-理论⑦--定时器模块-定时器A②