<jupyter_start><jupyter_text>download dataset<jupyter_code>!wget https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data<jupyter_output><empty_output><jupyter_text>install extra 3d plot lib<jupyter_code>!pip install plotly_express<jupyter_output><empty_output><jupyter_text>imports<jupyter_code>from sklearn.cluster import KMeans

import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import plotly_express as px<jupyter_output><empty_output><jupyter_text>read data<jupyter_code>data = pd.read_csv("iris.data", names=["sepal length", "sepal width", "petal length", "petal width", "class"])<jupyter_output><empty_output><jupyter_text>separete train data<jupyter_code>x = data.drop(["class"], axis=1).values
data.head()<jupyter_output><empty_output><jupyter_text>train and predict<jupyter_code>preds = []
for i in range(5):
    kmeans = KMeans(n_clusters=3, n_init=1, max_iter=30, init="random")
    kmeans.fit(x)
    pred = kmeans.predict(x)
    preds.append(pred)
    print("run:{0} cluster points\n1: {1}\n2: {2}\n3: {3}\n".format(i, x[pred == 0].shape[0], x[pred == 1].shape[0], x[pred == 2].shape[0]))<jupyter_output><empty_output><jupyter_text>plot graphs<jupyter_code>px.scatter_3d(data, x="petal length", y="petal width", z="sepal length", size="sepal width", color=preds[4])
px.scatter_3d(data, x="petal length", y="petal width", z="sepal length", size="sepal width", color="class")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16030013642564803, 'fraction_numerical': 0.015688949522510234, 'mean_word_length': 7.837349397590361, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '534457', 'license': 'MIT', 'n_tokens_mistral': 588, 'n_tokens_neox': 575, 'n_words': 91, 'path': ' clustering/data_mining_hw5.ipynb', 'repo_name': 'cccaaannn/machine_learning_colab', 'size': '1466'}