# Learning from Imbalanced Datasets: The Bike-Sharing Inventory Problem Using Sparse Information +
## 3 Methodology
### Iterative Resampling and Data Imbalance  
Though traditional techniques for data imbalance provide many benefits, in the case of the inventory problem, off-the-shelf techniques might over-generalize the problem. Simply stated, they might identify a set of hyperparameters \(\mathbf{\Theta}\) that is too general, as they assume that the same features that are important for the majority class are also important for the minority class. Therefore, this section introduces a resampling technique that generates and estimates, in an iterative manner, balanced data classes. The model focuses on a database-splitting function, and it is intuitively illustrated in Figure 3.  
Starting from the entire dataset, the approach divides the data into 2 classes. Class 1 corresponds to \(k=0\), therefore \(UB^{0}=0\). All the other data points are inserted in Class 2. The objective is to create two balanced classes of data. In Figure 3, we assume that two classes are sufficient. In practice, additional classes are created until all classes are the same size. However, only Class 1 is computed using the system of Equation (6), therefore \(UB^{k}\) and \(\varepsilon\), while all other classes are computed to ensure balance within the data, i.e., the only criterion to create all other classes is that they must have the same number of data points. At each iteration, a decision tree classifier is used to classify the data. All data points that are classified as Class 1 are considered properly classified. All remaining observations are included in a new dataset. At this point, we set \(k=k+1\), and we repeat the operation on the new reduced dataset. The operation continues until all data points have been classified. As Figure 3 is a purposely trivial example, the procedure is depicted in Algorithms 1 and 2, where \(E\) is the tolerance error for the class imbalance, i.e., how much class imbalance is allowed in the system. ```
Procedure: resampling (X,Y,\(\varepsilon,k,E\)) For\(UB\) in Y \(UB^{k}=UB^{k-1}+2\varepsilon\) if\(UB^{k}-\varepsilon<UB\leq UB^{k}+\varepsilon\) \(UB\in Class^{1}\) Else \(UB\in Class^{2}\)  Set \(\text{Len}=\text{length}\Big{(}Class^{2}\Big{)}\) If\(\text{length}\Big{(}Class^{1}\Big{)}<\text{Len}+E\)  Set \(n=\text{Len}/\text{length}\Big{(}Class^{1}\Big{)}\) Split\(Class^{2}\) in n classes If\(\text{length}\Big{(}Class^{1}\Big{)}>\text{Len}-E\)  Set \(n=\text{length}\Big{(}Class^{1}\Big{)}/\text{Len}\) Split\(Class^{1}\) in n classes Return(X,Class)
```  
**Algorithm 1**Iterative Resampling Technique  
Figure 3: Illustrative example of the resampling technique (Source: own elaboration). ```
Procedure : \(\mathcal{HIT}(\mathbf{X},\mathbf{Y},\mathbf{\Theta})\)  Set \(\varepsilon,k,E\)  Set \(k=0\) While\((\mathbf{X},\mathbf{Y})\) is not empty: ClassLabel\(=\) resampling\((\mathbf{X},\mathbf{Y},\varepsilon,k,E)\)  Train ML Classifier \(DT(\mathbf{X},\mathbf{\beta},\mathbf{\Theta})\) For\(\mathbf{X},\mathbf{Y}\) inClass\({}^{1}\):  remove \(\mathbf{X},\mathbf{Y}\) from \(\mathbf{X},\mathbf{Y}\)  Set \(k=k+1\)
```  
**Algorithm 2**Iterative ML Classifier  
It should be noted that, as the lower and upper bounds are computed using the cumulative net flow and not the demand, stations with different demand levels (e.g., in the city center or in the suburbs) may still have similar inventory levels and therefore be grouped in the same class. This could create issues during the classification, as these stations may exhibit a different behavior. Therefore, the model should ideally incorporate endogenous features, as previously mentioned, to account for this phenomenon. The resampling function needs to be used together with the learner in an iterative manner. This is illustrated in Algorithm 2. Specifically, the function determines a balanced group of classes to be forecasted at each iteration. Once a maximum number of classes is defined for each prediction group, the function generates the set of classes that have to be predicted (A) and the set to predict later (B).