<jupyter_start><jupyter_text>Perform $k$-means on the data<jupyter_code># Load packages
import numpy as np
import pickle

from FDApy.representation.functional_data import DenseFunctionalData

from skfda import FDataGrid
from skfda.ml.clustering import KMeans
# Load data
with open('./data/scenario_1.pkl', 'rb') as f:
    data_fd = pickle.load(f)
# Create FDataGrid object
data_matrix = data_fd.values
sample_points = data_fd.argvals['input_dim_0']
fdata = FDataGrid(data_matrix, sample_points)
# Compute derivatives
fdata_derivatives = fdata.derivative(order=1)
# Perform k-means
res = {}
for i in np.arange(2, 9, 1):
    kmeans = KMeans(n_clusters=i)
    kmeans.fit(fdata)
    res[i] = kmeans.predict(fdata)
# Perform k-means on derivatives
res_derivative = {}
for i in np.arange(2, 9, 1):
    kmeans = KMeans(n_clusters=i)
    kmeans.fit(fdata_derivatives)
    res_derivative[i] = kmeans.predict(fdata_derivatives)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10770855332629356, 'fraction_numerical': 0.009503695881731784, 'mean_word_length': 5.448979591836735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '86354', 'license': 'MIT', 'n_tokens_mistral': 381, 'n_tokens_neox': 353, 'n_words': 78, 'path': 'scenario_1/03-kmeans.ipynb', 'repo_name': 'StevenGolovkine/fcubt', 'size': '947'}