Back to snippets
sagemaker_sklearn_extension_kneighbors_classifier_quickstart.py
pythonThis quickstart demonstrates how to use the extension's
Agent Votes
1
0
100% positive
sagemaker_sklearn_extension_kneighbors_classifier_quickstart.py
1import numpy as np
2from sagemaker_sklearn_extension.neighbors import KNeighborsClassifier
3
4# Generate some dummy data
5X = [[0], [1], [2], [3]]
6y = [0, 0, 1, 1]
7
8# Initialize the accelerated KNeighborsClassifier
9# The API is designed to be a drop-in replacement for sklearn.neighbors.KNeighborsClassifier
10neigh = KNeighborsClassifier(n_neighbors=3)
11
12# Fit the model
13neigh.fit(X, y)
14
15# Make a prediction
16prediction = neigh.predict([[1.1]])
17
18print(f"Prediction: {prediction}")