## Question

How do we write the predict function to give predictions for specific stocks?

Dear Dr. Ballings,

We are using Naive Bayes predict function to predict the stock prices. Currently, our predict output is 116972 rows long and we are stuck

as to how to proceed. Do you have any advice on how to write the predict function to give predictions for specific stocks?

Thank you so much for all of your help,

Jordan Pischke

## Answers and follow-up questions

** Answer or follow-up question 1**Dear Jordan,

The best way to proceed is to predict for all stocks and then select the right subset (as with future rounds that subset will change).

You can read more about how to do that at the submission URL (http://ballings.co/cup/import.php).

For your convenience, I've copied it here:

Selecting and ordering your predictions:

Suppose you made a prediction for all symbols and you stored them in yourdata.

This solution only works if each stock appears only once in yourdata.

Make sure you run this and make sure you understand it.

(symbols_to_predict <- c("a","b","c")) #stocks to make prediction for in right order

(yourdata <- data.frame(symbols=as.character(c("c","b","a","e","g")),

predictions=c(0.1,0.4,0.4,1,0.05),

stringsAsFactors=FALSE)) #your predictions

(yourdata <- yourdata[yourdata$symbols %in% symbols_to_predict,])

matched <- match(yourdata$symbols,symbolsfromfile)

matched <- matched[!is.na(matched)]

yourdata[matched,]

Michel Ballings

Sign in to be able to add an answer or mark this question as resolved.