{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6045","repository_url":"https://api.github.com/repos/scikit-learn/scikit-learn","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6045/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6045/comments","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6045/events","html_url":"https://github.com/scikit-learn/scikit-learn/issues/6045","id":122417294,"number":6045,"title":"Accept multiple values for one categorical feature","user":{"login":"xxthermidorxx","id":3449164,"avatar_url":"https://avatars.githubusercontent.com/u/3449164?v=3","gravatar_id":"","url":"https://api.github.com/users/xxthermidorxx","html_url":"https://github.com/xxthermidorxx","followers_url":"https://api.github.com/users/xxthermidorxx/followers","following_url":"https://api.github.com/users/xxthermidorxx/following{/other_user}","gists_url":"https://api.github.com/users/xxthermidorxx/gists{/gist_id}","starred_url":"https://api.github.com/users/xxthermidorxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xxthermidorxx/subscriptions","organizations_url":"https://api.github.com/users/xxthermidorxx/orgs","repos_url":"https://api.github.com/users/xxthermidorxx/repos","events_url":"https://api.github.com/users/xxthermidorxx/events{/privacy}","received_events_url":"https://api.github.com/users/xxthermidorxx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-16T03:07:28Z","updated_at":"2016-04-04T03:14:12Z","closed_at":null,"body":"Hello,\r\n\r\nI think it is convenient to accept ```list``` as a value of ```dict``` in ```DictVectorizer.fit()```\r\nto accept multiple values for one categorical feature.\r\n\r\nAssume that we use the category of movies as a feature,\r\nand this category can be 'action', 'love-comedy', 'science-fiction', etc...\r\nSome movies match some of these categories,\r\n'The Matrix' can be both 'action' and 'science-fiction', for example.\r\n\r\nIdeal form in my mind is as follows:\r\n\r\n```python\r\n>>> dv = DictVectorizer(sparse=False)\r\n>>> movie_features = [{'category': ['action', 'science-fiction']}, {'category': 'action'}]\r\n>>> dv.fit_transform(movie_features)\r\narray([[1, 1],\r\n       [1, 0]])\r\n>>> dv.get_feature_names()\r\n['category=action', 'category=science-fiction']\r\n```\r\n\r\nBut with present API of ```DictVectorizer.fit()```, it only accepts one value for 'category', ```int``` or ```str```\r\nand we have to write redundant codes to achieve this, like this:\r\n\r\n```python\r\n>>> movie_features = [{'category': ['action', 'science-fiction']}, {'category': ['action']}]\r\n>>> new_movie_features = []\r\n>>> for movie in movie_features:\r\n...     cate_list = movie['category']\r\n...     feature_dict = {}\r\n...     for cate in cate_list:\r\n...         key = 'category={}'.format(cate)\r\n...         feature_dict[key] = 1\r\n...     new_movie_features.append(feature_dict)\r\n>>> new_movie_features\r\n[{'category=science-fiction': 1, 'category=action': 1}, {'category=action': 1}]\r\n```\r\n\r\nIf there exists a way to use multiple values for one categorical feature\r\nor there is already similar issue, could you please let me know?\r\nOtherwise, if accepting ```list``` as a values of ```dict``` is a reasonable way, I'll send a PR later."},"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/205114998","html_url":"https://github.com/scikit-learn/scikit-learn/issues/6045#issuecomment-205114998","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6045","id":205114998,"user":{"login":"22csnyder","id":10726729,"avatar_url":"https://avatars.githubusercontent.com/u/10726729?v=3","gravatar_id":"","url":"https://api.github.com/users/22csnyder","html_url":"https://github.com/22csnyder","followers_url":"https://api.github.com/users/22csnyder/followers","following_url":"https://api.github.com/users/22csnyder/following{/other_user}","gists_url":"https://api.github.com/users/22csnyder/gists{/gist_id}","starred_url":"https://api.github.com/users/22csnyder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/22csnyder/subscriptions","organizations_url":"https://api.github.com/users/22csnyder/orgs","repos_url":"https://api.github.com/users/22csnyder/repos","events_url":"https://api.github.com/users/22csnyder/events{/privacy}","received_events_url":"https://api.github.com/users/22csnyder/received_events","type":"User","site_admin":false},"created_at":"2016-04-04T03:14:12Z","updated_at":"2016-04-04T03:14:12Z","body":"Came across exactly this issue today. Seems appropriate to leave this remark here as a show of interest."}}