{"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":"none","dataSources":[{"sourceId":82487,"databundleVersionId":9019495,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport os\nimport matplotlib.pyplot as plt\nimport random\nimport seaborn as sns\n\ntrain_x = np.load('/kaggle/input/gpr-data-processing/train_x.npy')\ntrain_y = np.load('/kaggle/input/gpr-data-processing/train_y.npy')\ntest_x = np.load('/kaggle/input/gpr-data-processing/test_x.npy')\nsample_submission = np.load('/kaggle/input/gpr-data-processing/sample_submission.npy')\n\ntrain_x.shape, train_y.shape, test_x.shape, sample_submission.shape, ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-07-04T17:08:13.274202Z","iopub.execute_input":"2024-07-04T17:08:13.275204Z","iopub.status.idle":"2024-07-04T17:08:14.598864Z","shell.execute_reply.started":"2024-07-04T17:08:13.275165Z","shell.execute_reply":"2024-07-04T17:08:14.597487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Function to display random samples from datasets X and Y\ndef show_random_samples(num_samples=3, X=train_x, Y=train_y):\n    # Select 'num_samples' random indices from the dataset\n    samples = [random.randrange(0, X.shape[0]) for i in range(num_samples)]\n    \n    # Create a figure with subplots for displaying the samples\n    fig, axs = plt.subplots(num_samples, 3, figsize=(15, 5 * num_samples))\n\n    # Determine the minimum and maximum values for scaling the color maps\n    bscan_min, bscan_max = np.min(X[samples, :, :, 0]), np.max(X[samples, :, :, 0])\n    geom_min = [np.min(Y[:, :, :, 0]), np.min(Y[:, :, :, 1])]\n    geom_max = [np.max(Y[:, :, :, 0]), np.max(Y[:, :, :, 1])]\n\n    # Loop through each sample index to display its data\n    for i, sample in enumerate(samples):\n        data = X[sample]  # Get the data for the current sample\n        geom_data = Y[sample]  # Get the geometry data for the current sample\n\n        # Display b-scan data\n        im0 = axs[0, i].imshow(data, vmin=bscan_min, vmax=bscan_max, cmap='viridis')\n        axs[0, i].set_title(f'{sample} bscan')\n#         fig.colorbar(im0, ax=axs[0, i], orientation='vertical')\n\n        # Display relative permittivity data\n        im1 = axs[1, i].imshow(geom_data[:, :, 0], vmin=geom_min[0], vmax=geom_max[0], cmap='viridis')\n        axs[1, i].set_title(f'{sample} relative_permitivity')\n#         fig.colorbar(im1, ax=axs[1, i], orientation='vertical')\n\n        # Display conductivity data\n        im2 = axs[2, i].imshow(geom_data[:, :, 1], vmin=geom_min[1], vmax=geom_max[1], cmap='viridis')\n        axs[2, i].set_title(f'{sample} conductivity')\n#         fig.colorbar(im2, ax=axs[i, 2], orientation='vertical')\n\n    # Adjust layout to avoid overlapping\n    plt.tight_layout()\n    plt.show()\n\n# Call the function to display the random samples\nshow_random_samples()","metadata":{"execution":{"iopub.status.busy":"2024-07-04T17:19:42.245299Z","iopub.execute_input":"2024-07-04T17:19:42.245796Z","iopub.status.idle":"2024-07-04T17:19:45.150955Z","shell.execute_reply.started":"2024-07-04T17:19:42.245760Z","shell.execute_reply":"2024-07-04T17:19:45.149670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In the chart above, the last two series are what will need to be predicted","metadata":{}},{"cell_type":"markdown","source":"# Statistical parameters","metadata":{}},{"cell_type":"code","source":"\ndef describe_and_visualize_images(images, suptitle):\n    \"\"\"\n    Compute and visualize statistical parameters for grayscale images.\n\n    Parameters:\n    images (numpy.ndarray): Array of grayscale images with shape [-1, 128, 128, 1].\n\n    Output:\n    Saves and displays statistical plots.\n    \"\"\"\n    if images.ndim != 4 or images.shape[3] != 1:\n        raise ValueError(\"Expected images with shape [-1, 128, 128, 1]\")\n\n    # Flatten images for histogram plotting and statistical computation\n    flattened_images = images.reshape(-1)\n\n    # Compute statistical parameters\n    mean = np.mean(flattened_images)\n    std = np.std(flattened_images)\n    min_pixel = np.min(flattened_images)\n    max_pixel = np.max(flattened_images)\n    median = np.median(flattened_images)\n\n    print(f\"Mean pixel value: {mean}\")\n    print(f\"Standard deviation of pixel values: {std}\")\n    print(f\"Minimum pixel value: {min_pixel}\")\n    print(f\"Maximum pixel value: {max_pixel}\")\n    print(f\"Median pixel value: {median}\")\n\n    # Set up the plotting area\n    sns.set(style=\"whitegrid\")\n    fig, ax = plt.subplots(1, 2, figsize=(16, 6))\n    \n    # Histogram of pixel intensities\n    sns.histplot(flattened_images, bins=50, kde=True, ax=ax[0])\n    ax[0].set_title(\"Histogram of Pixel Values\")\n    ax[0].set_xlabel(\"Pixel Value\")\n    ax[0].set_ylabel(\"Frequency\")\n\n    # Boxplot of pixel intensities\n    sns.boxplot(x=flattened_images, ax=ax[1])\n    ax[1].set_title(\"Boxplot of Pixel Values\")\n    ax[1].set_xlabel(\"Pixel Value\")\n\n    plt.suptitle(suptitle, fontsize=16)\n    \n    # Save the plots\n    plt.savefig(\"statistical_plots.png\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-07-04T17:36:41.021744Z","iopub.execute_input":"2024-07-04T17:36:41.022175Z","iopub.status.idle":"2024-07-04T17:36:41.036576Z","shell.execute_reply.started":"2024-07-04T17:36:41.022145Z","shell.execute_reply":"2024-07-04T17:36:41.035183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_and_visualize_images(train_x, suptitle = 'Statistical Amalysis of GPR data')","metadata":{"execution":{"iopub.status.busy":"2024-07-04T17:36:47.162458Z","iopub.execute_input":"2024-07-04T17:36:47.162897Z","iopub.status.idle":"2024-07-04T17:38:20.644508Z","shell.execute_reply.started":"2024-07-04T17:36:47.162862Z","shell.execute_reply":"2024-07-04T17:38:20.643170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_and_visualize_images(train_y[:,:,:,0:1], suptitle = 'Statistical Amalysis of subsurface, dielectric constant')","metadata":{"execution":{"iopub.status.busy":"2024-07-04T17:38:20.646845Z","iopub.execute_input":"2024-07-04T17:38:20.647350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_and_visualize_images(train_y[:,:,:,1:2], suptitle = 'Statistical Amalysis of subsurface, electrical conductivity')","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}