Learn R Programming

DSWE (version 1.8.2)

KnnPredict: KNN : Predict

Description

The function can be used to make prediction on test data using trained model

Usage

KnnPredict(knnMdl, testData)

Value

a numeric / vector with prediction on test data using model generated by KnnFit

Arguments

knnMdl

a list containing:

  • knnMdl$data - The data set provided by user

  • knnMdl$xCol - The column number of features provided by user or the best subset column number

  • knnMdl$yCol - The column number of target provided by user

  • knn$bestK - The best k nearest neighbor calculated using the function KnnFit

testData

a data frame or matrix, to compute the predictions

Examples

Run this code

data = data1[c(1:100),]
xCol = 2
yCol = 7
subsetSelection = FALSE

knn_model = KnnPCFit(data, xCol, yCol, subsetSelection)
testData = data1[c(101:110), ]

prediction = KnnPredict(knn_model, testData)

Run the code above in your browser using DataLab