0

I have gaussian data which is:

r1=np.random.multivariate_normal(mean1, cov1, 3000)
r2=np.random.multivariate_normal(mean2, cov2, 3000)

Now I want to add class labels for these datas to train a classifier. For r1, it is class1 and for r2, it is class2. How can I add the class labels?

2
  • Which machine learning library do you want to use? pybrain? scikit-learn? Another library? Do you want to develop the library on your own?
    – quant
    Commented Oct 31, 2018 at 22:24
  • I am trying to design knn classifier without using library.
    – yasser
    Commented Oct 31, 2018 at 22:27

1 Answer 1

1

considering +1 for class1 as label1 and -1 for class 2 as label2:

label1 = np.ones( (r1.shape[0],1) )
label2 = np.ones( (r2.shape[0],1) ) * -1
data = np.concatenate((r1, r2))
labels = np.concatenate((label1, label2))

In case you need to shuffle the data before training and you want to keep track of which label is for which sample, first add each label to it's corresponding data:

r1 = np.append(label1, r1, axis=1)
r2 = np.append(label2, r2, axis=1)
data = np.concatenate((r1,r2))
np.random.shuffle(data)
labels = data[:,0] #extracts labels in shape of (len(labels),)which is a rank 1 array 
labels = np.reshape(labels,(len(labels),1)) #fix the shape to a 1D array    
R = data[:,(1,2)] #extracting inputs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.