<jupyter_start><jupyter_text>K-Nearest Neighbor Algorithmus: Parameter:  dataset = (X, Y)  mit X := Features  und Y := Classes  K := Hyperparameter für die nächsten k Nachbarn  sample := Neuer Datenpunkt zum Klassifizieren  Pseudo-Code:kNN (dataset, K, sample):    - Bestimme von jedem Punkt $p \in dataset$ die Distanz, mit der geg. Distanzfunktion.  - Bestimme die $K$ nächst gelegenen Nachbarn und bestimme die zugehörige Klasse von $sample$.<jupyter_code>import numpy as np
np.random.seed(42)
def generate_dataset():
    num_samples_class1 = 10
    num_samples_class2 = 6
    num_samples_class3 = 13
    cov = np.array([[1, 0], [0, 1]])
    data1 = np.random.multivariate_normal(
        np.array([0, 0]), cov, num_samples_class1
    )
    data2 = np.random.multivariate_normal(
        np.array([-10, 4]), cov, num_samples_class2
    )
    data3 = np.random.multivariate_normal(
        np.array([10, 10]), cov, num_samples_class3
    )
    data = np.concatenate((data1, data2, data3), axis=0)
    classes = np.array(
        [0 for i in range(num_samples_class1)] +
        [1 for i in range(num_samples_class2)] +
        [2 for i in range(num_samples_class3)]
    )
    return data, classes<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11156351791530944, 'fraction_numerical': 0.03175895765472313, 'mean_word_length': 3.4854014598540144, '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': '151235', 'license': 'MIT', 'n_tokens_mistral': 458, 'n_tokens_neox': 436, 'n_words': 115, 'path': 'Chapter3_MLIntroduction/KnnAlgorithm/KnnImplementation_preparation_start.ipynb', 'repo_name': 'tomex74/UdemyML', 'size': '1228'}