I have 50,000 samples. Of these 23,000 belong to the desired class $A$. I can sacrifice the number of instances that are classified as belonging to the desired class $A$. It will be enough for me to get 7000 instances in the desired class $A$, provided that most of these instances classified as belonging to $A$ really belong to the desired class $A$. How can I do this?

The following is the confusion matrix in the case the instances are perfectly classified.

[[23000   0]
 [  0 27000]]

But it is unlikely to obtain this confusion matrix, so I'm quite satisfied with the following confusion matrix.

[[7000   16000]
 [  500 26500]]

I am currently using the sklearn library. I mainly use algorithms based on decision trees, as they are quite fast in the calculation.

  • $\begingroup$ Hi and welcome to this community! I've reformulated part of your post to make it clearer. Make sure I've not changed the intended meaning. $\endgroup$ – nbro Dec 2 '19 at 23:44
  • 1
    $\begingroup$ I have two classes. I'm only interested in the first one. As a rule the desired class is called positive. It is important to me that in the positive class got as little as possible false negative labels that are predicted. I added two examples with a confusion matrix. $\endgroup$ – user287629 Dec 2 '19 at 23:50
  • $\begingroup$ That's what I thought. I've provided an answer below. I may edit it later to provide a complete example. $\endgroup$ – nbro Dec 2 '19 at 23:52

I think you're looking for the minimization of false positives, that is, the instances that are classified as belonging to the desired class (the positive part of false positives) but that do not actually belong to that class (the false part of false positives). In practice, given your constraints, you may want to maximize the precision, while maintaining a good recall.

In this answer to the question How can the model be tuned to improve precision, when precision is much more important than recall?, the user suggests performing a grid search (using sklearn.grid_search.GridSearchCV(clf, param_grid, scoring="precision")) to find the parameters of the model that maximize the precision. See also the question Classifier with adjustable precision vs recall.

  • 2
    $\begingroup$ Thanks! Some things already done. I have an opinion that basically algorithms try to separate both classes to the maximum. I don't have to do that, it's enough that as few false negatives as possible get into the desired class. $\endgroup$ – user287629 Dec 3 '19 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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