{
  "id": 15715,
  "title": "sklearn and pandas",
  "url": "/competitions/flavours-of-physics/discussion/15715",
  "author_name": "",
  "post_date": "2015-08-02T20:58:08.247Z",
  "votes": null,
  "comment_count": 1,
  "views": 546,
  "content": "<p>I'm trying to get a stratified cross validation set, starting with pandas dataframe.  I'm guessing I have to use numpy arrays, but need to get back to a dataframe for the classifier fit.</p>\n\n<p>X = train[all_features].values\nY = train['signal'].values\nskf = StratifiedKFold(Y, n_folds=20, shuffle=True, random_state=0)\nfor trn_idx, vld_idx in skf:\n  Xtrn, Xvld, Ytrn, Yvld = X[trn_idx], X[vld_idx], Y[trn_idx], Y[vld_idx]\n  break\nprint 'Xtrn shape: ', np.shape(Xtrn)\nprint 'Ytrn shape: ', np.shape(Ytrn)\nprint 'Xvld shape: ', np.shape(Xvld)\nprint 'Yvld shape: ', np.shape(Yvld)</p>",
  "messages": [
    {
      "id": "87990",
      "postDate": "08/02/2015 20:58:08",
      "content": "<p>I'm trying to get a stratified cross validation set, starting with pandas dataframe.  I'm guessing I have to use numpy arrays, but need to get back to a dataframe for the classifier fit.</p>\n\n<p>X = train[all_features].values\nY = train['signal'].values\nskf = StratifiedKFold(Y, n_folds=20, shuffle=True, random_state=0)\nfor trn_idx, vld_idx in skf:\n  Xtrn, Xvld, Ytrn, Yvld = X[trn_idx], X[vld_idx], Y[trn_idx], Y[vld_idx]\n  break\nprint 'Xtrn shape: ', np.shape(Xtrn)\nprint 'Ytrn shape: ', np.shape(Ytrn)\nprint 'Xvld shape: ', np.shape(Xvld)\nprint 'Yvld shape: ', np.shape(Yvld)</p>",
      "rawMarkdown": "I'm trying to get a stratified cross validation set, starting with pandas dataframe.  I'm guessing I have to use numpy arrays, but need to get back to a dataframe for the classifier fit.\r\n\r\nX = train[all_features].values\r\nY = train['signal'].values\r\nskf = StratifiedKFold(Y, n_folds=20, shuffle=True, random_state=0)\r\nfor trn_idx, vld_idx in skf:\r\n  Xtrn, Xvld, Ytrn, Yvld = X[trn_idx], X[vld_idx], Y[trn_idx], Y[vld_idx]\r\n  break\r\nprint 'Xtrn shape: ', np.shape(Xtrn)\r\nprint 'Ytrn shape: ', np.shape(Ytrn)\r\nprint 'Xvld shape: ', np.shape(Xvld)\r\nprint 'Yvld shape: ', np.shape(Yvld)",
      "votes": null
    },
    {
      "id": "87997",
      "postDate": "08/02/2015 21:34:07",
      "content": "<p>Ok, I think I got it.  Just have to send in the feature names in the columns variable to df ctor.</p>",
      "rawMarkdown": "Ok, I think I got it.  Just have to send in the feature names in the columns variable to df ctor.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 87997,
      "author_name": "johnhalter",
      "author_url": "",
      "post_date": "08/02/2015 21:34:07",
      "content": "<p>Ok, I think I got it.  Just have to send in the feature names in the columns variable to df ctor.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "87990": "I'm trying to get a stratified cross validation set, starting with pandas dataframe.  I'm guessing I have to use numpy arrays, but need to get back to a dataframe for the classifier fit.\r\n\r\nX = train[all_features].values\r\nY = train['signal'].values\r\nskf = StratifiedKFold(Y, n_folds=20, shuffle=True, random_state=0)\r\nfor trn_idx, vld_idx in skf:\r\n  Xtrn, Xvld, Ytrn, Yvld = X[trn_idx], X[vld_idx], Y[trn_idx], Y[vld_idx]\r\n  break\r\nprint 'Xtrn shape: ', np.shape(Xtrn)\r\nprint 'Ytrn shape: ', np.shape(Ytrn)\r\nprint 'Xvld shape: ', np.shape(Xvld)\r\nprint 'Yvld shape: ', np.shape(Yvld)",
    "87997": "Ok, I think I got it.  Just have to send in the feature names in the columns variable to df ctor."
  },
  "source": "meta"
}