[关闭]
@spiritnotes 2016-02-25T17:33:41.000000Z 字数 679 阅读 1482

数据可视化

机器学习实践


  1. def Visualization(data, feature_indexs = None):
  2. features = data['data']
  3. names = data['feature_names']
  4. target = data['target']
  5. if feature_indexs is None:
  6. feature_indexs = list(range(len(names)))
  7. for i in feature_indexs:
  8. for j in feature_indexs:
  9. if j <= i:
  10. continue
  11. show_plt(features, i, j, target, names)
  12. def show_plt(data, i, j, target, names):
  13. from matplotlib import pyplot as plt
  14. vis_types = ">ox"
  15. vis_colors = "rgb"
  16. target_set = set(target)
  17. for class_, marker, color in zip(target_set, vis_types, vis_colors):
  18. rows = (target == class_)
  19. plt.scatter(data[rows ,i],data[rows, j], marker=marker,c=color)
  20. if names:
  21. xlabel, ylabel = names[i], names[j]
  22. else:
  23. xlabel, ylabel = str(i), str(j)
  24. plt.xlabel(xlabel)
  25. plt.ylabel(ylabel)
  26. plt.autoscale(tight=True)
  27. plt.show()
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注