{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "Tce3stUlHN0L" }, "source": [ "##### Copyright 2023 The TensorFlow Authors." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "cellView": "form", "execution": { "iopub.execute_input": "2025-02-26T12:05:34.142530Z", "iopub.status.busy": "2025-02-26T12:05:34.142096Z", "iopub.status.idle": "2025-02-26T12:05:34.145903Z", "shell.execute_reply": "2025-02-26T12:05:34.145343Z" }, "id": "tuOe1ymfHZPu" }, "outputs": [], "source": [ "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# https://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "metadata": { "id": "36EdAGhThQov" }, "source": [ "# Uplifting with Decision Forests\n", "\n", "
\n",
" ![]() | \n",
" \n",
" ![]() | \n",
" \n",
" ![]() | \n",
" \n",
" ![]() | \n",
"
🌲 Try YDF, the successor of\n", " TensorFlow\n", " Decision Forests using the same algorithms but with more features and faster\n", " training!\n", "
\n", "\n", " Old code
\n", "\n", "import tensorflow_decision_forests as tfdf\n", "\n", "tf_ds = tfdf.keras.pd_dataframe_to_tf_dataset(ds, label=\"l\")\n", "model = tfdf.keras.RandomForestModel(label=\"l\")\n", "model.fit(tf_ds)\n", "\n", "
\n", " New code
\n", "\n", "import ydf\n", "\n", "model = ydf.RandomForestLearner(label=\"l\").train(ds)\n", "\n", "
(Learn more in the migration\n", " guide)
\n" ], "text/plain": [ "\n", " | channel | \n", "conversion | \n", "history | \n", "history_segment | \n", "mens | \n", "newbie | \n", "recency | \n", "segment | \n", "spend | \n", "visit | \n", "womens | \n", "zip_code | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "b'Web' | \n", "0 | \n", "29.990000 | \n", "b'1) $0 - $100' | \n", "1 | \n", "0 | \n", "6 | \n", "b'Womens E-Mail' | \n", "0.0 | \n", "0 | \n", "0 | \n", "b'Surburban' | \n", "
1 | \n", "b'Web' | \n", "0 | \n", "150.380005 | \n", "b'2) $100 - $200' | \n", "0 | \n", "1 | \n", "9 | \n", "b'Womens E-Mail' | \n", "0.0 | \n", "0 | \n", "1 | \n", "b'Surburban' | \n", "
2 | \n", "b'Phone' | \n", "0 | \n", "602.960022 | \n", "b'5) $500 - $750' | \n", "1 | \n", "1 | \n", "4 | \n", "b'Womens E-Mail' | \n", "0.0 | \n", "0 | \n", "0 | \n", "b'Surburban' | \n", "
3 | \n", "b'Multichannel' | \n", "0 | \n", "341.010010 | \n", "b'3) $200 - $350' | \n", "0 | \n", "0 | \n", "9 | \n", "b'Womens E-Mail' | \n", "0.0 | \n", "1 | \n", "1 | \n", "b'Urban' | \n", "
4 | \n", "b'Phone' | \n", "0 | \n", "97.180000 | \n", "b'1) $0 - $100' | \n", "0 | \n", "1 | \n", "3 | \n", "b'Womens E-Mail' | \n", "0.0 | \n", "1 | \n", "1 | \n", "b'Surburban' | \n", "
5 | \n", "b'Web' | \n", "0 | \n", "83.269997 | \n", "b'1) $0 - $100' | \n", "1 | \n", "0 | \n", "5 | \n", "b'Mens E-Mail' | \n", "0.0 | \n", "0 | \n", "0 | \n", "b'Urban' | \n", "
6 | \n", "b'Web' | \n", "0 | \n", "331.170013 | \n", "b'3) $200 - $350' | \n", "1 | \n", "0 | \n", "8 | \n", "b'Womens E-Mail' | \n", "0.0 | \n", "0 | \n", "0 | \n", "b'Surburban' | \n", "
7 | \n", "b'Multichannel' | \n", "0 | \n", "628.400024 | \n", "b'5) $500 - $750' | \n", "1 | \n", "1 | \n", "9 | \n", "b'No E-Mail' | \n", "0.0 | \n", "1 | \n", "0 | \n", "b'Surburban' | \n", "
8 | \n", "b'Phone' | \n", "0 | \n", "134.610001 | \n", "b'2) $100 - $200' | \n", "1 | \n", "0 | \n", "6 | \n", "b'No E-Mail' | \n", "0.0 | \n", "1 | \n", "0 | \n", "b'Rural' | \n", "
9 | \n", "b'Web' | \n", "0 | \n", "141.210007 | \n", "b'2) $100 - $200' | \n", "0 | \n", "1 | \n", "9 | \n", "b'Mens E-Mail' | \n", "0.0 | \n", "1 | \n", "1 | \n", "b'Surburban' | \n", "