{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":20270,"databundleVersionId":1222630,"sourceType":"competition"}],"dockerImageVersionId":31154,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        os.path.join(dirname, filename)\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-10-11T05:01:23.408308Z","iopub.execute_input":"2025-10-11T05:01:23.408877Z","iopub.status.idle":"2025-10-11T05:01:54.467312Z","shell.execute_reply.started":"2025-10-11T05:01:23.408850Z","shell.execute_reply":"2025-10-11T05:01:54.466717Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nfrom sklearn import datasets\nfrom sklearn import model_selection","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T05:02:06.323661Z","iopub.execute_input":"2025-10-11T05:02:06.323921Z","iopub.status.idle":"2025-10-11T05:02:06.327827Z","shell.execute_reply.started":"2025-10-11T05:02:06.323902Z","shell.execute_reply":"2025-10-11T05:02:06.327030Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def create_folds(data, num_splits):\n    data[\"kfold\"] = -1\n    num_bins = int(np.floor(1 + np.log2(len(data))))\n    print('num_bins: ',num_bins)\n\n    data.loc[:, \"bins\"] = pd.cut(data[\"target\"], bins=num_bins, labels=False)\n\n    kf = model_selection.StratifiedKFold(n_splits=num_splits, shuffle=True, random_state=42)\n    \n    for f, (t_, v_) in enumerate(kf.split(X=data, y=data.bins.values)):\n        data.loc[v_, 'kfold'] = f\n#     print(data.head())\n    data = data.drop(\"bins\", axis=1)\n\n    return data\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T05:02:13.176841Z","iopub.execute_input":"2025-10-11T05:02:13.177105Z","iopub.status.idle":"2025-10-11T05:02:13.182120Z","shell.execute_reply.started":"2025-10-11T05:02:13.177085Z","shell.execute_reply":"2025-10-11T05:02:13.181460Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/train.csv\")\n\ndf_5 = create_folds(df, num_splits=5)\ndf_10 = create_folds(df, num_splits=10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T05:02:15.514331Z","iopub.execute_input":"2025-10-11T05:02:15.514629Z","iopub.status.idle":"2025-10-11T05:02:15.592525Z","shell.execute_reply.started":"2025-10-11T05:02:15.514607Z","shell.execute_reply":"2025-10-11T05:02:15.591911Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_5.to_csv(\"train_5folds.csv\", index=False)\ndf_10.to_csv(\"train_10folds.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T05:02:17.341368Z","iopub.execute_input":"2025-10-11T05:02:17.341664Z","iopub.status.idle":"2025-10-11T05:02:17.562018Z","shell.execute_reply.started":"2025-10-11T05:02:17.341640Z","shell.execute_reply":"2025-10-11T05:02:17.561214Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}