{
  "id": 418189,
  "title": "Loading saved model and submitting",
  "url": "/competitions/predict-student-performance-from-game-play/discussion/418189",
  "author_name": "",
  "post_date": "2023-06-19T09:27:03.708518500Z",
  "votes": 1,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I can't quite get how can one save a model and then load it back to run the submissions with it, here is the code I use to load my model :<br>\n`# Load the pickled model from the file<br>\nwith open('model.pkl', 'rb') as file:<br>\n    loaded_model = pickle.load(file)</p>\n<h1>Use the loaded pickled model to make predictions</h1>\n<p>loaded_model.predict(X)`</p>\n<p>The weird thing is that when I jump back to my notebook I can see the model.pkl file …</p>",
  "messages": [
    {
      "id": "2308871",
      "postDate": "06/19/2023 09:27:03",
      "content": "<p>I can't quite get how can one save a model and then load it back to run the submissions with it, here is the code I use to load my model :<br>\n`# Load the pickled model from the file<br>\nwith open('model.pkl', 'rb') as file:<br>\n    loaded_model = pickle.load(file)</p>\n<h1>Use the loaded pickled model to make predictions</h1>\n<p>loaded_model.predict(X)`</p>\n<p>The weird thing is that when I jump back to my notebook I can see the model.pkl file …</p>",
      "rawMarkdown": "I can't quite get how can one save a model and then load it back to run the submissions with it, here is the code I use to load my model :\n`# Load the pickled model from the file\nwith open('model.pkl', 'rb') as file:\n    loaded_model = pickle.load(file)\n\n# Use the loaded pickled model to make predictions\nloaded_model.predict(X)`\n\nThe weird thing is that when I jump back to my notebook I can see the model.pkl file ...",
      "votes": null
    },
    {
      "id": "2309056",
      "postDate": "06/19/2023 11:21:28",
      "content": "<p>You can create two notebooks: one for fitting and one for inference. Then, in the fitting notebook you</p>\n<ul>\n<li>fit the model;</li>\n<li>do <code>pickle.dump(…)</code></li>\n<li>press “Save Version”, then “Save and Run” it.</li>\n</ul>\n<p>Once finished, this will create  <code>model.pkl</code> as the notebook’s  output. Then, In the inference notebook </p>\n<ul>\n<li>press “Add Data”;</li>\n<li>select your fitting notebook as data source;</li>\n<li>do <code>model = pickle.load(…)</code>;</li>\n<li>do your inference part and submit notebook for evaluation.</li>\n</ul>",
      "rawMarkdown": "You can create two notebooks: one for fitting and one for inference. Then, in the fitting notebook you\n- fit the model;\n- do `pickle.dump(…)`\n- press “Save Version”, then “Save and Run” it.\n\nOnce finished, this will create  `model.pkl` as the notebook’s  output. Then, In the inference notebook \n- press “Add Data”;\n- select your fitting notebook as data source;\n- do `model = pickle.load(…)`;\n- do your inference part and submit notebook for evaluation.",
      "votes": null
    },
    {
      "id": "2309330",
      "postDate": "06/19/2023 14:24:34",
      "content": "<p>Great ! Will this Add Data automatically import my libraries and all my variables and classes from the fitting notebook as well ? Do I need to set persistence in my notebook settings to files only or something like that ? </p>",
      "rawMarkdown": "Great ! Will this Add Data automatically import my libraries and all my variables and classes from the fitting notebook as well ? Do I need to set persistence in my notebook settings to files only or something like that ?",
      "votes": null
    },
    {
      "id": "2309634",
      "postDate": "06/19/2023 19:04:00",
      "content": "<p>It will only allow you to use output of the fitting notebook, i.e. whatever you save in the external file: <code>model.pkl</code>, <code>anythingelse.pkl</code>, etc.</p>\n<p>Persistence works in the case you are re-opening the same notebook, so it helps you to save variables/files between different sessions. It won't help to transfer data from one notebook to another.</p>",
      "rawMarkdown": "It will only allow you to use output of the fitting notebook, i.e. whatever you save in the external file: `model.pkl`, `anythingelse.pkl`, etc.\n\nPersistence works in the case you are re-opening the same notebook, so it helps you to save variables/files between different sessions. It won't help to transfer data from one notebook to another.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2309056,
      "author_name": "kononenko",
      "author_url": "",
      "post_date": "06/19/2023 11:21:28",
      "content": "<p>You can create two notebooks: one for fitting and one for inference. Then, in the fitting notebook you</p>\n<ul>\n<li>fit the model;</li>\n<li>do <code>pickle.dump(…)</code></li>\n<li>press “Save Version”, then “Save and Run” it.</li>\n</ul>\n<p>Once finished, this will create  <code>model.pkl</code> as the notebook’s  output. Then, In the inference notebook </p>\n<ul>\n<li>press “Add Data”;</li>\n<li>select your fitting notebook as data source;</li>\n<li>do <code>model = pickle.load(…)</code>;</li>\n<li>do your inference part and submit notebook for evaluation.</li>\n</ul>",
      "votes": null,
      "replies": [
        {
          "id": 2309330,
          "author_name": "qurious",
          "author_url": "",
          "post_date": "06/19/2023 14:24:34",
          "content": "<p>Great ! Will this Add Data automatically import my libraries and all my variables and classes from the fitting notebook as well ? Do I need to set persistence in my notebook settings to files only or something like that ? </p>",
          "votes": null,
          "replies": [
            {
              "id": 2309634,
              "author_name": "kononenko",
              "author_url": "",
              "post_date": "06/19/2023 19:04:00",
              "content": "<p>It will only allow you to use output of the fitting notebook, i.e. whatever you save in the external file: <code>model.pkl</code>, <code>anythingelse.pkl</code>, etc.</p>\n<p>Persistence works in the case you are re-opening the same notebook, so it helps you to save variables/files between different sessions. It won't help to transfer data from one notebook to another.</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2308871": "I can't quite get how can one save a model and then load it back to run the submissions with it, here is the code I use to load my model :\n`# Load the pickled model from the file\nwith open('model.pkl', 'rb') as file:\n    loaded_model = pickle.load(file)\n\n# Use the loaded pickled model to make predictions\nloaded_model.predict(X)`\n\nThe weird thing is that when I jump back to my notebook I can see the model.pkl file ...",
    "2309056": "You can create two notebooks: one for fitting and one for inference. Then, in the fitting notebook you\n- fit the model;\n- do `pickle.dump(…)`\n- press “Save Version”, then “Save and Run” it.\n\nOnce finished, this will create  `model.pkl` as the notebook’s  output. Then, In the inference notebook \n- press “Add Data”;\n- select your fitting notebook as data source;\n- do `model = pickle.load(…)`;\n- do your inference part and submit notebook for evaluation.",
    "2309330": "Great ! Will this Add Data automatically import my libraries and all my variables and classes from the fitting notebook as well ? Do I need to set persistence in my notebook settings to files only or something like that ?",
    "2309634": "It will only allow you to use output of the fitting notebook, i.e. whatever you save in the external file: `model.pkl`, `anythingelse.pkl`, etc.\n\nPersistence works in the case you are re-opening the same notebook, so it helps you to save variables/files between different sessions. It won't help to transfer data from one notebook to another."
  },
  "source": "meta"
}