# Setting up model in Caret, simple cross validation and preprocessing

Tcontrolparam = trainControl("cv",savePredictions = TRUE, summaryFunction = 
twoClassSummary, classProbs = T, returnResamp = "final")

Preprocessing.Options = c("center","scale","nzv","YeoJohnson")

# Run model

Model.GLM = train(x = Predictor.Vars, y = Result,
                         method = "glm",
                         metric = "ROC",
                         preProcess = Preprocessing.Options,
                         trControl = Tcontrolparam)

# Predict on new data - generates probability for each team

Predictions = predict(Model.GLM, New.Data, type = "prob")

# Post process probabilities so that each game, and the teams for each game add to 1.

Predictions.Post.Processing =  Predictions%>%
  mutate(Finalised.Win.Prob = Win.Prob/sum(Win.Prob))

I have an interesting question that I am yet to find an answer for in the general literature, so here goes nothing. Basically out of ideas.

I am trying to run a GLM (logistic reg) model in caret on a training data set that has ~2000 rows of data. In the data set each row has a related pair so they are not totally independant. I am modelling sports data for 2 different teams from the same game (hence the pair and 2 rows per game).

I am currently estimating the win probabilities for each team, for each game, however these do not numerically add up to 1. As they should do given it is for the same game. I am currently post processing so that they do add up to 1. This now leads to my question;

Is it possible to train the model in caret by building in the post processing (e.g linking of the two teams) and making the probs = 1, inside the resampling process/modelling building process?

Any thoughts or ideas - no matter how abstract they are would be appreciated!

EDIT: The below image is an example of the data set. In this example, weight, height, exp.game & exp.years are the variables being trained on. The model is trained to predict win/loss for each team and these probabilities are outputed in the lose and win columns respectively.

The yellow and white bands depict each game respectively. As in these are the two teams that are versing each other.

The finalised.win.prob is the post processing version to ensure that the probabilities for each team add to 1. As I say above, i want to be able to build this into the modeling training/resampling as opposed to just doing it post.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.