You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.0 KiB

3 years ago
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# 聚类效果怎么样?"
  8. ]
  9. },
  10. {
  11. "cell_type": "code",
  12. "execution_count": 3,
  13. "metadata": {},
  14. "outputs": [
  15. {
  16. "name": "stdout",
  17. "output_type": "stream",
  18. "text": [
  19. "the predicted result:\n",
  20. " [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
  21. " 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
  22. " 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 0 0 0 0 2 0 0 0 0\n",
  23. " 0 0 2 2 0 0 0 0 2 0 2 0 2 0 0 2 2 0 0 0 0 0 2 0 0 0 0 2 0 0 0 2 0 0 0 2 0\n",
  24. " 0 2]\n",
  25. "the real answer:\n",
  26. " [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
  27. " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
  28. " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2\n",
  29. " 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
  30. " 2 2]\n"
  31. ]
  32. }
  33. ],
  34. "source": [
  35. "from sklearn import datasets\n",
  36. "from sklearn.cluster import KMeans\n",
  37. "iris = datasets.load_iris()\n",
  38. "X = iris.data\n",
  39. "y = iris.target #保留标签\n",
  40. "clf=KMeans(n_clusters=3)\n",
  41. "model=clf.fit(X)\n",
  42. "predicted=model.predict(X)\n",
  43. "\n",
  44. "#补充程序,显示如下的运行结果,并将预测值与标签真值进行对比\n",
  45. "\n",
  46. "\n"
  47. ]
  48. },
  49. {
  50. "cell_type": "code",
  51. "execution_count": null,
  52. "metadata": {},
  53. "outputs": [],
  54. "source": []
  55. }
  56. ],
  57. "metadata": {
  58. "kernelspec": {
  59. "display_name": "Python 3",
  60. "language": "python",
  61. "name": "python3"
  62. },
  63. "language_info": {
  64. "codemirror_mode": {
  65. "name": "ipython",
  66. "version": 3
  67. },
  68. "file_extension": ".py",
  69. "mimetype": "text/x-python",
  70. "name": "python",
  71. "nbconvert_exporter": "python",
  72. "pygments_lexer": "ipython3",
  73. "version": "3.6.5"
  74. }
  75. },
  76. "nbformat": 4,
  77. "nbformat_minor": 2
  78. }