Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have two function. One to train a classifier and one to predict test data. If I run the predict function step by step it works fine, however If I call the predict function I get an error. I can't know what is happening due to the code of the function has no errors compiled manually. I've upload the two functions and the data on Github.you can access here
modelFit=mdp(Class = dades[,1],data=dades[,-1],lambda = 1,info.pred = T)
predict.mdp(modelFit, dades[1:5,-1])
Error in D[row, i] : subscript out of bounds
Thank you for anything you can do to help
The reason I could see was that in D[row, i] , variable row was overshooting the number of rows in D.
row itself is derived from vec.new : for(row in vec.new)
This piece is the culprit :
start=dim(D)[1]
vec.new=(start+1):(start+dim(newdata)[1])
vec.new starts from nrow(D)+1 , so even the first element is actually just beyond the size of D .
You can insert cat(row) in code and see.
I guess you will have to think about what start should be.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I defined several dummy variables and I can see them in my dataset. However, when I try to run a regression model, R says that Error: object "my_variable" not found. I also used exists(my_variable) and got the same error message. I checked for the spelling and it was not a problem.
I'd appreciate it if someone can help.
First, when you use exists(), you should put the variable in quotations (i.e., exists("my_variable")).
Second, be sure that you set up your regression model properly. For example:
lm(response ~ predictor1 + predictor2 + predictor3 + ...,
data=my_variable)
Ultimately, you need to include some of your data via dput(head(my_variable)), and the regression code.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
In R studio I have imported one .csv file which has two columns X and Y.
But when I try to use plot(X,Y), I get the error message:
"Object X not found"
I believe Alex's answer above is correct. The plot() function is complaining that X is not a variable, and you've already said it was a column instead. The "data" parameter tells plot not to try and interpret X and Y as variables, but as columns of a dataframe.
It would also work to use
plot(<name_of_dataframe>$X ~ <name_of_dataframe>$Y)
Where you replace <name_of_dataframe> with the actual name of the object that you imported the .csv into.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Okay so I'm making logs of some distance variables
- example;
loghospital=log(hospital_2015_distance, base=exp(1))
Works, i get values that i can run in a regression.
However for my LASSO regression it's better i specify a dataset.
So i want a dataframe of these logs (values).
Or better I want these logs (values) added to my existing dataframe called (data).
Any idea how this can be achieved? And if not, what else i should do to achieve the same?
To add it to your data.frame you can use $:
data$loghospital = log(hospital_2015_distance, base=exp(1))
Also you could use [[ or [ and probably should <- instead of = for assignment:
# Examples:
data[["loghospital"]] <- log(hospital_2015_distance, base=exp(1))
data["loghospital"] <- log(hospital_2015_distance, base=exp(1))
data[, "loghospital"] <- log(hospital_2015_distance, base=exp(1))
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to use c50 here what I did
train$default<-as.factor(train$default)
result<-C5.0(train[-17],train$default)
finalresult <- predict(result, test)
I am trying to run the following command table(test, Predicted=finalresult)in the R soft
but it is giving the following error
Error in sort.list(y): 'x' must be atomic for sort list
any suggestions?
You did not state how test looks. Since it is used for a prediction it presumably contains features and the value you want to predict. Assuming test$answer is what you want to predict. Try
table(test$answer, Predicted=finalresult)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a data table that has a int column that is counting the iteration of a test that I've preformed. So the first time I preformed the test, Table$Column == 1 and the second time Table$Column == 2 and so on and so forth.
However, there are times when a test breaks or I don't want to use the results from a particular test run. I have code that compares the current run vs. the previous run that looks like this.
vLatest<-max(Table$Column)
vPrevious<-max(Table$Column)-1
But since I sometimes omit results, it breaks vPrevious. How could I replace the "-1" with a function that finds the "2nd" max value?
This should work:
vPrevious <- sort(Table$Column, decreasing=T)[2]
We first sort in descending order and then pick the second element.