KNeighborsClassifier
public class KNeighborsClassifierK-neighbors classifier.
Classifier implementing the k-nearest neighbors vote.
- 
                  
                  The order of the norm of the difference: ||a - b||_p.DeclarationSwift var p: Int
- 
                  
                  Weight function used in prediction. DeclarationSwift public var weights: String
- 
                  
                  Number of neighbors. DeclarationSwift var neighborCount: Int
- 
                  
                  The training data. DeclarationSwift var data: Tensor<Float>
- 
                  
                  The target class correspoing to training data. DeclarationSwift var labels: Tensor<Int32>
- 
                  
                  Create a K neighbors classifier model. DeclarationSwift public init( neighborCount: Int = 5, weights: String = "distance", p: Int = 2 )ParametersneighborCountNumber of neighbors to use, default to 5.weightsWeight function used in prediction. Possible values uniform- uniform weighted,distance- weight point by inverse of their distance. Default set todistance.pThe order of the norm of the difference: ||a - b||_p, default set to2.
- 
                  
                  Fit a K-neighbors classifier model. DeclarationSwift public func fit(data: Tensor<Float>, labels: Tensor<Int32>)ParametersdataTraining data with shape [sample count, feature count].labelsTarget value with shape [sample count].
- 
                  
                  Returns the weights of each neighbor. DeclarationSwift internal func computeWeights( distances: Tensor<Float>, labels: Tensor<Float> ) -> Tensor<Float>ParametersdistancesContains the distance between test data and top neighbors. labelsContains the classes of neighbors. 
- 
                  
                  Returns the predicted classification. DeclarationSwift internal func predictSingleSample(_ test: Tensor<Float>) -> Tensor<Int32>ParameterstestInput data to be classified. Return ValuePredicted classification. 
- 
                  
                  Returns classification. DeclarationSwift public func prediction(for data: Tensor<Float>) -> Tensor<Int32>ParametersdataPrediction data with shape [sample count, feature count].Return ValueClassification for test data. 
- 
                  
                  Returns the mean accuracy. DeclarationSwift public func score(data: Tensor<Float>, labels: Tensor<Int32>) -> FloatParametersdataSample data with shape [sample count, feature count].labelsTarget label with shape [sample count].Return ValueReturns the mean accuracy on the given test data and labels. 
 KNeighborsClassifier Class Reference
      KNeighborsClassifier Class Reference