Closed skywang0407 closed 4 years ago
I think the reason it’s not working is g
was overwritten to be a factor variable somewhere in a previous chunk - can you double check that?
Professor @LucyMcGowan , g was overwritten when we had to get the confusion matrix in exercise 7. How can we change the code so this does not happen?
test %>%
mutate(g_factor=as.factor(g)) %>%
conf_mat(g_factor, lda_predicted_class)
Actually, I have changed the factor variable as g_test so it shouldn't rewrite g. However, it still only works by chunks and cannot knit.
If you clear everything out (click Session > Restart R) and run the chunks one by one from the top, where do you see the error? Can you paste the error you see?
This is the error I get, which seems to be the same error @skywang0407 got:
Error in qda.default(x, grouping, ...) : rank deficiency in group aa
My code for the qda is: model_qda <- qda(factor(g) ~ ., data = train) predictions_qda <- predict(model_qda)
If you remove factor()
(so just g~.
) does the error go away?
No, same error happens.
ah! I think I know what it is. In the previous exercises we added the predicted values from LDA to the train data frame and so since were using the . It is also trying to use that variable to fit the model...add this right before you fit qda:
train$lda_predicted_class <- NULL
The other way to fix this would be instead of overwriting the train data to add this variable, you could create a data frame with a different name:
train_new <- train %>%
mutate(lda_predicted_class <- predict(model)$class)
That worked! Thank you! Only thing is that my confusion matrix shows that all observations are being predicted right. Was this expected? ` {r train-qda} train$lda_predicted_class <- NULL model_qda <- qda(g ~ ., data = train) predictions_qda <- predict(model_qda)
class <- predict(model_qda, newdata = train)$class train <- train %>% mutate(qda_predicted_class = class)
train %>% mutate(g_factor=as.factor(g)) %>% conf_mat(g_factor, qda_predicted_class)
` Truth Prediction aa ao dcl iy sh aa 519 0 0 0 0 ao 0 759 0 0 0 dcl 0 0 562 0 0 iy 0 0 0 852 0 sh 0 0 0 0 648
Got it, thank you two!
Unfortunately, it still doesn't work on mine. I am just lost.
It can work by chunk, I just don't get it why it doesn't work by knit.
I am wondering if I can submit two html so that one has the lda model and another one has the qda model by opening up another work.
@skywang0407 @LucyMcGowan Mine the same! The confusion matrix work by chunk but could not knit.
@skywang0407 I just looked at your Rstudio Cloud instance and it knit for me. It looks like you reloaded the data to get it to knit (which works!)
@Cindyyyhey try to add this to the top of the chunk that calls the first qda()
function.
train <- read_csv("data/train.csv")
I believe the problem overall is you edited the train along the way and then tried to use the edited data frame in the qda function.
@LucyMcGowan my code is still not knitting, but each time I try it seems to be a new reason. I can typically run it, but I've only gotten as far as a 56% progress on the knit.
@ConnorReardon I just logged into your Rstudio cloud instance and it knit for me 🤔
Done! It finally knits! OMG, after so much effort. Thank you all!
Hello! Time to jump on this bandwagon. My code works in chunks, like described above, but will not knit. When it gets to exercise 9, I reload the data as follows:
test <- read_csv("data/test.csv") train <- read_csv("data/train.csv")
This will knit. However, when I create a QDA model/prediction/heatmap afterwards, it stops working and doesn't knit as seen below. No error pops up like @midupree wrote in #40
Any help would be greatly appreciated!
Actually, I think your problem is about internet, cause I met this problem before too. It seems R just stops running. You can try clear your workplace and run each chunk one by one and knit again. It might help.
Thanks for the idea, but I still run into the same error :/ I even moved it into another workspace and it still stops like that. I'll keep trying I guess
Hi Professor McGowan, About my QDA model, I can run it by chunks in the coding window, but it can not be knitted as below:
So I only commit and push my RMD, which works with the chunk.
Thanks!