{"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-11T18:24:11.238590Z","iopub.execute_input":"2025-10-11T18:24:11.238801Z","iopub.status.idle":"2025-10-11T18:24:12.312504Z","shell.execute_reply.started":"2025-10-11T18:24:11.238780Z","shell.execute_reply":"2025-10-11T18:24:12.311303Z"}},"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-11T18:24:12.313965Z","iopub.execute_input":"2025-10-11T18:24:12.314426Z","iopub.status.idle":"2025-10-11T18:24:12.322285Z","shell.execute_reply.started":"2025-10-11T18:24:12.314400Z","shell.execute_reply":"2025-10-11T18:24:12.321055Z"}},"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)\ndf_5.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-11T18:24:12.323347Z","iopub.execute_input":"2025-10-11T18:24:12.323673Z","iopub.status.idle":"2025-10-11T18:24:12.481365Z","shell.execute_reply.started":"2025-10-11T18:24:12.323644Z","shell.execute_reply":"2025-10-11T18:24:12.480380Z"}},"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-11T18:24:12.482109Z","iopub.execute_input":"2025-10-11T18:24:12.482500Z","iopub.status.idle":"2025-10-11T18:24:12.645273Z","shell.execute_reply.started":"2025-10-11T18:24:12.482470Z","shell.execute_reply":"2025-10-11T18:24:12.644315Z"}},"outputs":[],"execution_count":null}]}