I have a very large skewed training set where every feature's data-points are very similar ?

For example, following is some part of the training data :


where the last column is the class-label - only 0 and 1.

This only a part of the dataset, but the actual dataset contains about 95% of samples with class-label being 1, and the rest with class-label being 0, despite the fact that more or less all the samples are very much similar.

Please suggest an appropriate classifier (using scikit-learn) as well.

  • $\begingroup$ you also might want to rescale your features... maybe differences in the samples become more visible that way $\endgroup$
    – oW_
    Commented Dec 13, 2016 at 23:18

3 Answers 3


This is the so-called "Class Imbalance Problem". Fortunately, there are a number of possible approaches.

Probably easiest is going to be to use the class_weight option present in a number of scikit-learn's classifiers. For example, LogisticRegression.

You can either set this option to "balanced" (or "auto" if you're using an older version of sklearn), in which case it automatically adjusts weights inversely proportional to class frequency (i.e. it tries to compensate for the class imbalance); or you can manually set the weights for each class label using a dict, e.g. {0:1, 1: 20}.

For a worked example using an SVM, see here.

See here for more information: https://stats.stackexchange.com/questions/131255/class-imbalance-in-supervised-machine-learning

  • $\begingroup$ Can you share any reference for how to implement any of these approaches in code ? (preferably using scikit-learn's classifiers in python) @PriceHardman $\endgroup$
    – Jarvis
    Commented Sep 14, 2016 at 17:42
  • $\begingroup$ Yep, updated the answer. $\endgroup$ Commented Sep 14, 2016 at 20:21
  • $\begingroup$ I tried your method, but still its not helping, can you have a look at the complete .csv file, how can I contact you ? @PriceHardman $\endgroup$
    – Jarvis
    Commented Sep 15, 2016 at 2:04

I find the proposed answer very good, using a cost sensitive approach would be the first step. Another solution to your issue would be to use some sort of Sampling to balance the two classes, like SMOTE. Have a look at imbalance-learn module. Moreover, you may try to use other Classifiers, depends to what extend you want to go. I would give a try with Naive Bayes via Kernel estimation, which is simple and quick. You will have to check. In the end if no approach seems to predict the minority class you could degrade the majority class via under sampling.


The question mentions three training data characteristics.

  • Very large
  • Skewed
  • Similarity in values for all but the last dimension
  • Binary final dimension (~95% 1)

The large N is actually a good thing in terms of classification accuracy, but the volume of data may necessitate distributed computing and/or large memory, disk, network, and CPU provisions.

The narrow range of the real dimensions and the skew of the binary dimensions do not provide any information necessary to decide what classifier from scikit-learn is best. If you plot any two dimensions and look at the pictures from the visual comparison page you may be able to make a few best guesses yourself and try those first.

The key to getting the best performance from these classifiers is to and normalize what you can in three main ways.

  • Skew
  • Range
  • Offset

One cannot de-skew the binary dimension since there are no intermediate values and changing a 1 to a 0 makes no sense statistically. However, if the desired range to use in the classifier is -1 to 1, the data in that 7th dimension can be translated using x7' = 2 x7 - 1.

If one of the other dimensions has a skewed distribution and the classifier is known to work best with a normal distribution, it is possible that the data is exponentially distributed, in which case, if it is the 2nd dimension, the general translation might be x2' = ln (x2) / k1 - k0 where the constants are chosen to translate the distribution data to within the desired ideal range of the classifier.

Various non-linear functions that compensate for skew can be used to improve classification significantly and the resulting learned behavior (model) can then be re-expressed using the inverse of these non-linear functions

Scatter plots will become clearer indicators of which classifiers are likely to work best after distributions are normalized.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.