溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何用K-means算法的Java實現(xiàn)聚類分析681個三國武將

發(fā)布時間:2021-10-29 16:01:05 來源:億速云 閱讀:109 作者:柒染 欄目:編程語言

如何用K-means算法的Java實現(xiàn)聚類分析681個三國武將,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

一,k-means算法介紹:

k-means算法接受輸入量 k ;然后將n個數據對象劃分為 k個聚類以便使得所獲得的聚類滿足:同一聚類中的對象相似度較高;而不同聚類中的對象相似度較小。聚類相似度是利用各聚類中對象的均值所獲得一個“中心對象”(引力中心)來進行計算的。k個聚類具有以下特點:各聚類本身盡可能的緊湊,而各聚類之間盡可能的分開?!個聚類具有以下特點:各聚類本身盡可能的緊湊,而各聚類之間盡可能的分開。

k-means算法的工作過程說明如下:首先從n個數據對象任意選擇 k 個對象作為初始聚類中心;而對于所剩下其它對象,則根據它們與這些聚類中心的相似度(距離),分別將它們分配給與其最相似的(聚類中心所代表的)聚類;然后再計算每個所獲新聚類的聚類中心(該聚類中所有對象的均值);不斷重復這一過程直到標準測度函數開始收斂為止。一般都采用均方差作為標準測度函數。k個聚類具有以下特點:各聚類本身盡可能的緊湊,而各聚類之間盡可能的分開。

二,k-means算法基本步驟:

(1) 從 n個數據對象任意選擇 k 個對象作為初始聚類中心;

(2) 根據每個聚類對象的均值(中心對象),計算每個對象與這些中心對象的距離;并根據最小距離重新對相應對象進行劃分;

(3) 重新計算每個(有變化)聚類的均值(中心對象);

(4) 計算標準測度函數,當滿足一定條件,如函數收斂時,則算法終止;如果條件不滿足則回到步驟(2),不斷重復直到標準測度函數開始收斂為止。(一般都采用均方差作為標準測度函數。)

三,k-means算法的java實現(xiàn):

一共有七個類,General.java代表武將對象, Distance.java距離類計算各個武將到中心武將之間的距離, Cluster.java聚類對象包含一個中心武將和該聚類中所有武將, Kmeans.java核心的聚類算法類, Tool.java工具類用于轉換武將的星級為數字等操作, TestKmeans.java測試類即入口文件, DomParser.java用于讀取xml中的681個武將。

具體思路:先從general.xml文件中讀取681個武將,然后隨機選取初始類中心,計算各個武將到中心武將的距離,根據最小的距離進行聚類,然后重新根據平均值新的聚類的類中心,重新計算各個武將到新的中心武將的距離,直到更新后的聚類與原來的聚類包含的武將不再改變,即收斂時結束。

具體代碼如下:

1,General.java

</pre><pre name="code" class="java">
</pre><pre name="code" class="java">package kmeans;   public class General {            private String name; // 姓名      private int render; // 星級      private int tongshai; // 統(tǒng)帥      private int wuli; // 武力      private int zhili; // 智力      private int polic; // 政治      private int qiangbin; // 槍兵      private int jibin; // 戟兵      private int nubin; // 弩兵      private int qibin; // 騎兵      private int binqi; // 兵器      private int tongwu; // 統(tǒng)武      private int tongzhi; // 統(tǒng)智      private int tongwuzhi; // 統(tǒng)武智      private int tongwuzhizheng; // 統(tǒng)武智政      private int salary; // 50級工資       public General(int render, String name, int tongshai, int wuli, int zhili,              int polic, int qiangbin, int jibin, int nubin, int qibin,              int binqi, int tongwu, int tongzhi, int tongwuzhi,              int tongwuzhizheng, int salary) {          super();          this.name = name;          this.render = render;          this.tongshai = tongshai;          this.wuli = wuli;          this.zhili = zhili;          this.polic = polic;          this.qiangbin = qiangbin;          this.jibin = jibin;          this.nubin = nubin;          this.qibin = qibin;          this.binqi = binqi;          this.tongwu = tongwu;          this.tongzhi = tongzhi;          this.tongwuzhi = tongwuzhi;          this.tongwuzhizheng = tongwuzhizheng;          this.salary = salary;      }       public General(int render, int tongshai, int wuli, int zhili, int polic,              int qiangbin, int jibin, int nubin, int qibin, int binqi,              int tongwu, int tongzhi, int tongwuzhi, int tongwuzhizheng,              int salary) {          super();          this.name = "聚類中心";          this.render = render;           this.tongshai = tongshai;           this.wuli = wuli;          this.zhili = zhili;          this.polic = polic;          this.qiangbin = qiangbin;          this.jibin = jibin;          this.nubin = nubin;          this.qibin = qibin;          this.binqi = binqi;          this.tongwu = tongwu;          this.tongzhi = tongzhi;          this.tongwuzhi = tongwuzhi;          this.tongwuzhizheng = tongwuzhizheng;          this.salary = salary;      }       public General() {      }       @Override     public String toString() {          return "武將 [name=" + name + ", render=" + Tool.dxingji(render)                  + ", tongshai=" + tongshai + ", wuli=" + wuli + ", zhili="                 + zhili + ", polic=" + polic + ", qiangbin="                 + Tool.dchange(qiangbin) + ", jibin=" + Tool.dchange(jibin)                  + ", nubin=" + Tool.dchange(nubin) + ", qibin="                 + Tool.dchange(qibin) + ", binqi=" + Tool.dchange(binqi)                  + ", tongwu=" + tongwu + ", tongzhi=" + tongzhi                  + ", tongwuzhi=" + tongwuzhi + ", tongwuzhizheng="                 + tongwuzhizheng + ", salary=" + salary + "]";      }       public String getName() {          return name;      }       public void setName(String name) {          this.name = name;      }       public int getRender() {          return render;      }       public void setRender(int render) {          this.render = render;      }       public int getTongshai() {          return tongshai;      }       public void setTongshai(int tongshai) {          this.tongshai = tongshai;      }       public int getWuli() {          return wuli;      }       public void setWuli(int wuli) {          this.wuli = wuli;      }       public int getZhili() {          return zhili;      }       public void setZhili(int zhili) {          this.zhili = zhili;      }       public int getPolic() {          return polic;      }       public void setPolic(int polic) {          this.polic = polic;      }       public int getQiangbin() {          return qiangbin;      }       public void setQiangbin(int qiangbin) {          this.qiangbin = qiangbin;      }       public int getJibin() {          return jibin;      }       public void setJibin(int jibin) {          this.jibin = jibin;      }       public int getNubin() {          return nubin;      }       public void setNubin(int nubin) {          this.nubin = nubin;      }       public int getQibin() {          return qibin;      }       public void setQibin(int qibin) {          this.qibin = qibin;      }       public int getBinqi() {          return binqi;      }       public void setBinqi(int binqi) {          this.binqi = binqi;      }       public int getTongwu() {          return tongwu;      }       public void setTongwu(int tongwu) {          this.tongwu = tongwu;      }       public int getTongzhi() {          return tongzhi;      }       public void setTongzhi(int tongzhi) {          this.tongzhi = tongzhi;      }       public int getTongwuzhi() {          return tongwuzhi;      }       public void setTongwuzhi(int tongwuzhi) {          this.tongwuzhi = tongwuzhi;      }       public int getTongwuzhizheng() {          return tongwuzhizheng;      }       public void setTongwuzhizheng(int tongwuzhizheng) {          this.tongwuzhizheng = tongwuzhizheng;      }       public int getSalary() {          return salary;      }       public void setSalary(int salary) {          this.salary = salary;      }   }

2,Distance.java

</pre><pre name="code" class="java">package kmeans;  /**   * 這個類用于計算距離的。。   *   */ public class Distance {      int dest;// 目的      int source;// 源      double dist;// 歐式距離       public int getDest() {          return dest;      }       public void setDest(int dest) {          this.dest = dest;      }       public int getSource() {          return source;      }       public void setSource(int source) {          this.source = source;      }       public double getDist() {          return dist;      }       public void setDist(double dist) {          this.dist = dist;      }      /**       * 計算源和目的的距離       * @param dest 目的武將       * @param source 源武將       * @param dist 兩者間的距離       */     public Distance(int dest, int source, double dist) {          this.dest = dest;          this.source = source;          this.dist = dist;      }       public Distance() {      }   }

3,Cluster.java

</pre><pre name="code" class="java">package kmeans;   import java.util.ArrayList;   public class Cluster {      private int center;// 聚類中心武將的id      private ArrayList<General> ofCluster = new ArrayList<General>();// 屬于這個聚類的武將的集合       public int getCenter() {          return center;      }       public void setCenter(int center) {          this.center = center;      }       public ArrayList<General> getOfCluster() {          return ofCluster;      }       public void setOfCluster(ArrayList<General> ofCluster) {          this.ofCluster = ofCluster;      }       public void addGeneral(General general) {          if (!(this.ofCluster.contains(general)))              this.ofCluster.add(general);      }  }

4,Kmeans.java

</pre><pre name="code" class="java">
package kmeans;   import java.util.*;   public class Kmeans {      public ArrayList<General> allGenerals = null;      public int totalNumber = 0;// 得到所有的武將數目      public int K = 0;// 假設K=10       public Kmeans() {          allGenerals = new DomParser().prepare();          totalNumber = allGenerals.size();          K = 3;      }       // 第一次隨機選取聚類中心      public Set<Integer> firstRandom() {          Set<Integer> center = new HashSet<Integer>();// 聚類中心的點的id,采用set保證不會有重復id          Random ran = new Random();          int roll = ran.nextInt(totalNumber);          while (center.size() < K) {              roll = ran.nextInt(totalNumber);              center.add(roll);          }          return center;      }       // 根據聚類中心初始化聚類信息      public ArrayList<Cluster> init(Set<Integer> center) {          ArrayList<Cluster> cluster = new ArrayList<Cluster>();// 聚類 的數組          Iterator<Integer> it = center.iterator();          while (it.hasNext()) {              Cluster c = new Cluster();// 代表一個聚類              c.setCenter(it.next());              cluster.add(c);          }          return cluster;      }       /**       * 計算各個武將到各個聚類中心的距離,重新聚類       *        * @param cluster       *            聚類數組,用來聚類的,根據最近原則把武將聚類       * @param center       *            中心點id,用于計算各個武將到中心點的距離 return cluster 聚類后的所有聚類組成的數組       */     public ArrayList<Cluster> juLei(Set<Integer> center,              ArrayList<Cluster> cluster) {          ArrayList<Distance> distence = new ArrayList<Distance>();// 存放距離信息,表示每個點到各個中心點的距離組成的數組          General source = null;          General dest = null;          int id = 0;// 目的節(jié)點id          int id2 = 0;// 源節(jié)點id          Object[] p = center.toArray();// p 為聚類中心點id數組          boolean flag = false;          // 分別計算各個點到各個中心點的距離,并將距離最小的加入到各個聚類中,進行聚類          for (int i = 0; i < totalNumber; i++) {              // 每個點計算完,并聚類到距離最小的聚類中就清空距離數組              distence.clear();              // 計算到j個類中心點的距離,便利各個中心點              for (int j = 0; j < center.size(); j++) {                  // 如果該點不在中心點內 則計算距離                  if (!(center.contains(i))) {                      flag = true;                      // 計算距離                      source = allGenerals.get(i);// 某個點                      dest = allGenerals.get((Integer) p[j]);// 各個 中心點                      // 計算距離并存入數組                      distence.add(new Distance((Integer) p[j], i, Tool.juli(                              source, dest)));                  } else {                      flag = false;                  }              }              // 說明計算完某個武將到類中心的距離,開始比較              if (flag == true) {                  // 排序比較一個點到各個中心的距離的大小,找到距離最小的武將的 目的id,和源id,                  // 目的id即類中心點id,這個就歸到這個中心點所在聚類中                  double min = distence.get(0).getDist();// 默認第一個distance距離是最小的                  // 從1開始遍歷distance數組                  int minid = 0;                  for (int k = 1; k < distence.size(); k++) {                      if (min > distence.get(k).getDist()) {                          min = distence.get(k).getDist();                          id = distence.get(k).getDest();// 目的,即類中心點                          id2 = distence.get(k).getSource();// 某個武將                          minid = k;                      } else {                          id = distence.get(minid).getDest();                          id2 = distence.get(minid).getSource();                      }                  }                  // 遍歷cluster聚類數組,找到類中心點id與最小距離目的武將id相同的聚類                  for (int n = 0; n < cluster.size(); n++) {                      // 如果和中心點的id相同 則setError                      if (cluster.get(n).getCenter() == id) {                          cluster.get(n).addGeneral(allGenerals.get(id2));// 將與該聚類中心距離最小的武將加入該聚類                          break;                      }                  }              }          }          return cluster;      }       // 產生新的聚類中心點數組      public Set<Integer> updateCenter() {          Set<Integer> center = new HashSet<Integer>();          for (int i = 0; i < K; i++) {              center.add(i);          }          return center;      }       // 更新聚類中心, 求平均值      public ArrayList<Cluster> updateCluster(ArrayList<Cluster> cluster) {          ArrayList<Cluster> result = new ArrayList<Cluster>();          // 重新產生的新的聚類中心組成的數組          // k個聚類進行更新聚類中心          for (int j = 0; j < K; j++) {              ArrayList<General> ps = cluster.get(j).getOfCluster();// 該聚類的所有 武將                                                                      // 組成的數組              ps.add(allGenerals.get(cluster.get(j).getCenter()));// 同時將該類中心對應的武將加入該武將數組              int size = ps.size();// 該聚類的長度大小              // 計算和,然后在計算平均值              int sumrender = 0, sumtongshai = 0, sumwuli = 0, sumzhili = 0, sumjibin = 0, sumnubin = 0, sumqibin = 0, sumpolic = 0, sumqiangbin = 0, sumbinqi = 0, sumtongwu = 0, sumtongzhi = 0, sumtongwuzhi = 0, sumtongwuzhizheng = 0, sumsalary = 0;              for (int k1 = 0; k1 < size; k1++) {                  sumrender += ps.get(k1).getRender();                  sumtongshai += ps.get(k1).getRender();                  sumwuli += ps.get(k1).getWuli();                  sumzhili += ps.get(k1).getZhili();                  sumjibin += ps.get(k1).getJibin();                  sumnubin += ps.get(k1).getNubin();                  sumqibin += ps.get(k1).getQibin();                  sumpolic += ps.get(k1).getPolic();                  sumqiangbin += ps.get(k1).getQiangbin();                  sumbinqi += ps.get(k1).getBinqi();                  sumtongwu += ps.get(k1).getTongwu();                  sumtongzhi += ps.get(k1).getTongzhi();                  sumtongwuzhi += ps.get(k1).getTongwuzhi();                  sumtongwuzhizheng += ps.get(k1).getTongwuzhizheng();                  sumsalary += ps.get(k1).getSalary();              }              // 產生新的聚類,然后加入到聚類數組中              Cluster newCluster = new Cluster();              newCluster.setCenter(j);              // 計算平均值并構造新的武將對象              newCluster.addGeneral(new General(sumrender / size, sumtongshai                      / size, sumwuli / size, sumzhili / size, sumjibin / size,                      sumnubin / size, sumqibin / size, sumpolic = 0,                      sumqiangbin = 0, sumbinqi / size, sumtongwu / size,                      sumtongzhi / size, sumtongwuzhi / size, sumtongwuzhizheng                              / size, sumsalary / size));              result.add(newCluster);          }          return result;       }       /**       * 計算各個武將到各個更新后的聚類中心的距離,重新聚類       * @param update 更新后的聚類中心       * @param cluster 要存儲的聚類中心       */     public ArrayList<Cluster> updateJuLei(ArrayList<Cluster> update,              ArrayList<Cluster> cluster) {          ArrayList<Distance> distence = new ArrayList<Distance>();// 存放距離信息,表示每個點到各個中心點的距離組成的數組          General source = null;          General dest = null;          int id = 0;// 目的節(jié)點id          int id2 = 0;// 源節(jié)點id          //Object[] p = center.toArray();// p 為聚類中心點id數組          boolean flag = false;          // 分別計算各個點到各個中心點的距離,并將距離最小的加入到各個聚類中,進行聚類          for (int i = 0; i < totalNumber; i++) {              // 每個點計算完,并聚類到距離最小的聚類中就清空距離數組              distence.clear();              // 計算到j個類中心點的距離,便利各個中心點              //for (int j = 0; j < center.size(); j++) {              for (int j = 0; j < update.size(); j++) {                  // 如果該點不在中心點內 則計算距離                  //if (!(center.contains(i))) {                      flag = true;                      // 計算距離                      source = allGenerals.get(i);// 某個點                      // dest = allGenerals.get((Integer) p[j]);// 各個 中心點                      dest = update.get(j).getOfCluster().get(0);// 各個 中心點                      // 計算距離并存入數組                      //distence.add(new Distance((Integer) p[j], i, Tool.juli(                      distence.add(new Distance(update.get(j).getCenter(), i, Tool.juli(                              source, dest)));                      /*} else {                      flag = false;                  }*/             }              // 說明計算完某個武將到類中心的距離,開始比較              if (flag == true) {                  // 排序比較一個點到各個中心的距離的大小,找到距離最小的武將的 目的id,和源id,                  // 目的id即類中心點id,這個就歸到這個中心點所在聚類中                  double min = distence.get(0).getDist();// 默認第一個distance距離是最小的                  // 從1開始遍歷distance數組                  int mid = 0;                  for (int k = 1; k < distence.size(); k++) {                      if (min > distence.get(k).getDist()) {                          min = distence.get(k).getDist();                          id = distence.get(k).getDest();// 目的,即類中心點                          id2 = distence.get(k).getSource();// 某個武將                          mid = k;                      } else {                          id = distence.get(mid).getDest();                          id2 = distence.get(mid).getSource();                      }                  }                  // 遍歷cluster聚類數組,找到類中心點id與最小距離目的武將id相同的聚類                  for (int n = 0; n < cluster.size(); n++) {                      // 如果和中心點的id相同 則setError                      if (cluster.get(n).getCenter() == id) {                          cluster.get(n).addGeneral(allGenerals.get(id2));// 將與該聚類中心距離最小的武將加入該聚類                      }                  }              }          }          return cluster;      }       // 不斷循環(huán)聚類直到各個聚類沒有重新分配      public ArrayList<Cluster> getResult() {          ArrayList<Cluster> result = new ArrayList<Cluster>();          ArrayList<Cluster> temp = new ArrayList<Cluster>();          boolean flag = false;          // 得到隨機中心點然后進行聚類          Set<Integer> center = firstRandom();          result = juLei(center, init(center));          print(result);          do {              // 重新聚類              ArrayList<Cluster> up = updateCluster(result);//新的聚類中心              ArrayList<Cluster> cluster = init(updateCenter()); // 得到更新后的中心點對應的聚類數組              temp = updateJuLei(up, cluster);              //print(temp);              flag = isEquals(temp, result);              result = temp;          } while (!flag);          return result;      }            public boolean isEquals(ArrayList<Cluster> temp, ArrayList<Cluster> result){          boolean flag = false;          if(temp.size() != result.size()){              return flag;          }          for(Cluster tem : temp){              for(Cluster res : result){                  if(tem.getCenter() == res.getCenter()){                      flag = true;                  }              }              // 如果找了一輪沒找到 則說明兩個聚類              if(flag == false){                  return false;              }else{// 如果找了一輪找到了,那么接著找                  flag = false;              }          }          //如果代碼能進行到這邊,說明是true          flag = true;          return flag;      }            //輸出所有的聚類      public void print(ArrayList<Cluster> cs) {          System.out.println("***************************************");          for (int i = 0; i < cs.size(); i++) {              Cluster c = cs.get(i);              System.out.println("-----------------------------------------------------");              System.out.println("center: " + allGenerals.get(c.getCenter()));              ArrayList<General> p = c.getOfCluster();              for (int j = 0; j < p.size(); j++) {                  System.out.println("general:"+p.get(j)+"\n");              }          }      }   }

5,Tool.java

</pre><pre name="code" class="java">package kmeans;   public class Tool {      //將各種武器的精通程度轉為數字      public static int change(String str) {          int result = str.equals("精") ? 4 : (str.equals("神") ? 3 : (str                  .equals("通") ? 2 : 1));          return result;      }      //將星級轉為數字      public static int xingji(String str) {          int result = str.equals("★★★★★") ? 5 : (str.equals("★★★★") ? 4 : (str                  .equals("★★★") ? 3 : (str.equals("★★") ? 2 : 1)));          return result;      }      //反轉 將各種武器的數字轉為精通程度      public static String dchange(int str) {          String result = str== 4 ? "精" : (str== 3 ? "神" : (str== 2 ? "通" : "疏"));          return result;      }      //反轉 將數字轉為星級      public static String dxingji(int str) {          String result = str== 5 ? "★★★★★" : (str== 4 ? "★★★★" : (str== 3 ? "★★★" : (str == 2 ? "★★" : "★")));          return result;      }      //計算歐式距離 傳入兩個將軍對象。。      public static double juli(General g1, General g2) {          double result = (Double) Math.sqrt(StrictMath.pow(g1.getRender() - g2.getRender(), 2)                  + StrictMath.pow(g1.getTongshai() - g2.getTongshai(), 2)                  + StrictMath.pow(g1.getWuli() - g2.getWuli(), 2)                  + StrictMath.pow(g1.getZhili() - g2.getZhili(), 2)                  + StrictMath.pow(g1.getPolic() - g2.getPolic(), 2)                  + StrictMath.pow(g1.getQiangbin() - g2.getQiangbin(), 2)                  + StrictMath.pow(g1.getQibin() - g2.getQibin(), 2)                  + StrictMath.pow(g1.getJibin() - g2.getJibin(), 2)                  + StrictMath.pow(g1.getNubin() - g2.getNubin(), 2)                  + StrictMath.pow(g1.getBinqi() - g2.getBinqi(), 2)                  + StrictMath.pow(g1.getTongwu() - g2.getTongwu(), 2)                  + StrictMath.pow(g1.getTongzhi() - g2.getTongzhi(), 2)                  + StrictMath.pow(g1.getTongwuzhizheng() - g2.getTongwuzhizheng(), 2)                  + StrictMath.pow(g1.getTongwuzhi() - g2.getTongwuzhi(), 2)                  + StrictMath.pow(g1.getSalary() - g2.getSalary(), 2)                  );          return result;      }  }

6,DomParser.java

</pre><pre name="code" class="java">package kmeans;   import javax.xml.parsers.*;   import java.io.*;  import java.util.ArrayList;   import org.w3c.dom.*;  import org.xml.sax.SAXException;   public class DomParser {       private ArrayList<General> generals = new ArrayList<General>();       public ArrayList<General> prepare(){          // get dom解析器工廠          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();          factory.setIgnoringElementContentWhitespace(true);          // get dom 解析器          DocumentBuilder builder = null;          try {              builder = factory.newDocumentBuilder();          } catch (ParserConfigurationException e) {              e.printStackTrace();          }          // 解析文檔          Document doc = null;          try {              doc = builder.parse(new File("general.xml"));          } catch (SAXException e) {              e.printStackTrace();          } catch (IOException e) {              e.printStackTrace();          }          // 取得根節(jié)點          Element generalList = doc.getDocumentElement();          // 得到所有row節(jié)點          NodeList nodeList = generalList.getElementsByTagName("Row");          // 便利所有row節(jié)點          for (int i = 1; i < nodeList.getLength(); i++) {                            System.out.println("------------the " + i                      + " element--------------");                            Node row = nodeList.item(i);              // 取得所有Data數據              NodeList attList = row.getChildNodes();              // 取得數據中的各個部分, 并加入ArrayList中              generals.add(new General(Tool.xingji(attList.item(1)                      .getTextContent()), attList.item(3).getTextContent(),                      Integer.parseInt(attList.item(5).getTextContent()),                       Integer.parseInt(attList.item(7).getTextContent()),                      Integer.parseInt(attList.item(9).getTextContent()),                       Integer.parseInt(attList.item(11).getTextContent()),                       Tool.change(attList.item(13).getTextContent()),                      Tool.change(attList.item(15).getTextContent()),                       Tool.change(attList.item(17).getTextContent()),                       Tool.change(attList.item(19).getTextContent()),                       Tool.change(attList.item(21).getTextContent()),                       Integer.parseInt(attList.item(23).getTextContent()),                      Integer.parseInt(attList.item(25).getTextContent()),                      Integer.parseInt(attList.item(27).getTextContent()),                      Integer.parseInt(attList.item(29).getTextContent()),                      Integer.parseInt(attList.item(31).getTextContent())));                            System.out.println(" 星級:"                     + Tool.xingji(attList.item(1).getTextContent()) + " 姓名:"                     + attList.item(3).getTextContent() + " 統(tǒng)率:"                     + attList.item(5).getTextContent() + " 武力:"                     + attList.item(7).getTextContent() + " 智力:"                     + attList.item(9).getTextContent() + " 政治:"                     + attList.item(11).getTextContent() + "槍兵:"                     + Tool.change(attList.item(13).getTextContent()) + " 戟兵:"                     + Tool.change(attList.item(15).getTextContent()) + " 弩兵:"                     + Tool.change(attList.item(17).getTextContent()) + " 騎兵:"                     + Tool.change(attList.item(19).getTextContent()) + " 兵器:"                     + Tool.change(attList.item(21).getTextContent()) + " 統(tǒng)武:"                     + attList.item(23).getTextContent() + " 統(tǒng)智:"                     + attList.item(25).getTextContent() + " 統(tǒng)武智:"                     + attList.item(27).getTextContent() + " 統(tǒng)武智政:"                     + attList.item(29).getTextContent() + " 50級工資:"                     + attList.item(31).getTextContent() + " ");              /*               * for (int j = 0; j < attList.getLength(); j++) {               * System.out.println(attList.item(j).getTextContent()); }               */         }          return generals;       }  }

7,TestKmeans.java

package kmeans;   public class TestKmeans {       public static void main(String[] args) {          Kmeans_eold kmeans = new Kmeans_eold();          kmeans.print(kmeans.getResult());      }   }

附部分general.xml:

<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"  xmlns:o="urn:schemas-microsoft-com:office:office"  xmlns:x="urn:schemas-microsoft-com:office:excel"  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"  xmlns:html="http://www.w3.org/TR/REC-html40">  <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">   <Created>2006-09-13T11:21:51Z</Created>   <LastSaved>2012-04-26T13:39:57Z</LastSaved>   <Version>14.00</Version>  </DocumentProperties>  <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">   <AllowPNG/>   <RemovePersonalInformation/>  </OfficeDocumentSettings>  <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">   <WindowHeight>5850</WindowHeight>   <WindowWidth>11070</WindowWidth>   <WindowTopX>0</WindowTopX>   <WindowTopY>90</WindowTopY>   <ProtectStructure>False</ProtectStructure>   <ProtectWindows>False</ProtectWindows>  </ExcelWorkbook>  <Styles>   <Style ss:ID="Default" ss:Name="Normal">    <Alignment ss:Vertical="Center"/>    <Borders/>    <Font ss:FontName="宋體" x:CharSet="134" ss:Size="11" ss:Color="#000000"/>    <Interior/>    <NumberFormat/>    <Protection/>   </Style>   <Style ss:ID="s16">    <Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:WrapText="1"/>    <Font ss:FontName="宋體" x:CharSet="134" ss:Bold="1"/>   </Style>   <Style ss:ID="s17">    <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>    <Font ss:FontName="宋體" x:CharSet="134" ss:Size="12" ss:Bold="1"/>   </Style>   <Style ss:ID="s18">    <Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:WrapText="1"/>    <Font ss:FontName="宋體" x:CharSet="134"/>   </Style>   <Style ss:ID="s19">    <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>   </Style>  </Styles>  <Worksheet ss:Name="三國數據">   <Table ss:ExpandedColumnCount="16" ss:ExpandedRowCount="682" x:FullColumns="1"    x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5">    <Row ss:Height="28.5">     <Cell ss:StyleID="s16"><Data ss:Type="String">星級</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">姓名</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">統(tǒng)率</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">武力</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">智力</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">政治</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">槍兵</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">戟兵</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">弩兵</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">騎兵</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">兵器</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">統(tǒng)武</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">統(tǒng)智</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">統(tǒng)武智 </Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">統(tǒng)武智政</Data></Cell>     <Cell ss:StyleID="s17"><Data ss:Type="String">50級工資 </Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">呂布</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">87</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">100</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">26</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">13</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">161</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">194</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">257</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">350</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">19250</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">張飛</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">85</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">98</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">30</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">22</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">168</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">193</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">264</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">350</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">19250</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">関羽</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">95</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">97</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">75</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">62</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">165</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">191</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">260</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">347</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">19085</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">馬超</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">88</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">97</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">44</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">26</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">168</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">187</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">259</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">353</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">19415</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">趙雲</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">91</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">96</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">76</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">65</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">192</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">170</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">267</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">329</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">18095</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">許褚</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">65</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">96</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">36</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">20</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">161</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">101</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">197</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">217</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">11935</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">典韋</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">56</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">95</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">35</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">29</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">151</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">91</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">186</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">215</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">11825</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">甘寧</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">86</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">94</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">76</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">18</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">181</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">183</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">270</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">351</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">19305</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">龐德</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">80</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">94</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">70</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">44</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">174</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">150</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">244</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">288</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">15840</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">文醜</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">78</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">94</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">25</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">25</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">172</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">103</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">197</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">222</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">12210</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">黃忠</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">86</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">93</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">60</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">52</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">185</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">171</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">263</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">321</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">17655</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">太史慈</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">82</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">93</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">66</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">58</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">175</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">148</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">241</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">299</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">16445</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">顏良</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">79</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">93</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">42</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">32</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">172</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">121</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">214</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">246</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">13530</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">張遼</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">93</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">92</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">78</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">58</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">183</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">167</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">257</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">330</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">18150</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">孫策</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">92</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">92</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">69</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">70</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">130</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">192</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">230</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">325</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">17875</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">魏延</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">81</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">92</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">69</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">49</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">精</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">173</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">150</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">242</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">291</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">16005</Data></Cell>    </Row>    <Row>     <Cell ss:StyleID="s18"><Data ss:Type="String">★★★★★</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">華雄</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">81</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">92</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">56</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">40</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">通</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">神</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="String">疏</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">173</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">137</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">229</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">269</Data></Cell>     <Cell ss:StyleID="s19"><Data ss:Type="Number">14795</Data></Cell>    </Row>

最終運行結果截圖如下:

讀取到得武將數據如圖,

如何用K-means算法的Java實現(xiàn)聚類分析681個三國武將

運行后的部分截圖:

如何用K-means算法的Java實現(xiàn)聚類分析681個三國武將

看完上述內容,你們掌握如何用K-means算法的Java實現(xiàn)聚類分析681個三國武將的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI