Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

project guidance required for A UK-based online retail store has captured the sales data for different products for the period of one year.. Kmeans..

getting this error as all the NA values are ommited..

Error in knn(train_data, test_data, train_data_target, k = 645) :
NA/NaN/Inf in foreign function call (arg 6)
In addition: Warning messages:
1: In knn(train_data, test_data, train_data_target, k = 645) :
NAs introduced by coercion
2: In knn(train_data, test_data, train_data_target, k = 645) :
NAs introduced by coercion



program code:
ecomm <- read.csv("D:\\My project\\ecommrce\\Project 2_Dataset.csv")
ecomm
View(ecomm)
names(ecomm)
str(ecomm)
summary(ecomm)
ecomm <- ecomm[,-9]
summary(ecomm)
library(dplyr)

fun1 <- function(x){
sum(is.na(x))
}

sapply(ecomm, fun1)
ecomm1 <- na.omit(ecomm)

ecomm %>% group_by(Country) %>% summarise_all(mean)


boxplot(ecomm$Quantity)
summary(ecomm$Quantity)
IQR1 <- 10.00-1.00
qauntity_high <- 10.00+1.5*IQR1
quantity_low <- 10.00-1.5*IQR1
ecomm1$Quantity <- ifelse(ecomm1$Quantity>qauntity_high |
ecomm1$Quantity<quantity_low,qauntity_high,
quantity_low)

quantile(ecomm1$Quantity)
boxplot(ecomm1$UnitPrice)
quantile(ecomm1$UnitPrice)
IQR2 <- 3.75-1.25
unitprice_high <- 3.75+1.5*IQR2
ecomm1$UnitPrice <- ifelse(ecomm1$UnitPrice>unitprice_high,unitprice_high,
ecomm1$UnitPrice)

boxplot(ecomm1$UnitPrice)


summary(ecomm1)
ecomm1$Country <- as.factor(ecomm1$Country)
ecomm1$InvoiceDate <- as.factor(ecomm1$InvoiceDate)
names(ecomm1)
ecomm1 <- ecomm1[,-c(1:3,5)]
ecomm1
View(ecomm1)

library(dplyr)
ecomm1 %>% group_by(Country) %>% summarise_all(mean)
ecomm_target <- ecomm1[,-3]
set.seed(123)
ecomm_random <- sample(1:nrow(ecomm1),0.9*nrow(ecomm1))
ecomm_random

train_data <-ecomm_target[ecomm_random,]
test_data <- ecomm_target[-ecomm_random,]

train_data_target <- ecomm1[ecomm_random,3]
summary(train_data_target)
test_data_target <- ecomm1[-ecomm_random,3]
summary(ecomm1)
boxplot(ecomm1$Country)
ecomm1$Country


sum(is.na(ecomm1))
na.omit(ecomm1)
library(class)
knn_model <- knn(train_data,test_data,train_data_target,k=645)
knn_model

please help..need assistance
 
Top