The invention relates to the field of machine learning.
The class imbalance problem is well known in the machine learning field. This problem arises when a certain dataset, intended to be used for training a certain machine learning model (e.g., a classifier), includes a vastly different number of samples for different ones of the classes, making one or more of the classes greatly underrepresented.
The class imbalance problem causes significant difficulties in achieving ultimate classification performance, as classifiers tend to be biased towards larger classes. Moreover, it is often the underrepresented classes which are critical to correctly identify in real-life applications, but the naturally low number of samples in these classes during training makes it difficult to produce a classifier which can classify such minority samples well enough later on. For example, in fields such as fraud detection, disease diagnosis, cyber security, and many others, it is often much easier to collect samples associated with normal situations (e.g., legitimate transactions, healthy test results, or legitimate network packets) than samples associated with problematic ones (e.g., fraudulent transactions, pathological test results, or illegitimate network packets).
The foregoing examples of the related art and limitations related therewith are intended to be illustrative and not exclusive. Other limitations of the related art will become apparent to those of skill in the art upon a reading of the specification and a study of the figures.
The following embodiments and aspects thereof are described and illustrated in conjunction with systems, tools and methods which are meant to be exemplary and illustrative, not limiting in scope.
One embodiment is directed to a computer-implemented method which includes: Receiving a balancing policy and an imbalanced dataset that comprises samples distributed unequally between different classes. Automatically performing initial adjustment of the imbalanced dataset to comply with the balancing policy, by: oversampling one or more of the classes which are underrepresented in the imbalanced dataset, and if one or more of the classes are overrepresented in the imbalanced dataset, undersampling the one or more overrepresented classes. Operating a generative machine learning model to generate samples for the one or more underrepresented classes, based on the initially-adjusted dataset. Operating a machine learning classification model to label the generated samples with class labels corresponding to the one or more underrepresented classes. Selecting some of the generated samples which, according to the labelling, have a relatively high probability of preserving their class labels, compared to other ones of the generated samples. Composing a balanced dataset which complies with the balancing policy and comprises: the samples from the imbalanced dataset belonging to the one or more underrepresented classes; the selected generated samples; and, if one or more of the classes are overrepresented in the imbalanced dataset, also an undersampling of the samples belonging to the one or more overrepresented classes in the imbalanced dataset.
Another embodiment is directed to a system which includes: at least one hardware processor, and a non-transitory computer-readable storage medium having program code embodied therewith, the program code executable by said at least one hardware processor to: Receive a balancing policy and an imbalanced dataset that comprises samples distributed unequally between different classes. Automatically perform initial adjustment of the imbalanced dataset to comply with the balancing policy, by: oversampling one or more of the classes which are underrepresented in the imbalanced dataset, and if one or more of the classes are overrepresented in the imbalanced dataset, undersampling the one or more overrepresented classes. Operate a generative machine learning model to generate samples for the one or more underrepresented classes, based on the initially-adjusted dataset. Operate a machine learning classification model to label the generated samples with class labels corresponding to the one or more underrepresented classes. Select some of the generated samples which, according to the labelling, have a relatively high probability of preserving their class labels, compared to other ones of the generated samples. Compose a balanced dataset which complies with the balancing policy and comprises: the samples from the imbalanced dataset belonging to the one or more underrepresented classes; the selected generated samples; and, if one or more of the classes are overrepresented in the imbalanced dataset, also an undersampling of the samples belonging to the one or more overrepresented classes in the imbalanced dataset.
A further embodiment is directed to a computer program product comprising a non-transitory computer-readable storage medium having program code embodied therewith, the program code executable by at least one hardware processor to: Receive a balancing policy and an imbalanced dataset that comprises samples distributed unequally between different classes. Automatically perform initial adjustment of the imbalanced dataset to comply with the balancing policy, by: oversampling one or more of the classes which are underrepresented in the imbalanced dataset, and if one or more of the classes are overrepresented in the imbalanced dataset, undersampling the one or more overrepresented classes. Operate a generative machine learning model to generate samples for the one or more underrepresented classes, based on the initially-adjusted dataset. Operate a machine learning classification model to label the generated samples with class labels corresponding to the one or more underrepresented classes. Select some of the generated samples which, according to the labelling, have a relatively high probability of preserving their class labels, compared to other ones of the generated samples. Compose a balanced dataset which complies with the balancing policy and comprises: the samples from the imbalanced dataset belonging to the one or more underrepresented classes; the selected generated samples; and, if one or more of the classes are overrepresented in the imbalanced dataset, also an undersampling of the samples belonging to the one or more overrepresented classes in the imbalanced dataset.
In some embodiments, if one or more of the classes are well-represented in the imbalanced dataset, the balanced dataset further comprises the samples belonging to the one or more well-represented classes in the imbalanced dataset.
In some embodiments, the balancing policy defines a specific distribution of the samples among the different classes.
In some embodiments, the balancing policy comprises a percentile band defining a minimal and a maximal percentile of samples allowed for each of the different classes.
In some embodiments, in the initial adjustment, the oversampling comprises ruleset-based production of new samples.
In some embodiments, in the initial adjustment, the oversampling comprises machine learning-based production of new samples.
In some embodiments, in at least one of the initial adjustment and the balancing, the undersampling comprises deletion of some of the samples in the one or more overrepresented classes.
In some embodiments, in the imbalanced dataset, a ratio between an amount of samples in a smallest one of the classes and an amount of samples in a largest one of the classes is 1:2 or greater.
In some embodiments of the method, it is performed on a hardware processor of the computer in which the method is implemented.
In addition to the exemplary aspects and embodiments described above, further aspects and embodiments will become apparent by reference to the figures and by study of the following detailed description.
Exemplary embodiments are illustrated in referenced figures. Dimensions of components and features shown in the figures are generally chosen for convenience and clarity of presentation and are not necessarily shown to scale. The figures are listed below.
A system, a method, and a computer program product for balancing a machine learning dataset are disclosed herein. Advantageously, these may produce a high-quality, balanced dataset which, when used for training a machine learning model, makes the model perform better.
First, a balancing policy and an imbalanced dataset may be received. The imbalanced dataset includes samples that are distributed unequally between different classes.
Then, initial adjustment of the imbalanced dataset may take place, so that the number of samples in each of the classes complies with the balancing policy. This may be performed by oversampling any underrepresented classes, and optionally also undersampling any overrepresented classes—if such exist. The undersampling and oversampling may be performed using conventional techniques, potentially even naïve ones which are known not to yield high-quality samples.
The imbalanced dataset may then be finally balanced, producing a high-quality, balanced dataset, by: Operating a generative machine learning model to generate samples for the underrepresented class(es), based on the initially-adjusted dataset. Then, operating a machine learning classification model to label the generated samples with class labels corresponding to the underrepresented class(es), such that these labels may be used to effect a quality control mechanism. Next, those of the generated samples which, according to their labeling, have a relatively high probability of preserving their class labels, may be selected. Finally, the balanced dataset may be composed, still in compliance with the balancing policy, from: the samples belonging to the underrepresented class(es), the selected generated samples, and an undersampling of the samples belonging to the overrepresented class(es) (if such exist). If, according to the balancing policy, there are also any well-represented classes (which do not require any addition or omission of samples), any samples belonging to these classes are of course also included in the composed, balanced dataset.
The balanced dataset may be used for training a machine learning classifier to classify new samples. Advantageously, such trained classifier may potentially perform better than a classifier trained on an imbalanced dataset or on a dataset which was balanced according to other techniques than the one disclosed herein.
Reference is now made to
Storage device(s) 106 may have stored thereon program instructions and/or components configured to operate hardware processor(s) 102. The program instructions may include one or more software modules, such as a balancing module 108. The software components may include an operating system having various software components and/or drivers for controlling and managing general system tasks (e.g., memory management, storage device control, power management, etc.), and facilitating communication between various hardware and software components.
System 100 may operate by loading instructions of balancing module 108 into RAM 104 as they are being executed by processor(s) 102. The instructions of balancing module 108 may cause system 100 to receive a balancing policy 112 and an imbalanced dataset 110, process them, and output a balanced dataset 114.
System 100 as described herein is only an exemplary embodiment of the present invention, and in practice may be implemented in hardware only, software only, or a combination of both hardware and software. System 100 may have more or fewer components and modules than shown, may combine two or more of the components, or may have a different configuration or arrangement of the components. System 100 may include any additional component enabling it to function as an operable computer system, such as a motherboard, data busses, power supply, a network interface card, a display, an input device (e.g., keyboard, pointing device, touch-sensitive display), etc. (not shown). Moreover, components of system 100 may be co-located or distributed, or the system may be configured to run as one or more cloud computing “instances,” “containers,” “virtual machines,” or other types of encapsulated software applications, as known in the art.
The instructions of balancing module 108 are now discussed with reference to the flowchart of
Steps of method 200 may either be performed in the order they are presented or in a different order (or even in parallel), as long as the order allows for a necessary input to a certain step to be obtained from an output of an earlier step. In addition, the steps of method 200 are performed automatically (e.g., by system 100 of
In step 202, an original, imbalanced dataset (denoted D), is received. The imbalanced dataset includes samples that are distributed unequally between multiple different classes. The figure shows, for illustration purposes only, five different classes, with great variation of class sizes: the fifth class (the rightmost class in the figure) includes approximately 7 times the number of samples of the first class (the leftmost class in the figure). The second, third, and fourth classes include intermediate amounts of samples.
The term ‘imbalanced dataset,’ as used herein, may be a dataset in which there exists a class which is at least twice larger (in terms of number of samples) than another class. It is not uncommon to encounter imbalanced datasets with even a 1:200 ratio between the smallest class and the largest class. Even more substantially imbalanced datasets do exist. For purposes of this disclosure, ‘imbalanced dataset’ refers to a dataset with a ratio of between 1:2 and 1:10,000 between its smallest and largest classes, with any specific ratio or sub-range within that broader range being an optional embodiment of the invention.
The samples in the imbalanced dataset may be of any data type: text, image, video, audio, etc. All samples in the imbalanced dataset may be of the same data type.
The following description uses a text data type to describe the various embodiments of the invention. This is done, however, for demonstration purposes only. Those of skill in the art will readily recognize how to adapt the following description so that embodiments of the invention are usable with other data types.
In step 204, a balancing policy (denoted π(⋅)) is received. The balancing policy, generally, aims to reach a specific distribution of the samples among the classes, by adding and removing samples. A simplistic example, illustrated in the Figure, is of a balancing policy that defines a certain band [Blow, Bhigh]—a minimal and maximal amount of samples that each class should include. Each of Blow and Bhigh may be defined in terms of a percentile. For example, Blow may be set at the 30th percentile and Bhigh at the 70th percentile.
Classes that are already within the band are referred to herein as well-represented (WR) classes; classes that are below the band are referred to as underrepresented (UR) classes; and classes that are above the band are referred to herein as overrepresented (OR) classes.
Interim reference is made to
In
Without any balancing, c1=5%, c2=10%, c3=15%, c4=30%, and c5=40%. These percentages translate to numbers, of course, according to the actual amount of samples in the imbalanced dataset.
Lastly,
These examples are certainly not exhaustive, and a user of method 200 may choose to set any balancing policy that transform the class size distribution to a desired one.
Back to
The initial adjustment of step 206 may be performed by oversampling one or more of the classes which are underrepresented in the imbalanced dataset, and, if one or more of the classes are overrepresented in the imbalanced dataset, undersampling the one or more overrepresented classes.
The terms ‘oversampling’ and ‘undersampling,’ as used herein, refer to any conventional technique for adding and removing samples, respectively. For example, oversampling may include any conventional technique for ruleset-based (e.g., random or pseudo-random transformation of original samples or their features to produce new ones) or machine learning-based generation of new samples (e.g., using a generative machine learning model) or even simply duplication of samples. Undersampling, in turn, may refer to any technique to reduce the number of samples in a class, such as simplistic deletion of some samples, or combination of multiple samples into one (e.g., by averaging or otherwise jointly representing features or data of different samples).
The initial adjustment of step 206 produces an initially-adjusted dataset, denoted DS. This dataset complies with the balancing policy, since all its classes are within the defined band.
Next, steps 208 through 214 are all aimed at finally balancing the imbalanced dataset, to produce the high-quality balanced dataset 112 (also of
As step 208 completes, there are multiple new samples (weakly labeled) for the underrepresented class(es). However, not all of these newly-generated samples may be of sufficient quality for inclusion in the final, balanced dataset. Accordingly, step 210 sets the stage for a quality control mechanism, to be applied in step 212: In step 210, a machine learning classification model (also referred to as a “weak labeler” or simply “labeler”) may be operated to attempt to re-label the samples generated in step 208 with class labels corresponding to the one or more underrepresented classes. The weak labeler may be any suitable, conventional classifier. In one option, only one weak labeler is used. In another option, multiple weak labelers are used; this may either include using multiple instances of the same weak labeler in order to separately label different classes, or using different weak labelers to label all classes by each such labeler.
Next, in step 212, selection of high-quality samples out of the generated samples may take place. Some of the generated samples which, according to the labeling of step 210, have a relatively high probability (compared to other ones of the generated samples) of preserving their original class labels (those assigned during the generation step 208) may be selected in this step. The result is a dataset denoted Dsyn, which includes, for the underrepresented classes, their original samples plus the selected high-quality generated samples. In case the labeling of step 210 was performed by multiple different weak labelers, as in one of the options mentioned above, the selection of high-quality samples out of the generated samples may include selecting those samples whose label was agreed upon by all weak labelers, or by a voting majority of these weak labelers (e.g., more than 50%, 60%, 70%, 80%, 90%, etc.).
In step 214, the final, balanced dataset (denoted DBalanced) 112 may be composed from: the samples from D belonging to the one or more underrepresented classes, the selected generated samples (from Dsyn), and an undersampling (by any conventional method) of the samples belonging to the one or more overrepresented classes of D.
By virtue of steps 204 through 214, DBalanced may be suitable for use as a high-quality dataset (also “training set”) for training a machine learning classification model (also “classifier”) to classify new samples. In optional steps (not shown) of method 200, DBalanced is in fact used for such training and then for classification.
Method 200 may also be expressed by the following algorithm (demonstrating use of the method with a textual imbalanced dataset):
1, . . . ,
k
(·,·)
(·,·)
(
(D, Bhigh), Blow)
using DS to obtain
tuned and synthesize a set of labeled
tuned
1(DS), . . . , hk ←
k(DS)
(Dsyn ∪ D, Bhigh)
To evaluate its performance, method 200 was experimentally applied to the following three datasets: the COVID-19 QA (CQA) dataset, the Stack Exchange Frequently Asked Questions (SEAQ) dataset, and the Airline Travel Information Systems (ATIS) dataset, as well as to ten additional semantic utterance classification (SUC) datasets.
The experimental setup and results are described in Tepper, N. et al., “Balancing via Generation for Multi-Class Text Classification Improvement,” Findings of the Association for Computational Linguistics: EMNLP 2020, pages 1440-1452, November 2020, whose Chapter 5 (“Experiments”) is incorporated herein by reference. Each detail, parameters, or the like described in that Chapter 5 is considered an optional variation of method 200.
The experiments have shown that method 200 succeeded in increasing micro and macro accuracy of prediction by a classifier trained on a dataset that was balanced by the method.
The present invention may be a system, a method, and/or a computer program product. The computer program product may include a computer readable storage medium (or media) having computer readable program instructions thereon for causing a processor to carry out aspects of the present invention.
The computer readable storage medium can be a tangible device that can retain and store instructions for use by an instruction execution device. The computer readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer readable storage medium includes the following: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire. Rather, the computer readable storage medium is a non-transient (i.e., not-volatile) medium.
Computer readable program instructions described herein can be downloaded to respective computing/processing devices from a computer readable storage medium or to an external computer or external storage device via a network, for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing/processing device.
Computer readable program instructions for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, or either source code or object code written in any combination of one or more programming languages, including an object-oriented programming language such as Java, Smalltalk, C++ or the like, and conventional procedural programming languages, such as the “C” programming language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, a field-programmable gate array (FPGA), or a programmable logic array (PLA) may execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention. In some embodiments, electronic circuitry including, for example, an application-specific integrated circuit (ASIC), may be incorporate the computer readable program instructions already at time of fabrication, such that the ASIC is configured to execute these instructions without programming.
Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer readable program instructions.
These computer readable program instructions may be provided to a processor of a general-purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.
In the description and claims, each of the terms “substantially,” “essentially,” and forms thereof, when describing a numerical value, means up to a 20% deviation (namely, ±20%) from that value. Similarly, when such a term describes a numerical range, it means up to a 20% broader range—10% over that explicit range and 10% below it).
In the description, any given numerical range should be considered to have specifically disclosed all the possible subranges as well as individual numerical values within that range, such that each such subrange and individual numerical value constitutes an embodiment of the invention. This applies regardless of the breadth of the range. For example, description of a range of integers from 1 to 6 should be considered to have specifically disclosed subranges such as from 1 to 3, from 1 to 4, from 1 to 5, from 2 to 4, from 2 to 6, from 3 to 6, etc., as well as individual numbers within that range, for example, 1, 4, and 6. Similarly, description of a range of fractions, for example from 0.6 to 1.1, should be considered to have specifically disclosed subranges such as from 0.6 to 0.9, from 0.7 to 1.1, from 0.9 to 1, from 0.8 to 0.9, from 0.6 to 1.1, from 1 to 1.1 etc., as well as individual numbers within that range, for example 0.7, 1, and 1.1.
The descriptions of the various embodiments of the present invention have been presented for purposes of illustration, but are not intended to be exhaustive or limited to the explicit descriptions. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein was chosen to best explain the principles of the embodiments, the practical application or technical improvement over technologies found in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.
In the description and claims of the application, each of the words “comprise,” “include,” and “have,” as well as forms thereof, are not necessarily limited to members in a list with which the words may be associated.
Where there are inconsistencies between the description and any document incorporated by reference or otherwise relied upon, it is intended that the present description controls.