{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/patsy/issues/78","labels_url":"https://api.github.com/repos/pydata/patsy/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/pydata/patsy/issues/78/comments","events_url":"https://api.github.com/repos/pydata/patsy/issues/78/events","html_url":"https://github.com/pydata/patsy/issues/78","id":117035520,"number":78,"title":"Python. Titanic Data Error","user":{"login":"pintolx","id":15163435,"avatar_url":"https://avatars.githubusercontent.com/u/15163435?v=3","gravatar_id":"","url":"https://api.github.com/users/pintolx","html_url":"https://github.com/pintolx","followers_url":"https://api.github.com/users/pintolx/followers","following_url":"https://api.github.com/users/pintolx/following{/other_user}","gists_url":"https://api.github.com/users/pintolx/gists{/gist_id}","starred_url":"https://api.github.com/users/pintolx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pintolx/subscriptions","organizations_url":"https://api.github.com/users/pintolx/orgs","repos_url":"https://api.github.com/users/pintolx/repos","events_url":"https://api.github.com/users/pintolx/events{/privacy}","received_events_url":"https://api.github.com/users/pintolx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-11-16T01:49:28Z","updated_at":"2015-11-16T03:41:26Z","closed_at":null,"body":"I am trying out some machine learning algorithms to be able to predict the people who survived who were aboard the titanic. I am following this example https://github.com/mlakhavani/titanic/blob/master/TitanixFinal.ipynb\r\n\r\nHowever on from patsy import dmatrices\r\n```\r\ny, x = dmatrices('survived ~ sex + age + sibsp + parch + pclass + fare + C + Q + S + Col + Dr + Master + Miss + Mr + Mrs + Rev',\r\n                 titanic_train, return_type=\"dataframe\")\r\n\r\ny_test, x_test = dmatrices('survived ~ sex + age + sibsp + parch + pclass + fare + + C + Q + S + Col + Dr + Master + Miss + Mr + Mrs + Rev',\r\n                           titanic_test, return_type=\"dataframe\")\r\ni get this error\r\nPatsyError                                Traceback (most recent call last)\r\n<ipython-input-153-63b2f538454b> in <module>()\r\n      1 y_test, x_test = dmatrices('Survived ~ Sex + Age + SibSp + Parch + Pclass + Fare + + C + Q + S ++ Dr + Master + Miss + Mr + Mrs + Rev',\r\n----> 2                            titanic_test, return_type=\"dataframe\")\r\n\r\nC:\\Anaconda\\lib\\site-packages\\patsy\\highlevel.pyc in dmatrices(formula_like, data, eval_env, NA_action, return_type)\r\n    295     eval_env = EvalEnvironment.capture(eval_env, reference=1)\r\n    296     (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,\r\n--> 297                                       NA_action, return_type)\r\n    298     if lhs.shape[1] == 0:\r\n    299         raise PatsyError(\"model is missing required outcome variables\")\r\n\r\nC:\\Anaconda\\lib\\site-packages\\patsy\\highlevel.pyc in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)\r\n    154         return build_design_matrices(builders, data,\r\n    155                                      NA_action=NA_action,\r\n--> 156                                      return_type=return_type)\r\n    157     else:\r\n    158         # No builders, but maybe we can still get matrices\r\n\r\nC:\\Anaconda\\lib\\site-packages\\patsy\\build.pyc in build_design_matrices(builders, data, NA_action, return_type, dtype)\r\n    945         for evaluator in builder._evaluators:\r\n    946             if evaluator not in evaluator_to_values:\r\n--> 947                 value, is_NA = evaluator.eval(data, NA_action)\r\n    948                 evaluator_to_isNAs[evaluator] = is_NA\r\n    949                 # value may now be a Series, DataFrame, or ndarray\r\n\r\nC:\\Anaconda\\lib\\site-packages\\patsy\\build.pyc in eval(self, data, NA_action)\r\n    161         result = self.factor.eval(self._state, data)\r\n    162         result = categorical_to_int(result, self._levels, NA_action,\r\n--> 163                                     origin=self.factor)\r\n    164         assert result.ndim == 1\r\n    165         return result, np.asarray(result == -1)\r\n\r\nC:\\Anaconda\\lib\\site-packages\\patsy\\categorical.pyc in categorical_to_int(data, levels, NA_action, origin)\r\n    270     if hasattr(data, \"shape\") and len(data.shape) > 1:\r\n    271         raise PatsyError(\"categorical data must be 1-dimensional\",\r\n--> 272                          origin)\r\n    273     if (not iterable(data)\r\n    274         or isinstance(data, (six.text_type, six.binary_type))):\r\n\r\nPatsyError: categorical data must be 1-dimensional\r\n    Survived ~ Sex + Age + SibSp + Parch + Pclass + Fare + + C + Q + S ++ Dr + Master + Miss + Mr + Mrs + Rev\r\n\r\n```\r\nHow can i solve this issue?"},"comment":{"url":"https://api.github.com/repos/pydata/patsy/issues/comments/156907165","html_url":"https://github.com/pydata/patsy/issues/78#issuecomment-156907165","issue_url":"https://api.github.com/repos/pydata/patsy/issues/78","id":156907165,"user":{"login":"njsmith","id":609896,"avatar_url":"https://avatars.githubusercontent.com/u/609896?v=3","gravatar_id":"","url":"https://api.github.com/users/njsmith","html_url":"https://github.com/njsmith","followers_url":"https://api.github.com/users/njsmith/followers","following_url":"https://api.github.com/users/njsmith/following{/other_user}","gists_url":"https://api.github.com/users/njsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/njsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/njsmith/subscriptions","organizations_url":"https://api.github.com/users/njsmith/orgs","repos_url":"https://api.github.com/users/njsmith/repos","events_url":"https://api.github.com/users/njsmith/events{/privacy}","received_events_url":"https://api.github.com/users/njsmith/received_events","type":"User","site_admin":false},"created_at":"2015-11-16T03:41:26Z","updated_at":"2015-11-16T03:41:26Z","body":"Huh. Well, that tells us that whatever you've done, it's very different than anything in that notebook you linked to. And if you're only getting this on the test set and not the training set, then it probably means you made some mistake in your code above setting up the test set.\r\n\r\nIf you do `titanic_test[\"Patch\"].dtypes` then I bet it will say that one of those columns has type `object`, which means that you created it in a way that you said it can contain arbitrary non-integer values (like strings or whatever), so patsy is taking you at your word and treating it as categorical even though all the values happen to be numbers. So you need to figure out how to fix that. (Maybe it shouldn't be a dataframe with two columns, either.)\r\n\r\nFiguring out how happened and fixing it will require looking at your code that created this object, and that's more a general pandas question. If you can't figure it out then I'd suggest asking on stackoverflow or the pandas mailing list."}}