How to preprocess my stepwise regression using lasso/ridge? I am struggling in the preprocessing of some analyses. I have a dataframe with around 100 observations and quite a few possible predictors (categorial and numerical data, about 20 in total). I am quite aware of the restricted number of cases and the inherent problems, still I would like to come up with some predictions and yet a parimonious model. I chose glmStepAIC method from the caret package using a code similar to this
train_control <- trainControl(method = "repeatedcv", 
                              number = 10, 
                              savePredictions = "final", 
                              classProbs = TRUE, 
                              repeats=5)

mdl_step <- train(dataframe %>% select(-dv),
                      dataframe$dv,
                      method = 'glmStepAIC', 
                      preProcess = c("center", "scale"),
                      tuneLength = 10,
                      family = binomial,
                      trControl = train_control,
                      metric = "Accuracy")

The results are credible and the models make sense, but I am aware that the estimates are too optimistic [1], so I have been trying to find out about possible ways to validate our results. I have come across the possibility of pre-processing the data with lasso or ridge regression, but I can't find any examples and don't know how to set this up. Is there anyone who can give me some advice?

Both your use of an automated stepwise regression and of accuracy as your metric are highly troublesome, as the corresponding linked pages explain in detail. Those approaches are likely to overfit, as you recognize for stepwise selection, and won't work well on new data samples. You certainly cannot use this approach for inference (p-values, confidence intervals), as your final model doesn't take into account that you used the outcomes to choose the model.
No form of "pre-processing" will help if you then simply use it as a prelude to stepwise predictor selection or some other automated modeling process that uses the outcomes to build the model. You end up with the same problems.
You have two types of choices if you want a validated model.
First, and probably most useful, is to use a penalized model based on LASSO or ridge regression directly--not as a prelude to stepwise selection. The penalization of regression coefficients in those methods brings the final model's "optimism" down to reasonable levels.
Second is to document the optimism of your modeling process and adjust your model accordingly. Take a bootstrap sample of your data (same sample size, but with replacement). That mimics the process of taking your original data sample from the underlying population. Apply your automated modeling process to the bootstrap sample. Evaluate that model's performance both on the corresponding bootstrap sample and on the full data set: the difference (how much better it performs on the bootstrap sample than on the full data set) is an estimate of the "optimism" of the fit. Repeat a few hundred times to get an overall estimate of the "optimism" of the modeling process. That's called the "optimism bootstrap."
When you do either of the above, use a proper scoring rule like log-loss or the Brier score instead of "accuracy," which is based on an assumption about a probability cutoff for class assignment.
Frank Harrell's notes on Regression Modeling Strategies go into extensive detail on these matters.
