andrews_cluster.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Andrews curves for the Iris dataset."""
  2. import numpy as np
  3. from sklearn import datasets
  4. from vedo import *
  5. from vedo.pyplot import Figure, plot
  6. iris = datasets.load_iris() # loading iris data set
  7. AC = andrews_curves(iris.data)
  8. theta = np.linspace(-np.pi, np.pi, 100)
  9. settings.remember_last_figure_format = True
  10. fig = Figure(
  11. xlim=(-np.pi, np.pi),
  12. ylim=(-2, 16),
  13. padding=0,
  14. axes=dict(htitle="", axes_linewidth=2, xyframe_line=0),
  15. )
  16. setosas = []
  17. for r in AC[:20]: # setosa
  18. p = pol2cart(r, theta).T
  19. fig += plot(theta, r, c="red5")
  20. setosas.append(Line(p))
  21. setosas = merge(setosas).lw(3).c("red5")
  22. versicolors = []
  23. for r in AC[50:70]: # versicolor
  24. p = pol2cart(r, theta).T
  25. fig += plot(theta, r, c="blue5")
  26. versicolors.append(Line(p))
  27. versicolors = merge(versicolors).lw(3).c("blue5")
  28. virginicas = []
  29. for r in AC[100:120]: # virginica
  30. p = pol2cart(r, theta).T
  31. fig += plot(theta, r, c="green5")
  32. virginicas.append(Line(p))
  33. virginicas = merge(virginicas).lw(3).c("green5")
  34. fig = fig.clone2d(size=0.75)
  35. show(setosas, versicolors, virginicas, fig, __doc__, axes=12)