{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-02T12:25:59.384606Z","iopub.execute_input":"2023-08-02T12:25:59.385015Z","iopub.status.idle":"2023-08-02T12:25:59.39202Z","shell.execute_reply.started":"2023-08-02T12:25:59.38498Z","shell.execute_reply":"2023-08-02T12:25:59.390818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Source\n - https://stackoverflow.com/questions/37799865/valueerror-num-must-be-1-num-2-not-3\n - https://pygam.readthedocs.io/en/latest/notebooks/quick_start.html#Fit-a-Model\n ","metadata":{}},{"cell_type":"code","source":"import os\nimport pydicom\n\n# Get the path to the DICOM folder\ndicom_folder_path = \"/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057\"\n\n# Get a list of all the DICOM files in the folder\ndicom_files = os.listdir(dicom_folder_path)\n\n# Iterate over the DICOM files\nfor dicom_file in dicom_files:\n    # Check if the file is a DICOM file\n    if dicom_file.endswith(\".dcm\"):\n        # Read the DICOM file\n        dcm = pydicom.dcmread(os.path.join(dicom_folder_path, dicom_file))","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:25:59.404989Z","iopub.execute_input":"2023-08-02T12:25:59.405521Z","iopub.status.idle":"2023-08-02T12:26:00.937485Z","shell.execute_reply.started":"2023-08-02T12:25:59.405474Z","shell.execute_reply":"2023-08-02T12:26:00.936484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dcm","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:26:00.939358Z","iopub.execute_input":"2023-08-02T12:26:00.939672Z","iopub.status.idle":"2023-08-02T12:26:00.947708Z","shell.execute_reply.started":"2023-08-02T12:26:00.939645Z","shell.execute_reply":"2023-08-02T12:26:00.946744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import matplotlib.pyplot as plt\n# # Iterate over the DICOM files\n# for dicom_file in dicom_files:\n#     # Check if the file is a DICOM file\n#     if dicom_file.endswith(\".dcm\"):\n#         # Read the DICOM file\n#         dcm = pydicom.dcmread(os.path.join(dicom_folder_path, dicom_file))\n\n#         # Get the pixel data\n#         pixel_data = dcm.pixel_array\n\n#         # Plot the image\n#         plt.imshow(pixel_data, cmap=\"gray\")\n#         plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:26:00.949237Z","iopub.execute_input":"2023-08-02T12:26:00.949833Z","iopub.status.idle":"2023-08-02T12:26:00.96247Z","shell.execute_reply.started":"2023-08-02T12:26:00.949803Z","shell.execute_reply":"2023-08-02T12:26:00.96121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import matplotlib.pyplot as plt\n# dicom_folder_path = \"/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057\"\n# for i, dicom_file in enumerate(dicom_files):\n#     # Check if the file is a DICOM file\n#     if dicom_file.endswith(\".dcm\"):\n#         # Read the DICOM file\n#         dcm = pydicom.dcmread(os.path.join(dicom_folder_path, dicom_file))\n\n#         # Get the pixel data\n#         pixel_data = dcm.pixel_array\n\n#         # Plot the image\n#         plt.subplot(11,9,i+1)\n#         plt.imshow(pixel_data, cmap=\"gray\")\n#         plt.title(dicom_file)\n\n# # Show the plot\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:26:00.964342Z","iopub.execute_input":"2023-08-02T12:26:00.964643Z","iopub.status.idle":"2023-08-02T12:26:00.983161Z","shell.execute_reply.started":"2023-08-02T12:26:00.964617Z","shell.execute_reply":"2023-08-02T12:26:00.981274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\nimport ipywidgets as widgets\n\ndicom_files = ['/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm', '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1001.dcm', '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1002.dcm']\nimages = [pydicom.read_file(f) for f in dicom_files]\n\n# Create an interactive slider\nslice_no = widgets.IntSlider(min=0, max=len(images) - 1, value=0, step=1, description='Slice:')\n\ndef show_image(slice_no):\n    image = images[slice_no].pixel_array\n    image = image.astype(np.uint8)\n    plt.imshow(image, cmap='gray')\n    plt.show()\n\n# Connect the slider to the function\nwidgets.interact(show_image, slice_no=slice_no)","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:26:00.985105Z","iopub.execute_input":"2023-08-02T12:26:00.98555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import csv\nwith open('/kaggle/input/rsna-2023-abdominal-trauma-detection/train.csv', 'r') as file:\n    reader = csv.reader(file, delimiter = '\\t')\n    for row in reader:\n        print(row)","metadata":{"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/train.csv')\nprint(df)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_names = df.columns\nprint(column_names)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\n\nX_train, X_test, y_train, y_test = train_test_split(df, df[\"bowel_injury\"], test_size=0.2)\n\nmodel = LinearRegression()\n\nmodel.fit(X_train, y_train)\n\nscore = model.score(X_test, y_test)\n\nprint(\"Accuracy:\", score)","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:44:50.52276Z","iopub.execute_input":"2023-08-02T12:44:50.523206Z","iopub.status.idle":"2023-08-02T12:44:50.564096Z","shell.execute_reply.started":"2023-08-02T12:44:50.523174Z","shell.execute_reply":"2023-08-02T12:44:50.563248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.multiclass import OneVsRestClassifier\nfrom sklearn.linear_model import LogisticRegression\n\n# Create a LogisticRegression classifier\nclf = OneVsRestClassifier(LogisticRegression())\n\n# Train the classifier\nclf.fit(X_train, y_train)\n\n# Make predictions on the test set\npredictions = clf.predict(X_test)\n\n# Calculate the accuracy\naccuracy = np.mean(predictions == y_test)\n\nprint(\"Accuracy:\", accuracy)","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:33:07.482268Z","iopub.execute_input":"2023-08-02T12:33:07.483202Z","iopub.status.idle":"2023-08-02T12:33:07.522887Z","shell.execute_reply.started":"2023-08-02T12:33:07.483171Z","shell.execute_reply":"2023-08-02T12:33:07.522186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.svm import SVC\n# Split the data into training and testing sets\nX_train, X_test, y_train, y_test = train_test_split(df.drop('any_injury', axis=1), df['any_injury'], test_size=0.2)\n\n# Create a SVM model\nmodel = SVC()\n\n# Train the model\nmodel.fit(X_train, y_train)\n\n# Evaluate the model\nprint(model.score(X_test, y_test))\n\n# Use the model to identify injuries\npredictions = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-08-02T12:49:33.687595Z","iopub.execute_input":"2023-08-02T12:49:33.688518Z","iopub.status.idle":"2023-08-02T12:49:33.896435Z","shell.execute_reply.started":"2023-08-02T12:49:33.688483Z","shell.execute_reply":"2023-08-02T12:49:33.895333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install pygam","metadata":{"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}