{"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":25383,"databundleVersionId":2684322,"sourceType":"competition"},{"sourceId":20270,"databundleVersionId":1222630,"sourceType":"competition"}],"dockerImageVersionId":31089,"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-09-09T05:17:34.809287Z","iopub.execute_input":"2025-09-09T05:17:34.809624Z","iopub.status.idle":"2025-09-09T05:17:37.042243Z","shell.execute_reply.started":"2025-09-09T05:17:34.809593Z","shell.execute_reply":"2025-09-09T05:17:37.041235Z"}},"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[\"Pawpularity\"], 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-09-09T05:17:37.043299Z","iopub.execute_input":"2025-09-09T05:17:37.043696Z","iopub.status.idle":"2025-09-09T05:17:37.050825Z","shell.execute_reply.started":"2025-09-09T05:17:37.043673Z","shell.execute_reply":"2025-09-09T05:17:37.049869Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(\"../input/petfinder-pawpularity-score/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-09-09T05:17:37.052678Z","iopub.execute_input":"2025-09-09T05:17:37.052963Z","iopub.status.idle":"2025-09-09T05:17:37.171728Z","shell.execute_reply.started":"2025-09-09T05:17:37.052939Z","shell.execute_reply":"2025-09-09T05:17:37.170677Z"}},"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-09-09T05:17:42.415284Z","iopub.execute_input":"2025-09-09T05:17:42.415622Z","iopub.status.idle":"2025-09-09T05:17:42.519715Z","shell.execute_reply.started":"2025-09-09T05:17:42.415595Z","shell.execute_reply":"2025-09-09T05:17:42.518796Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_5.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-09T05:17:40.554449Z","iopub.execute_input":"2025-09-09T05:17:40.554769Z","iopub.status.idle":"2025-09-09T05:17:40.594998Z","shell.execute_reply.started":"2025-09-09T05:17:40.554743Z","shell.execute_reply":"2025-09-09T05:17:40.593821Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}