|
3689 | 3689 | "live_data[\"prediction\"] = model.predict(live_data.filter(like=\"feature_\"))\n", |
3690 | 3690 | "live_data.to_parquet(\"predictions.parquet\")" |
3691 | 3691 | ] |
3692 | | - }, |
3693 | | - { |
3694 | | - "cell_type": "code", |
3695 | | - "execution_count": 8, |
3696 | | - "metadata": { |
3697 | | - "id": "EX-tGFkGY_mI" |
3698 | | - }, |
3699 | | - "outputs": [], |
3700 | | - "source": [ |
3701 | | - "# Define your prediction pipeline as a function\n", |
3702 | | - "def predict(live_features: pd.DataFrame) -> pd.DataFrame:\n", |
3703 | | - " live_predictions = model.predict(live_data.filter(like=\"feature_\"))\n", |
3704 | | - " submission = pd.Series(live_predictions, index=live_features.index)\n", |
3705 | | - " return submission.to_frame(\"prediction\")" |
3706 | | - ] |
3707 | | - }, |
3708 | | - { |
3709 | | - "cell_type": "code", |
3710 | | - "execution_count": 9, |
3711 | | - "metadata": { |
3712 | | - "id": "lXl3qyWKZBsP" |
3713 | | - }, |
3714 | | - "outputs": [], |
3715 | | - "source": [ |
3716 | | - "# Use the cloudpickle library to serialize your function\n", |
3717 | | - "import cloudpickle\n", |
3718 | | - "p = cloudpickle.dumps(predict)\n", |
3719 | | - "with open(\"crypto_example_model.pkl\", \"wb\") as f:\n", |
3720 | | - " f.write(p)" |
3721 | | - ] |
3722 | | - }, |
3723 | | - { |
3724 | | - "cell_type": "code", |
3725 | | - "execution_count": 10, |
3726 | | - "metadata": { |
3727 | | - "colab": { |
3728 | | - "base_uri": "https://localhost:8080/", |
3729 | | - "height": 17 |
3730 | | - }, |
3731 | | - "id": "USljDjorZCqj", |
3732 | | - "outputId": "94809fd6-89ab-4637-b435-957ebe6c07a1" |
3733 | | - }, |
3734 | | - "outputs": [ |
3735 | | - { |
3736 | | - "data": { |
3737 | | - "application/javascript": "\n async function download(id, filename, size) {\n if (!google.colab.kernel.accessAllowed) {\n return;\n }\n const div = document.createElement('div');\n const label = document.createElement('label');\n label.textContent = `Downloading \"${filename}\": `;\n div.appendChild(label);\n const progress = document.createElement('progress');\n progress.max = size;\n div.appendChild(progress);\n document.body.appendChild(div);\n\n const buffers = [];\n let downloaded = 0;\n\n const channel = await google.colab.kernel.comms.open(id);\n // Send a message to notify the kernel that we're ready.\n channel.send({})\n\n for await (const message of channel.messages) {\n // Send a message to notify the kernel that we're ready.\n channel.send({})\n if (message.buffers) {\n for (const buffer of message.buffers) {\n buffers.push(buffer);\n downloaded += buffer.byteLength;\n progress.value = downloaded;\n }\n }\n }\n const blob = new Blob(buffers, {type: 'application/binary'});\n const a = document.createElement('a');\n a.href = window.URL.createObjectURL(blob);\n a.download = filename;\n div.appendChild(a);\n a.click();\n div.remove();\n }\n ", |
3738 | | - "text/plain": [ |
3739 | | - "<IPython.core.display.Javascript object>" |
3740 | | - ] |
3741 | | - }, |
3742 | | - "metadata": {}, |
3743 | | - "output_type": "display_data" |
3744 | | - }, |
3745 | | - { |
3746 | | - "data": { |
3747 | | - "application/javascript": "download(\"download_8b3fb0bb-d59e-4532-9af9-f9a24c435c82\", \"crypto_example_model.pkl\", 4115725)", |
3748 | | - "text/plain": [ |
3749 | | - "<IPython.core.display.Javascript object>" |
3750 | | - ] |
3751 | | - }, |
3752 | | - "metadata": {}, |
3753 | | - "output_type": "display_data" |
3754 | | - } |
3755 | | - ], |
3756 | | - "source": [ |
3757 | | - "# Download file if running in Google Colab\n", |
3758 | | - "try:\n", |
3759 | | - " from google.colab import files\n", |
3760 | | - " files.download('crypto_example_model.pkl')\n", |
3761 | | - "except:\n", |
3762 | | - " pass" |
3763 | | - ] |
3764 | 3692 | } |
3765 | 3693 | ], |
3766 | 3694 | "metadata": { |
|
0 commit comments