Memuat
Memuat
k-Nearest Neighbors for Sports and Kinesiology
0 views
Classify student fitness category in physical education students from agility and endurance with k-Nearest Neighbors and determine the optimal value of k. k-Nearest Neighbors classifies a point by the majority class among its k nearest neighbours. It suits as a simple baseline for small to medium data with irregular class boundaries.

Classify student fitness category in physical education students from agility and endurance with k-Nearest Neighbors and determine the optimal value of k.
| Role | Variable | Unit |
|---|---|---|
| Main | student fitness category | - |
| Supporting 1 | agility | detik |
| Supporting 2 | endurance | menit |
The k-NN model classifies student fitness category (low/high) from agility and endurance with test accuracy 0.933, F1 0.933 and AUC 0.974. Best k = 17.
Computed from illustrative synthetic data, not from a real study.
k-Nearest Neighbors classifies a point by the majority class among its k nearest neighbours. It suits as a simple baseline for small to medium data with irregular class boundaries.
Report the chosen k with the reason for choosing it, and the test metrics. Note that prediction is slow on large data because the whole training set is stored.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import cross_val_score, train_test_split
from sklearn.metrics import accuracy_score, f1_score
rng = np.random.default_rng(51)
n = 300
agility = np.r_[rng.normal(0, 1, n // 2), rng.normal(2, 1, n // 2)]
endurance = np.r_[rng.normal(0, 1, n // 2), rng.normal(2, 1, n // 2)]
student_fitness_category = np.r_[np.zeros(n // 2), np.ones(n // 2)].astype(int)
X = np.column_stack([agility, endurance])
X_tr, X_te, y_tr, y_te = train_test_split(X, student_fitness_category, test_size=0.25, stratify=student_fitness_category, random_state=51)
ks = range(1, 26, 2)
cv = [cross_val_score(make_pipeline(StandardScaler(), KNeighborsClassifier(k)), X_tr, y_tr, cv=5).mean()
for k in ks]
best_k = list(ks)[int(np.argmax(cv))]
clf = make_pipeline(StandardScaler(), KNeighborsClassifier(best_k)).fit(X_tr, y_tr)
pred = clf.predict(X_te)
print("Best k:", best_k)
print("Accuracy:", round(accuracy_score(y_te, pred), 3), "F1:", round(f1_score(y_te, pred), 3))
plt.plot(list(ks), cv, marker="o")
plt.xlabel("k"); plt.ylabel("CV accuracy")
plt.show()Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$16
excl. 11% VAT
Duration: 3 working days
Output: Python files + result figures
Deliverables
Package 2 · most chosen
US$47
excl. 11% VAT
Duration: 7 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$106
excl. 11% VAT
Duration: 12-15 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. k-Nearest Neighbors is commonly used at this level in Sports and Kinesiology. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output Python gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$16, Package 2 (your data analysis and interpretation) US$47 and Package 3 (full guidance) US$106, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. Python is a trademark of the Python Software Foundation.
Back to Python portfolio