# Learning from Imbalanced Datasets: The Bike-Sharing Inventory Problem Using Sparse Information +
## 3 Methodology
### The Inventory Problem as a Classification Problem Using Machine Learning  
An ML classifier is an algorithm that returns the probability \(p(Y=k)\) that the dependent variable \(Y\) belongs to a certain class \(k\). Without the loss of generality, in the case of a supervised classifier, we can write  
\[p(Y=k)=\mathcal{H}(\mathbf{X},\mathbf{\Theta}) \tag{5}\]  
where \(\mathcal{H}\) is a general nonlinear-model, \(\mathbf{X}\) is the set of features (or independent variables) used to predict the probability \(p(Y=k)\), and \(\mathbf{\Theta}\) is a set of hyperparameters. The form of the model \(\mathcal{H}\) depends on the type of classifier used (neural networks, decision trees, etc.) and the hyperparameters \(\mathbf{\Theta}\), which explain the relationship between dependent and independent variables. To obtain the correct value of \(\mathbf{\Theta}\), supervised models use a training set (i.e., a dataset where both dependent and independent variables are known) and compute the set of parameters \(\mathbf{\Theta}\) that, given the training set, is more likely to reproduce the data. In the case of decision trees, Equation (5) can be rewritten as follows:  
\[p(Y=k)=DT(\mathbf{X},\mathbf{\theta},\mathbf{\Theta}) \tag{6}\]  
Figure 2: Hypothetical cumulative net flow (Source: own elaboration). where \(\mathbf{\theta}\) is the set of hyperparameters/weights that is associated with the feature vectors \(\mathbf{X}\). Similar to linear regression or logistic regression, \(\mathbf{\theta}\) represents the impact that each feature has on the prediction. This aspect related to interpretability makes decision trees among the simplest and most interpretable classifiers. In order to use Equations (5) and (6) in the context of the inventory problem, it is necessary to define the dependent and independent variables. In the case of the dependent variables, our objective is to estimate the UB and LB of the demand for bikes/docks; therefore, we might want to set \(Y^{UB}=UB\) and \(Y^{LB}=LB\) in Equations (5) and (6). The problem is that classification problems require discrete variables while the LB/UB for bikes/docks are continuous ones. Therefore, we need to define classes for the UB and LB and transform \(Y^{UB}/Y^{LB}\) into categorical variables. To do so, we introduce the error term \(\varepsilon\), which represents the expected precision of the model. Given \(\varepsilon\), we can say that a certain value of the UB belongs to the class \(k\) if, and only if,  
\[ \begin{cases}UB\in k&if\ UB^{k}-\varepsilon<UB\leq UB^{k}+\varepsilon\ with\ UB^{k}-\varepsilon\geq 0\\ UB\
otin k&otherwise\end{cases}  \tag{7}\]  
where \(UB^{k}\) is the center of the class. To provide a numerical example, the first class will have a center equal to zero, therefore \(UB^{0}=0\). Assuming an error term \(\varepsilon\) of 2 bikes, all target values \(UB\leq 2\) will belong to Class 0. The second class will assume \(UB^{1}=4\), therefore all observations \(2<UB\leq 6\) will belong to this class, and so on. Note that for \(\varepsilon=0.5\), each integer represents a separate class. The same procedure applies for the LB. Creating independent variables is straightforward, as any feature can potentially be used within the ML classifier. In general, we argue that three features should be used in the context of the inventory problem:  
\[\mathbf{X}=\Big{\{}\mathbf{X}_{behavioral},\mathbf{X}_{ Endogenous}\,\mathbf{X}_{ exogenous}\Big{\}} \tag{8}\]  
The difference between endogenous and exogenous features is straightforward. Endogenous features are explained by other variables within the model (for instance, lagged variables such as the departures and arrivals collected in the station the day before), while exogenous variables are not explained by other variables within a model (e.g., location of the station).