Class: Lurn::Neighbors::KNNRegression
- Defined in:
- lib/lurn/neighbors/knn_regression.rb
Instance Attribute Summary
Attributes inherited from KNNBase
Instance Method Summary collapse
-
#predict(vector) ⇒ Float
Predicts the value of the given observation by averaging the target value of the closest k predictor observations based on euclidian distance.
Methods inherited from KNNBase
#fit, #initialize, #nearest_neighbors
Constructor Details
This class inherits a constructor from Lurn::Neighbors::KNNBase
Instance Method Details
#predict(vector) ⇒ Float
Predicts the value of the given observation by averaging the target value of the closest k predictor observations based on euclidian distance.
12 13 14 15 16 |
# File 'lib/lurn/neighbors/knn_regression.rb', line 12 def predict(vector) _, neighboring_targets = nearest_neighbors(vector) neighboring_targets.inject(:+).to_f / neighboring_targets.length.to_f end |