mercredi 11 août 2021

How to assign random numbers (0,1) with pre-determined counts for different intervals in Python

I am using Python. I have read in this dataset:

enter image description here

I need to randomly assigned 0 and 1 values such that:

  • for a score between 100 and 109: the count of 0's is 2 and the count of 1's is 4
  • for a score above 109: the count of 0's is 2 and the count of 1's is 2

So, ultimately, the dataset might look like this:

Id Score Target 1 100 0 2 104 1 3 104 1 4 106 1 5 106 0 6 109 1 7 113 0 8 115 1 9 115 1 10 116 0

Again, the Target values (0,1) are randomly assigned but their total count has to sum up to the pre-determined counts: there have to be TWO zero's and FOUR ones when the score is <= 109 an there have to be TWO zero's and TWO one's when the score is greater than 109.

I have tried to combine two arrays (for example: np.concatenate((np.zeros(10), np.ones(23))), but I don't know how to structure it.

Can anyone help, please?




Aucun commentaire:

Enregistrer un commentaire