{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install tensorflow tensorflow_decision_forests","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-27T21:10:47.879686Z","iopub.execute_input":"2023-02-27T21:10:47.880196Z","iopub.status.idle":"2023-02-27T21:15:06.08932Z","shell.execute_reply.started":"2023-02-27T21:10:47.880158Z","shell.execute_reply":"2023-02-27T21:15:06.088103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport tensorflow_decision_forests as tfdf","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:16.838444Z","iopub.execute_input":"2023-02-27T21:15:16.839418Z","iopub.status.idle":"2023-02-27T21:15:16.845744Z","shell.execute_reply.started":"2023-02-27T21:15:16.839376Z","shell.execute_reply":"2023-02-27T21:15:16.844324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:16.848229Z","iopub.execute_input":"2023-02-27T21:15:16.84953Z","iopub.status.idle":"2023-02-27T21:15:17.016592Z","shell.execute_reply.started":"2023-02-27T21:15:16.849484Z","shell.execute_reply":"2023-02-27T21:15:17.015086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:17.069687Z","iopub.execute_input":"2023-02-27T21:15:17.070332Z","iopub.status.idle":"2023-02-27T21:15:17.09778Z","shell.execute_reply.started":"2023-02-27T21:15:17.070295Z","shell.execute_reply":"2023-02-27T21:15:17.096557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:45.036517Z","iopub.execute_input":"2023-02-27T21:15:45.037303Z","iopub.status.idle":"2023-02-27T21:15:45.052902Z","shell.execute_reply.started":"2023-02-27T21:15:45.037254Z","shell.execute_reply":"2023-02-27T21:15:45.05171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_ids = train_df['patient_id'].unique().tolist()","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:47.840826Z","iopub.execute_input":"2023-02-27T21:15:47.841321Z","iopub.status.idle":"2023-02-27T21:15:47.855163Z","shell.execute_reply.started":"2023-02-27T21:15:47.841268Z","shell.execute_reply":"2023-02-27T21:15:47.853599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_s = train_df[train_df['patient_id'].isin(patient_ids[:])]\ndisplay(train_df_s)","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:52.559078Z","iopub.execute_input":"2023-02-27T21:15:52.559527Z","iopub.status.idle":"2023-02-27T21:15:52.597458Z","shell.execute_reply.started":"2023-02-27T21:15:52.559491Z","shell.execute_reply":"2023-02-27T21:15:52.595907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(train_df.loc[:,['laterality', 'view', 'age','implant','cancer']], label=\"cancer\")\ntest_ds = tfdf.keras.pd_dataframe_to_tf_dataset(test_df.loc[:, ['laterality', 'view', 'age','implant']])\n","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:56.01588Z","iopub.execute_input":"2023-02-27T21:15:56.016354Z","iopub.status.idle":"2023-02-27T21:15:56.179335Z","shell.execute_reply.started":"2023-02-27T21:15:56.016316Z","shell.execute_reply":"2023-02-27T21:15:56.178012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tfdf.keras.GradientBoostedTreesModel(verbose=10)\nmodel.fit(train_ds)","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:15:59.963071Z","iopub.execute_input":"2023-02-27T21:15:59.963593Z","iopub.status.idle":"2023-02-27T21:16:12.284503Z","shell.execute_reply.started":"2023-02-27T21:15:59.963546Z","shell.execute_reply":"2023-02-27T21:16:12.283182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:16:29.361548Z","iopub.execute_input":"2023-02-27T21:16:29.36199Z","iopub.status.idle":"2023-02-27T21:16:29.382506Z","shell.execute_reply.started":"2023-02-27T21:16:29.361953Z","shell.execute_reply":"2023-02-27T21:16:29.380824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tfdf.model_plotter.plot_model_in_colab(model, tree_idx=0, max_depth=5)","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:16:37.570412Z","iopub.execute_input":"2023-02-27T21:16:37.570845Z","iopub.status.idle":"2023-02-27T21:16:37.588307Z","shell.execute_reply.started":"2023-02-27T21:16:37.570801Z","shell.execute_reply":"2023-02-27T21:16:37.587044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(train_ds)","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:16:42.51968Z","iopub.execute_input":"2023-02-27T21:16:42.520183Z","iopub.status.idle":"2023-02-27T21:16:43.135815Z","shell.execute_reply.started":"2023-02-27T21:16:42.520141Z","shell.execute_reply":"2023-02-27T21:16:43.134173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(test_ds)\npredictions","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:16:46.438251Z","iopub.execute_input":"2023-02-27T21:16:46.438696Z","iopub.status.idle":"2023-02-27T21:16:46.555975Z","shell.execute_reply.started":"2023-02-27T21:16:46.438659Z","shell.execute_reply":"2023-02-27T21:16:46.554588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:16:51.134143Z","iopub.execute_input":"2023-02-27T21:16:51.134544Z","iopub.status.idle":"2023-02-27T21:16:51.15415Z","shell.execute_reply.started":"2023-02-27T21:16:51.134511Z","shell.execute_reply":"2023-02-27T21:16:51.152598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['cancer'] = predictions\nsubmission= test_df[['prediction_id','cancer']].groupby(['prediction_id']).mean()","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:36:50.944294Z","iopub.execute_input":"2023-02-27T21:36:50.944918Z","iopub.status.idle":"2023-02-27T21:36:50.956617Z","shell.execute_reply.started":"2023-02-27T21:36:50.944859Z","shell.execute_reply":"2023-02-27T21:36:50.955225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#submission = pd.DataFrame(data={'prediction_id': test_df['prediction_id'], 'cancer': np.random.rand(test_df.shape[0])}).drop_duplicates(subset='prediction_id')\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:37:01.482455Z","iopub.execute_input":"2023-02-27T21:37:01.482912Z","iopub.status.idle":"2023-02-27T21:37:01.495077Z","shell.execute_reply.started":"2023-02-27T21:37:01.482874Z","shell.execute_reply":"2023-02-27T21:37:01.493248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-02-27T21:39:32.234211Z","iopub.execute_input":"2023-02-27T21:39:32.234717Z","iopub.status.idle":"2023-02-27T21:39:32.242695Z","shell.execute_reply.started":"2023-02-27T21:39:32.234675Z","shell.execute_reply":"2023-02-27T21:39:32.241424Z"},"trusted":true},"execution_count":null,"outputs":[]}]}