i m doing dimensionaly reduction using PCA. I don't understand why some dataset already had a target ad example in Iris database or other like this (https://scikit-learn.org/stable/datasets/index.html) had a target_names useful when plot data.

Ad example in iris database choose like color= target_names to do this

enter image description here

i found this code online in example.

fig = plt.figure(figsize = (8,8))
ax = fig.add_subplot(1,1,1) 
ax.set_xlabel('Principal Component 1', fontsize = 15)
ax.set_ylabel('Principal Component 2', fontsize = 15)
ax.set_title('2 component PCA', fontsize = 20)
targets = ['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
colors = ['r', 'g', 'b']
for target, color in zip(targets,colors):
    indicesToKeep = finalDf['target'] == target
    ax.scatter(finalDf.loc[indicesToKeep, 'principal component 1']
               , finalDf.loc[indicesToKeep, 'principal component 2']
               , c = color
               , s = 50)

I m trying to do the same with my dataset, where i dont have a target

i have a table in this way

User    Movie
        0 1 2 3 4 
      0 2 0 5 0 0
      1 0 1 1 0 0
      2 0 5 5 5 0

for each user i have all film and him review (0 if don't review)

When plot my graph i tried to do this

fig = plt.figure(figsize = (16,12))
ax = fig.add_subplot(111)

ax.scatter(a,b, alpha = 1)
plt.title('Method: PCA')
#plt.savefig('PCA.png', dpi = 300)

but i really don't know where is my target. I try to add another column to my dataset with gender for user for cluster user for gender but give an error of the shape because i just have a 2 gender but 6000 user.

I really don't know to apply a target in this way, Same suggestion?


Iris data set comes with a label, it is a supervised learning problem. The task is to predict the species of the flowers.

Your problem need not have a label, it really depends on your task and data. If your goal is to predict the gender and you want to see if you can see a pattern in lower dimensional space, you can give it a try to treat gender as a target.

If your problem is an unsupervised one, You can also just plot out your data and see whether you see any clustering in your dataset.

Remark: You might want to be careful about the $0$ values, $0$ doesn't mean the movie is good or bad. It really means no feedback.

  • $\begingroup$ Can i create a label with other element in the dataset? merged the 2 df (one with user and movie , and one with information about person) ..i tried but i m not sure that i can do $\endgroup$ – theantomc Mar 6 '19 at 12:44
  • $\begingroup$ you mean if you can append two dataframe together? of course you can. But you should ask yourself, what problem are you trying to solve. Are you trying to understand if we can deduce the gender from the movies? Also, those $0$ values, you might want some preprocessing. $\endgroup$ – Siong Thye Goh Mar 6 '19 at 12:48
  • $\begingroup$ because my dataset will be too sparse with all 0 values? and make more noise in the data? you mean this? $\endgroup$ – theantomc Mar 6 '19 at 13:36
  • $\begingroup$ If you view $0$ as really a number, your algorithm might really view it as a very very bad movie since it is less than $1$ but that is not reflective of the truth. It is in fact a label that we do not have information at that value. $\endgroup$ – Siong Thye Goh Mar 6 '19 at 13:41
  • $\begingroup$ Have any suggestion? I can use a median maybe $\endgroup$ – theantomc Mar 6 '19 at 13:59

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.