Data mining using the scikit-learn library:

 # Import necessary libraries

from sklearn.datasets import load_iris from sklearn.cluster import KMeans # Load dataset data = load_iris() X = data.data # Perform clustering using K-means algorithm kmeans = KMeans(n_clusters=3) kmeans.fit(X) # Print the cluster labels print("Cluster labels:") print(kmeans.labels_) In the above program, we first import the necessary libraries. We then load the Iris dataset using the `load_iris` function from scikit-learn. Next, we extract the feature matrix `X` from the dataset.

We then create an instance of the K-means clustering algorithm with `n_clusters=3`, which means we want to find 3 clusters in the data. We fit the algorithm to the data using the `fit` method.

Finally, we print the cluster labels assigned by the algorithm to each data point in the dataset.

Comments

Popular posts from this blog

Ecommerce website

Yes, Python is an object-oriented programming (OOP) language, but it is also a multi-paradigm language

Your task is to find the missing number.