Issue
Sorry for asking dumb question. I'm new to the fetch_20newsgroup. I have printed out the newsgroups_train.target but i still don't get it what it means. Also, I have taken a look at the doc of sklearn. It said that target is a target label? Please someone tell me what does it mean thanks!
print(newsgroups_train.target)
[7 4 4 ... 3 1 8]
Solution
newsgroups_train.target
returns the label corresponding to the features. It represents the ids of the newsgroup your are aiming to predict.
You can convert them to their respective names using newsgroups_train.target_names
as follows :
from sklearn.datasets import fetch_20newsgroups
import numpy as np
newsgroups_train = fetch_20newsgroups(subset='train')
X, y = newsgroups_train.data, newsgroups_train.target
print(np.array(newsgroups_train.target_names)[y])
which output:
['rec.autos' 'comp.sys.mac.hardware' 'comp.sys.mac.hardware' ...
'comp.sys.ibm.pc.hardware' 'comp.graphics' 'rec.motorcycles']
Answered By - Antoine Dubuis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.