{"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":"none","dataSources":[{"sourceId":20270,"databundleVersionId":1222630,"sourceType":"competition"}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nfrom sklearn import datasets\nfrom sklearn import model_selection","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-10-11T06:23:08.437411Z","iopub.execute_input":"2025-10-11T06:23:08.438260Z","iopub.status.idle":"2025-10-11T06:23:09.517034Z","shell.execute_reply.started":"2025-10-11T06:23:08.438215Z","shell.execute_reply":"2025-10-11T06:23:09.516159Z"}},"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","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T06:23:09.518359Z","iopub.execute_input":"2025-10-11T06:23:09.518761Z","iopub.status.idle":"2025-10-11T06:23:09.524984Z","shell.execute_reply.started":"2025-10-11T06:23:09.518738Z","shell.execute_reply":"2025-10-11T06:23:09.524012Z"}},"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)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T06:23:09.525910Z","iopub.execute_input":"2025-10-11T06:23:09.526228Z","iopub.status.idle":"2025-10-11T06:23:09.677708Z","shell.execute_reply.started":"2025-10-11T06:23:09.526201Z","shell.execute_reply":"2025-10-11T06:23:09.676837Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_5.to_csv(\"train_5folds.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T06:23:09.679404Z","iopub.execute_input":"2025-10-11T06:23:09.679695Z","iopub.status.idle":"2025-10-11T06:23:09.820477Z","shell.execute_reply.started":"2025-10-11T06:23:09.679674Z","shell.execute_reply":"2025-10-11T06:23:09.819559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_5.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T06:23:09.821365Z","iopub.execute_input":"2025-10-11T06:23:09.821649Z","iopub.status.idle":"2025-10-11T06:23:09.841126Z","shell.execute_reply.started":"2025-10-11T06:23:09.821628Z","shell.execute_reply":"2025-10-11T06:23:09.840406Z"}},"outputs":[],"execution_count":null}]}