{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":39272,"databundleVersionId":4629629,"sourceType":"competition"},{"sourceId":4619805,"sourceType":"datasetVersion","datasetId":2688675}],"dockerImageVersionId":30665,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-03T15:08:02.26869Z","iopub.execute_input":"2024-03-03T15:08:02.26907Z","iopub.status.idle":"2024-03-03T15:08:16.479989Z","shell.execute_reply.started":"2024-03-03T15:08:02.269042Z","shell.execute_reply":"2024-03-03T15:08:16.479021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" # Load train and test CSV files\ntrain_data = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/test.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-03T15:08:58.392422Z","iopub.execute_input":"2024-03-03T15:08:58.393153Z","iopub.status.idle":"2024-03-03T15:08:58.479126Z","shell.execute_reply.started":"2024-03-03T15:08:58.393121Z","shell.execute_reply":"2024-03-03T15:08:58.478151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n \n# Display train data\nprint(\"Train Data:\")\ndisplay(train_data.head())  # Display first few rows of train data\ndisplay(train_data.describe())  # Display summary statistics of train data\n \n# Display test data\nprint(\"\\nTest Data:\")\ndisplay(test_data.head())  # Display first few rows of test data\ndisplay(test_data.describe())  # Display summary statistics of test data\n \n# Visualize distribution of BIRADS scores in train and test data\nplt.figure(figsize=(10, 5))\nplt.subplot(1, 2, 1)\nsns.countplot(data=train_data, x='BIRADS')\nplt.title('Distribution of BIRADS Scores in Train Data')\n \nplt.subplot(1, 2, 2)\nsns.countplot(data=test_data, x='BIRADS')\nplt.title('Distribution of BIRADS Scores in Test Data')\n \nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T15:13:43.712538Z","iopub.execute_input":"2024-03-03T15:13:43.712981Z","iopub.status.idle":"2024-03-03T15:13:44.274454Z","shell.execute_reply.started":"2024-03-03T15:13:43.712949Z","shell.execute_reply":"2024-03-03T15:13:44.273131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" \n# Define image data generators\ntrain_datagen = ImageDataGenerator(rescale=1./255)\ntest_datagen = ImageDataGenerator(rescale=1./255)\n \ntrain_generator = train_datagen.flow_from_dataframe(\n    train_data,\n    x_col='file_paths',\n    y_col='BIRADS',\n    target_size=(512, 512),\n    batch_size=32,\n    class_mode='categorical'\n)\n \ntest_generator = test_datagen.flow_from_dataframe(\n    test_data,\n    x_col='file_paths',\n    y_col='BIRADS',\n    target_size=(IMG_HEIGHT, IMG_WIDTH),\n    batch_size=32,\n    class_mode='categorical'\n)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-03T15:11:27.979587Z","iopub.execute_input":"2024-03-03T15:11:27.979989Z","iopub.status.idle":"2024-03-03T15:11:29.606426Z","shell.execute_reply.started":"2024-03-03T15:11:27.979958Z","shell.execute_reply":"2024-03-03T15:11:29.605118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" \n# Define the model\nmodel = Sequential()\nmodel.add(Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH, 3)))\nmodel.add(MaxPooling2D((2, 2)))\nmodel.add(Conv2D(64, (3, 3), activation='relu'))\nmodel.add(MaxPooling2D((2, 2)))\nmodel.add(Conv2D(128, (3, 3), activation='relu'))\nmodel.add(MaxPooling2D((2, 2)))\nmodel.add(Conv2D(128, (3, 3), activation='relu'))\nmodel.add(MaxPooling2D((2, 2)))\nmodel.add(Flatten())\nmodel.add(Dense(512, activation='relu'))\nmodel.add(Dense(num_classes, activation='softmax'))  # num_classes is the number of unique BIRADS scores\n \n# Compile the model\nmodel.compile(optimizer='adam',\n              loss='categorical_crossentropy',\n              metrics=['accuracy'])\n \n# Train the model\nhistory = model.fit(train_generator,\n                    epochs=20,\n                    validation_data=test_generator)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]}]}