TheAlgorithms/R

Missing dependencies in .R files?

isabelgiang opened this issue · 1 comments

Hello,

I am having problems running some of the algorithms because they seem to expect me to have certain variables or methods loaded that I do not have.

For example, for DecisionTree.R:

library(rpart)
x <- cbind(x_train,y_train)
# grow tree 
fit <- rpart(y_train ~ ., data = x,method="class")
summary(fit)
# Predict Output 
predicted= predict(fit,x_test)

When I attempt to run this script in RStudio, I get the following errors:

Error in cbind(x_train, y_train) : object 'x_train' not found
> # grow tree 
> fit <- rpart(y_train ~ ., data = x,method="class")
Error in is.data.frame(data) : object 'x' not found
> summary(fit)
Error in object[[i]] : object of type 'closure' is not subsettable
> # Predict Output 
> predicted= predict(fit,x_test)
Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "function"
> predicted= predict(fit,x_test)
Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "function"

Are there other R files or packages that the user is expected to have installed, aside from the packages already included?

I am using a fresh RStudio install (version 1.1.463) on Ubuntu 16.04 with R version 3.2.3.

@hollowsunsets oh, sure, I'm sorry for not indicating the source of the relevant dataset. The DecisionTree.R is only about the implement thought of the DecisionTree Algorithm by R, and you can find the dataset for testing on your own by google, such as: http://archive.ics.uci.edu/ml/datasets/Bank+Marketing

good luck~