# How to build predictive/multivariate (and uni, bi, etc.) regression model for categorical dataset that is already one hot encoded?

I'm a bit confused about how to build any kind of ML model with only categorical data.

I have a dataset of training completed by each person. The dataset has about 25 columns (names of the training) and 3500+ rows (training that was completed or not completed) with each row indexed to a specific person. Since the training is categorical, I already hot-encoded each row/column of the dataset with each row still indexed to a specific person. The last column is the total number of incidents a person has been involved in (which right now is either 0 or 1 total incidents but could be more in the future).

Is there a way to build some type of multivariate or multiple linear regression predictive/machine learning model to predict things like which person is more likely to be involved in an incident based upon the training that they have or have not taken - or which trainings are most effective based upon a number of incidents, etc.? Also, is there a way to perhaps assign a probability to each person based upon the training they took (or not taken) and the total number of incidents they were involved or not involved in? Again, I'm not sure what to do because I am trying to make predictions about categorical data from other categorical data.

Here is an example of my data frame (each row is indexed to a specific person instead of the row index number):

import pandas as pd

data = {'Training1':[1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1],
'Training2':[0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1],
'Training3':[1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
'Training4':[1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1],
'Training5':[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1],
'Training6':[1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1],
'Training7':[1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0],
'Training8':[1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1],
'Training9':[1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1],
'Training10':[1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1],
'Training11':[1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0],
'Training12':[1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1],
'Training13':[1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1],
'Training14':[1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1],
'Training15':[1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1],
'Training16':[1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0],
'Training17':[1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1],
'Training18':[1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1],
'Training19':[1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1],
'Training20':[1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0],
'Training21':[1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1],
'Training22':[1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1],
'Training23':[1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0],
'Training24':[1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1],
'Training25':[1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1],
'Total_Incidents': [1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1]}

df = pd.DataFrame(data)


The data you describe is perfectly appropriate for the tasks you mention. It's important to formalize each task in order to use the correct design, for example:

predict things like which person is more likely to be involved in an incident based upon the training that they have or have not taken

This is a typical supervised learning problem where the target variable is the number of incidents. If the target variable is boolean then it's more standard to treat it as a binary classification problem, but if it's a numerical value it would be a regression problem. In both cases, there are many methods that can be used: linear regression, SVM... I would recommend a decision tree because it provides a model which is easily interpretable.

Note that in this case, you should split your data at least between the training set and test set in order to evaluate the performance of the model.

which trainings are most effective based upon the number of incidents

This question is a bit different, I don't know if this is intended: the difference is whether the goal is to predict a target variable (this involves training a model, see above) or to analyze/describe the data. The latter option involves simply calculating statistics on the whole dataset. For example in this case you could calculate the conditional probability of "had an incident given had taken training X" for every training X (this can also be done for various combinations of training).

is there a way to perhaps assign a probability to each person based upon the training they took (or not taken) and the total number of incidents they were involved or not involved in?

• First part: finding a probability for a person based only on the training they took can be obtained with a predictive model (first option above). Most classification and regression methods calculate a probability for the result (mind that this probability is itself a prediction in this case).

• Second part: same problem but using an additional variable about the incidents the person has been involved in. This would be a significantly different problem because it involves the "incidents" variable used both as an input feature and as the target variable. This is doable but it requires thinking about including time in the design because it implies that at a particular time $$t$$ some people have already been involved in an incident and the question is whether they are going to be involved again.