<jupyter_start><jupyter_text>Scikit Learn 中 k-邻近算法使用<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
X_train = np.array([
    [1.52257606, 7.49321217],
    [0.8008419 , 3.66472342],
    [2.56315092, 7.35571784],
    [1.97784174, 7.67234035],
    [1.87810736, 6.08917511],
    [4.18258396, 5.32894219],
    [7.18557125, 7.03119673],   
    [6.37347031, 1.55094849],
    [6.57819843, 6.34820027],
    [5.55726854, 5.53267332]]
)
y_train = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])
X_train.shape
y_train.shape
x = np.array([3.18557125, 6.03119673])
from sklearn.neighbors import KNeighborsClassifier
kNN_classifier = KNeighborsClassifier(n_neighbors=6)
kNN_classifier.fit(X_train, y_train)
X_predict = x.reshape(1, -1)
X_predict
y_predict = kNN_classifier.predict(X_predict)
y_predict[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14957780458383596, 'fraction_numerical': 0.2545235223160434, 'mean_word_length': 4.570469798657718, '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': '580171', 'license': 'MIT', 'n_tokens_mistral': 517, 'n_tokens_neox': 391, 'n_words': 64, 'path': '01kNN/02use-kNN-in-Scikit-Learn.ipynb', 'repo_name': 'ovtenng/ML-Algorithms-Action', 'size': '829'}