Lazy Learning Models¶
This module contains the implementation of the Weighted K-Nearest Neighbors algorithm for lazy learning.
Weighted K-Nearest Neighbors Class¶
- class source.model.lazy.WeightedKNN(alpha, k=5, decay='exponential', bandwidth=1.0, memory_size=100)¶
Bases:
objectWeighted K-Nearest Neighbors with exponential decay weighting.
- Parameters:
alpha (float) – Decay rate for the weights.
k (int) – Number of nearest neighbors to consider.
decay (str) – Type of decay to use (“exponential”, “linear” supported).
bandwidth (float) – Bandwidth for the KDE.
memory_size (int) – Maximum number of observations to store in memory.
Initialize the WeightedKNN object.
- Parameters:
alpha (float) – Decay rate for the weights.
k (int) – Number of nearest neighbors to consider.
decay (str) – Type of decay to use (“exponential”, “linear” supported).
bandwidth (float) – Bandwidth for the KDE.
memory_size (int) – Maximum number of observations to store in memory.
- __init__(alpha, k=5, decay='exponential', bandwidth=1.0, memory_size=100)¶
Initialize the WeightedKNN object.
- Parameters:
alpha (float) – Decay rate for the weights.
k (int) – Number of nearest neighbors to consider.
decay (str) – Type of decay to use (“exponential”, “linear” supported).
bandwidth (float) – Bandwidth for the KDE.
memory_size (int) – Maximum number of observations to store in memory.
- lazy_predict(x_query, take='kde')¶
Predict the value for a new observation using weighted KNN.
- Parameters:
x_query (numpy array) – Query observation vector.
take (str) – Method to aggregate neighbor labels (“mean” or “weighted_mean” or “kde”).
- Returns:
prediction – Predicted value for the query observation.
- Return type:
float
- update_store(X_new, y_new)¶
Update the data store with new observations and labels.
- Parameters:
X_new (numpy array) – New observation vectors.
y_new (numpy array) – New labels corresponding to the observations.
CKDE forecasting based on Weighted K-Nearest Neighbors Model