模糊C中具有错误维度的聚类中心意味着聚类

时间:2018-04-27 06:29:40

标签: python-3.x scikit-learn cluster-analysis fuzzy-c-means

你好我在下面写了简单的代码来探索模糊Cmean聚类

import pandas as pd
import numpy as np
from os import listdir
from sklearn.model_selection import train_test_split
from skfuzzy.cluster import cmeans, cmeans_predict
from sklearn.metrics import classification_report,confusion_matrix

def find_csv_filenames( path_to_dir, suffix=".csv" ):
    filenames = listdir(path_to_dir)
    return [ path_to_dir+filename for filename in filenames if filename.endswith( suffix ) ]

listFiles = find_csv_filenames('<Path to folder with csv files>')
for files in listFiles:
    df = pd.read_csv(files)
    df.loc[df['bug']>1,'bug']=1
    df2 =df.iloc[:,3:]
    #Above are some pre processing steps
    #Below splitting data for test and train
    X_train, X_test = train_test_split(df2, test_size=0.30)
    #dropping bug column for unsupervised learning
    X_train2 = X_train.drop('bug',axis=1) 
    X_test2  = X_test.drop('bug',axis=1) 
    print (X_train2.shape)
    #Shape is 163,20 for 163 training data with 20 features
    cntr, u, u0, d, jm, p, fpc = cmeans(X_train2,2,2,0.25,500,init=None, seed=None)
    print(cntr.shape)
    #above shape is coming 2,163

来自上述cmeam算法的中心大小(2,163)但由于我的训练数据只有20个特征,因此 cntr的形状应该是(2,20)即可。无法理解我错在哪里

1 个答案:

答案 0 :(得分:1)

来自<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <h2>Test SMS Triggers</h2> <p id="demo1"></p> <p id="demo2"></p> <p id="demo3"></p>文档:

  

数据:2d数组,大小(S,N)

     

要群集的数据。 N是数据集的数量; S是每个样本向量中的要素数。

所以你需要调整你的输入,而不是测试,但是:

skfuzzy

应该工作。