{"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":false,"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-09T18:26:30.784484Z","iopub.execute_input":"2025-10-09T18:26:30.784842Z","iopub.status.idle":"2025-10-09T18:26:34.685627Z","shell.execute_reply.started":"2025-10-09T18:26:30.784787Z","shell.execute_reply":"2025-10-09T18:26:34.684695Z"}},"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-09T18:26:34.687162Z","iopub.execute_input":"2025-10-09T18:26:34.687542Z","iopub.status.idle":"2025-10-09T18:26:34.694403Z","shell.execute_reply.started":"2025-10-09T18:26:34.687515Z","shell.execute_reply":"2025-10-09T18:26:34.693278Z"}},"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-09T18:26:34.695447Z","iopub.execute_input":"2025-10-09T18:26:34.695976Z","iopub.status.idle":"2025-10-09T18:26:34.903865Z","shell.execute_reply.started":"2025-10-09T18:26:34.695739Z","shell.execute_reply":"2025-10-09T18:26:34.902768Z"}},"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-09T18:26:34.904919Z","iopub.execute_input":"2025-10-09T18:26:34.905283Z","iopub.status.idle":"2025-10-09T18:26:35.204908Z","shell.execute_reply.started":"2025-10-09T18:26:34.905252Z","shell.execute_reply":"2025-10-09T18:26:35.203836Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_5.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-09T18:26:35.206866Z","iopub.execute_input":"2025-10-09T18:26:35.207357Z","iopub.status.idle":"2025-10-09T18:26:35.234052Z","shell.execute_reply.started":"2025-10-09T18:26:35.207328Z","shell.execute_reply":"2025-10-09T18:26:35.233033Z"}},"outputs":[],"execution_count":null}]}