0

I'm trying to make a regression, using the knnreg() function for the k nearest neighbours. Here is what I have done so far: Divide the data in training and test data randomly. enter image description here

Then, I tried to use the function as (I think) is intended. enter image description here

Now when I use summary(), I get this weird output: enter image description here

As I understand it, it should give me the function it used for the specific value of k right?

I should also be able to plot the regression, however I was wondering how that work since I cannot simply use abline() as in the linear regression.

Last, I'd like to know r^2 of the train and test data, normally I'd find this in the summary() function for a linear regression, where do I find that here?

I hope someone can help me out, thanks already :)

Here is the full code for copypaste using the dataset iris:

ir <- iris
attach(ir)
#generate new table with relevant data
ir1.1 <- subset(ir,select=c(Sepal.Length,Sepal.Width))
#generate random tables for training and test data
set.seed(748)
testreihen.ir <- sample(1:nrow(ir1.1),(150/3))
testdaten.ir <- ir1.1[testreihen,]
trainingsdaten.ir <- ir1.1[-testreihen,]
#regression KNN
library(caret)
fit_knn_train.ir <- 
knnreg(Sepal.Length~Sepal.Width,data=trainingsdaten.ir,k=598)
fgerzn
  • 1
  • 1
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please don't post code or data as images. We can't copy/paste those values for testing. – MrFlick Nov 05 '21 at 17:36

0 Answers0