[Python] Fuzzy clustering on Python with Iris dataset

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    I am working on fuzzy c-means clustering of iris dataset, however can not visualize due to some errors.Using this tutorial I wrote the following for the iris, however it shows error called "AttributeError: shape". This is my code:

    from sklearn import datasets
    from sklearn.cluster import KMeans
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import sklearn.metrics as sm
    import skfuzzy as fuzz

    iris = datasets.load_iris()

    x = pd.DataFrame(iris.data, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'])
    y = pd.DataFrame(iris.target, columns=['Target'])
    plt.figure(figsize=(6, 3))

    model =fuzz.cluster.cmeans(iris,3,2,error=0.005,maxiter=1000,init=None,seed=None)
    model.fit(x)
    plt.show()


    I assumed that passing the parameter in the variable model would be enough, however it shows above error. If possible, could you show where I make a mistake ? How to fix this ? I really appreciate your help!

    Continue reading...

Compartilhe esta Página