{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19596,"databundleVersionId":1292430,"sourceType":"competition"},{"sourceId":1262046,"sourceType":"datasetVersion","datasetId":726424},{"sourceId":1264575,"sourceType":"datasetVersion","datasetId":725893}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\nfor 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":"2024-01-13T10:28:07.843888Z","iopub.execute_input":"2024-01-13T10:28:07.844321Z","iopub.status.idle":"2024-01-13T10:28:08.377213Z","shell.execute_reply.started":"2024-01-13T10:28:07.844289Z","shell.execute_reply":"2024-01-13T10:28:08.375556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport audioread\nimport logging\nimport os\nimport random\nimport time\nimport warnings\n\nimport librosa\nimport numpy as np\nimport pandas as pd\nimport soundfile as sf\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.utils.data as data\n\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom typing import Optional\n\nfrom fastprogress import progress_bar\nfrom sklearn.metrics import f1_score\nfrom torchvision import models\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:08.380123Z","iopub.execute_input":"2024-01-13T10:28:08.380761Z","iopub.status.idle":"2024-01-13T10:28:08.391613Z","shell.execute_reply.started":"2024-01-13T10:28:08.380704Z","shell.execute_reply":"2024-01-13T10:28:08.390395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train = pd.read_csv('/kaggle/input/birdsong-recognition/train.csv')\nTrain","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:08.393791Z","iopub.execute_input":"2024-01-13T10:28:08.394254Z","iopub.status.idle":"2024-01-13T10:28:08.910218Z","shell.execute_reply.started":"2024-01-13T10:28:08.394210Z","shell.execute_reply":"2024-01-13T10:28:08.908056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:08.914342Z","iopub.execute_input":"2024-01-13T10:28:08.914895Z","iopub.status.idle":"2024-01-13T10:28:08.923884Z","shell.execute_reply.started":"2024-01-13T10:28:08.914823Z","shell.execute_reply":"2024-01-13T10:28:08.922254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns',None)\npd.set_option('display.expand_frame_repr',False)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:08.925701Z","iopub.execute_input":"2024-01-13T10:28:08.926190Z","iopub.status.idle":"2024-01-13T10:28:08.938095Z","shell.execute_reply.started":"2024-01-13T10:28:08.926145Z","shell.execute_reply":"2024-01-13T10:28:08.936589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:08.942919Z","iopub.execute_input":"2024-01-13T10:28:08.943931Z","iopub.status.idle":"2024-01-13T10:28:08.991301Z","shell.execute_reply.started":"2024-01-13T10:28:08.943884Z","shell.execute_reply":"2024-01-13T10:28:08.990070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:08.993247Z","iopub.execute_input":"2024-01-13T10:28:08.994249Z","iopub.status.idle":"2024-01-13T10:28:09.087030Z","shell.execute_reply.started":"2024-01-13T10:28:08.994192Z","shell.execute_reply":"2024-01-13T10:28:09.086239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(Train.columns[Train.isnull().any()])","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.088264Z","iopub.execute_input":"2024-01-13T10:28:09.088738Z","iopub.status.idle":"2024-01-13T10:28:09.195975Z","shell.execute_reply.started":"2024-01-13T10:28:09.088708Z","shell.execute_reply":"2024-01-13T10:28:09.194411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['playback_used'].fillna('no',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.197959Z","iopub.execute_input":"2024-01-13T10:28:09.199195Z","iopub.status.idle":"2024-01-13T10:28:09.231815Z","shell.execute_reply.started":"2024-01-13T10:28:09.199137Z","shell.execute_reply":"2024-01-13T10:28:09.229446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['playback_used'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.238530Z","iopub.execute_input":"2024-01-13T10:28:09.239597Z","iopub.status.idle":"2024-01-13T10:28:09.254706Z","shell.execute_reply.started":"2024-01-13T10:28:09.239550Z","shell.execute_reply":"2024-01-13T10:28:09.253424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()\nTrain['playback_used']=le.fit_transform(Train['playback_used'])","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.256702Z","iopub.execute_input":"2024-01-13T10:28:09.257058Z","iopub.status.idle":"2024-01-13T10:28:09.273949Z","shell.execute_reply.started":"2024-01-13T10:28:09.257028Z","shell.execute_reply":"2024-01-13T10:28:09.272881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.275486Z","iopub.execute_input":"2024-01-13T10:28:09.276971Z","iopub.status.idle":"2024-01-13T10:28:09.325013Z","shell.execute_reply.started":"2024-01-13T10:28:09.276915Z","shell.execute_reply":"2024-01-13T10:28:09.323846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['channels'] = Train['channels'].astype(str).str[0].astype(int) \nTrain","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.326623Z","iopub.execute_input":"2024-01-13T10:28:09.329302Z","iopub.status.idle":"2024-01-13T10:28:09.407686Z","shell.execute_reply.started":"2024-01-13T10:28:09.329230Z","shell.execute_reply":"2024-01-13T10:28:09.406204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['year'] = Train['date'].apply(lambda x: x.split('-')[0])\nTrain['month'] = Train['date'].apply(lambda x: x.split('-')[1])\nTrain['Date'] = Train['date'].apply(lambda x: x.split('-')[2])\n","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.409158Z","iopub.execute_input":"2024-01-13T10:28:09.409486Z","iopub.status.idle":"2024-01-13T10:28:09.464401Z","shell.execute_reply.started":"2024-01-13T10:28:09.409437Z","shell.execute_reply":"2024-01-13T10:28:09.463161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.466038Z","iopub.execute_input":"2024-01-13T10:28:09.466518Z","iopub.status.idle":"2024-01-13T10:28:09.518169Z","shell.execute_reply.started":"2024-01-13T10:28:09.466452Z","shell.execute_reply":"2024-01-13T10:28:09.516740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('date',axis=1,inplace=True)\nTrain","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.520039Z","iopub.execute_input":"2024-01-13T10:28:09.520408Z","iopub.status.idle":"2024-01-13T10:28:09.588576Z","shell.execute_reply.started":"2024-01-13T10:28:09.520377Z","shell.execute_reply":"2024-01-13T10:28:09.587211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['pitch'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.590503Z","iopub.execute_input":"2024-01-13T10:28:09.591611Z","iopub.status.idle":"2024-01-13T10:28:09.607760Z","shell.execute_reply.started":"2024-01-13T10:28:09.591564Z","shell.execute_reply":"2024-01-13T10:28:09.606803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Train.drop('pitch',axis=1,inplace=True)\nTrain","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.608949Z","iopub.execute_input":"2024-01-13T10:28:09.609364Z","iopub.status.idle":"2024-01-13T10:28:09.658184Z","shell.execute_reply.started":"2024-01-13T10:28:09.609324Z","shell.execute_reply":"2024-01-13T10:28:09.656793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Train.drop('speed',axis=1,inplace = True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.659598Z","iopub.execute_input":"2024-01-13T10:28:09.659922Z","iopub.status.idle":"2024-01-13T10:28:09.664794Z","shell.execute_reply.started":"2024-01-13T10:28:09.659893Z","shell.execute_reply":"2024-01-13T10:28:09.663668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['species'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.666169Z","iopub.execute_input":"2024-01-13T10:28:09.666587Z","iopub.status.idle":"2024-01-13T10:28:09.682312Z","shell.execute_reply.started":"2024-01-13T10:28:09.666546Z","shell.execute_reply":"2024-01-13T10:28:09.681051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['number_of_notes'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.684635Z","iopub.execute_input":"2024-01-13T10:28:09.685047Z","iopub.status.idle":"2024-01-13T10:28:09.699179Z","shell.execute_reply.started":"2024-01-13T10:28:09.684998Z","shell.execute_reply":"2024-01-13T10:28:09.697575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.701096Z","iopub.execute_input":"2024-01-13T10:28:09.701633Z","iopub.status.idle":"2024-01-13T10:28:09.752182Z","shell.execute_reply.started":"2024-01-13T10:28:09.701586Z","shell.execute_reply":"2024-01-13T10:28:09.750531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Train['min_notes'] = Train['number_of_notes'].apply(lambda x: x.split('-')[0])\n#Train['max_notes'] = Train['number_of_notes'].apply(lambda x: x.split('-')[1])","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.753875Z","iopub.execute_input":"2024-01-13T10:28:09.754275Z","iopub.status.idle":"2024-01-13T10:28:09.763495Z","shell.execute_reply.started":"2024-01-13T10:28:09.754240Z","shell.execute_reply":"2024-01-13T10:28:09.761930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('title',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.765130Z","iopub.execute_input":"2024-01-13T10:28:09.765566Z","iopub.status.idle":"2024-01-13T10:28:09.791791Z","shell.execute_reply.started":"2024-01-13T10:28:09.765528Z","shell.execute_reply":"2024-01-13T10:28:09.790230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['secondary_labels'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.793432Z","iopub.execute_input":"2024-01-13T10:28:09.793848Z","iopub.status.idle":"2024-01-13T10:28:09.808213Z","shell.execute_reply.started":"2024-01-13T10:28:09.793812Z","shell.execute_reply":"2024-01-13T10:28:09.806481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['bird_seen'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.809684Z","iopub.execute_input":"2024-01-13T10:28:09.810033Z","iopub.status.idle":"2024-01-13T10:28:09.821365Z","shell.execute_reply.started":"2024-01-13T10:28:09.810002Z","shell.execute_reply":"2024-01-13T10:28:09.820621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['sci_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.822557Z","iopub.execute_input":"2024-01-13T10:28:09.822887Z","iopub.status.idle":"2024-01-13T10:28:09.836142Z","shell.execute_reply.started":"2024-01-13T10:28:09.822857Z","shell.execute_reply":"2024-01-13T10:28:09.834804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['latitude'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.845665Z","iopub.execute_input":"2024-01-13T10:28:09.846343Z","iopub.status.idle":"2024-01-13T10:28:09.866940Z","shell.execute_reply.started":"2024-01-13T10:28:09.846309Z","shell.execute_reply":"2024-01-13T10:28:09.865250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train = Train[Train['latitude']!='Not specified']\nTrain = Train[Train['longitude']!='Not specified']","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.869013Z","iopub.execute_input":"2024-01-13T10:28:09.869391Z","iopub.status.idle":"2024-01-13T10:28:09.944138Z","shell.execute_reply.started":"2024-01-13T10:28:09.869356Z","shell.execute_reply":"2024-01-13T10:28:09.943091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['latitude'] = Train['latitude'].astype(float)\nTrain['longitude'] = Train['longitude'].astype(float)\nTrain","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:09.945926Z","iopub.execute_input":"2024-01-13T10:28:09.946608Z","iopub.status.idle":"2024-01-13T10:28:10.009285Z","shell.execute_reply.started":"2024-01-13T10:28:09.946567Z","shell.execute_reply":"2024-01-13T10:28:10.007901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.011039Z","iopub.execute_input":"2024-01-13T10:28:10.011427Z","iopub.status.idle":"2024-01-13T10:28:10.092753Z","shell.execute_reply.started":"2024-01-13T10:28:10.011394Z","shell.execute_reply":"2024-01-13T10:28:10.091540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['year'] = Train['year'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.094083Z","iopub.execute_input":"2024-01-13T10:28:10.094416Z","iopub.status.idle":"2024-01-13T10:28:10.104558Z","shell.execute_reply.started":"2024-01-13T10:28:10.094386Z","shell.execute_reply":"2024-01-13T10:28:10.103208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['month'] = Train['month'].astype(int)\n\nTrain['Date'] = Train['Date'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.106144Z","iopub.execute_input":"2024-01-13T10:28:10.106458Z","iopub.status.idle":"2024-01-13T10:28:10.125578Z","shell.execute_reply.started":"2024-01-13T10:28:10.106430Z","shell.execute_reply":"2024-01-13T10:28:10.124078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.128995Z","iopub.execute_input":"2024-01-13T10:28:10.129500Z","iopub.status.idle":"2024-01-13T10:28:10.209994Z","shell.execute_reply.started":"2024-01-13T10:28:10.129433Z","shell.execute_reply":"2024-01-13T10:28:10.208573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['sampling_rate'] = Train['sampling_rate'].apply(lambda x: x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.212537Z","iopub.execute_input":"2024-01-13T10:28:10.213032Z","iopub.status.idle":"2024-01-13T10:28:10.239076Z","shell.execute_reply.started":"2024-01-13T10:28:10.212988Z","shell.execute_reply":"2024-01-13T10:28:10.237573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.240834Z","iopub.execute_input":"2024-01-13T10:28:10.241579Z","iopub.status.idle":"2024-01-13T10:28:10.321250Z","shell.execute_reply.started":"2024-01-13T10:28:10.241540Z","shell.execute_reply":"2024-01-13T10:28:10.319827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.322721Z","iopub.execute_input":"2024-01-13T10:28:10.323037Z","iopub.status.idle":"2024-01-13T10:28:10.373498Z","shell.execute_reply.started":"2024-01-13T10:28:10.323008Z","shell.execute_reply":"2024-01-13T10:28:10.372148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.375402Z","iopub.execute_input":"2024-01-13T10:28:10.375848Z","iopub.status.idle":"2024-01-13T10:28:10.385461Z","shell.execute_reply.started":"2024-01-13T10:28:10.375807Z","shell.execute_reply":"2024-01-13T10:28:10.384441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['type'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.386383Z","iopub.execute_input":"2024-01-13T10:28:10.386719Z","iopub.status.idle":"2024-01-13T10:28:10.402077Z","shell.execute_reply.started":"2024-01-13T10:28:10.386690Z","shell.execute_reply":"2024-01-13T10:28:10.400559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Type = Train['type'].apply(lambda x:x.split(',')).reset_index().explode(\"type\")\nType = Type['type'].apply(lambda x:x.strip().lower()).reset_index()\nType['type'] = Type['type'].replace('calls','call')\nType['type'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.403840Z","iopub.execute_input":"2024-01-13T10:28:10.404268Z","iopub.status.idle":"2024-01-13T10:28:10.472682Z","shell.execute_reply.started":"2024-01-13T10:28:10.404228Z","shell.execute_reply":"2024-01-13T10:28:10.471239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['elevation'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.474973Z","iopub.execute_input":"2024-01-13T10:28:10.475844Z","iopub.status.idle":"2024-01-13T10:28:10.492375Z","shell.execute_reply.started":"2024-01-13T10:28:10.475792Z","shell.execute_reply":"2024-01-13T10:28:10.491241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['elevation'] = Train['elevation'].replace(['? m','Unknown m',' m'],0)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.494526Z","iopub.execute_input":"2024-01-13T10:28:10.495989Z","iopub.status.idle":"2024-01-13T10:28:10.511628Z","shell.execute_reply.started":"2024-01-13T10:28:10.495937Z","shell.execute_reply":"2024-01-13T10:28:10.510507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['elevation'] = Train['elevation'].astype(str)\nTrain['elevation'] = Train['elevation'].apply(lambda x:x.split(' ')[0])\n","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.513151Z","iopub.execute_input":"2024-01-13T10:28:10.514649Z","iopub.status.idle":"2024-01-13T10:28:10.534715Z","shell.execute_reply.started":"2024-01-13T10:28:10.514612Z","shell.execute_reply":"2024-01-13T10:28:10.533098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['elevation'] = pd.to_numeric(Train['elevation'], errors='coerce')\nTrain['elevation'] = Train['elevation'].fillna(0).astype(int)\n","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.536386Z","iopub.execute_input":"2024-01-13T10:28:10.536792Z","iopub.status.idle":"2024-01-13T10:28:10.572317Z","shell.execute_reply.started":"2024-01-13T10:28:10.536759Z","shell.execute_reply":"2024-01-13T10:28:10.571209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('description',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.573758Z","iopub.execute_input":"2024-01-13T10:28:10.574606Z","iopub.status.idle":"2024-01-13T10:28:10.597295Z","shell.execute_reply.started":"2024-01-13T10:28:10.574569Z","shell.execute_reply":"2024-01-13T10:28:10.595833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['bitrate_of_mp3'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.602653Z","iopub.execute_input":"2024-01-13T10:28:10.603068Z","iopub.status.idle":"2024-01-13T10:28:10.614603Z","shell.execute_reply.started":"2024-01-13T10:28:10.603034Z","shell.execute_reply":"2024-01-13T10:28:10.613100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop(Train[Train['bitrate_of_mp3']=='3'].index,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.616571Z","iopub.execute_input":"2024-01-13T10:28:10.617504Z","iopub.status.idle":"2024-01-13T10:28:10.645238Z","shell.execute_reply.started":"2024-01-13T10:28:10.617440Z","shell.execute_reply":"2024-01-13T10:28:10.643677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['bitrate_of_mp3']=Train['bitrate_of_mp3'].fillna('0')","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.646902Z","iopub.execute_input":"2024-01-13T10:28:10.647267Z","iopub.status.idle":"2024-01-13T10:28:10.657996Z","shell.execute_reply.started":"2024-01-13T10:28:10.647235Z","shell.execute_reply":"2024-01-13T10:28:10.656310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['bitrate_of_mp3'] = Train['bitrate_of_mp3'].apply(lambda x:x.split(' ')[0]).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.659595Z","iopub.execute_input":"2024-01-13T10:28:10.659917Z","iopub.status.idle":"2024-01-13T10:28:10.686943Z","shell.execute_reply.started":"2024-01-13T10:28:10.659888Z","shell.execute_reply":"2024-01-13T10:28:10.685577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('background',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.689759Z","iopub.execute_input":"2024-01-13T10:28:10.690306Z","iopub.status.idle":"2024-01-13T10:28:10.707977Z","shell.execute_reply.started":"2024-01-13T10:28:10.690256Z","shell.execute_reply":"2024-01-13T10:28:10.706687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['xc_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.710059Z","iopub.execute_input":"2024-01-13T10:28:10.710410Z","iopub.status.idle":"2024-01-13T10:28:10.719748Z","shell.execute_reply.started":"2024-01-13T10:28:10.710378Z","shell.execute_reply":"2024-01-13T10:28:10.718557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('xc_id',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.722076Z","iopub.execute_input":"2024-01-13T10:28:10.722572Z","iopub.status.idle":"2024-01-13T10:28:10.742266Z","shell.execute_reply.started":"2024-01-13T10:28:10.722526Z","shell.execute_reply":"2024-01-13T10:28:10.740693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['url'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.743997Z","iopub.execute_input":"2024-01-13T10:28:10.744344Z","iopub.status.idle":"2024-01-13T10:28:10.758697Z","shell.execute_reply.started":"2024-01-13T10:28:10.744314Z","shell.execute_reply":"2024-01-13T10:28:10.757133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('url',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.760403Z","iopub.execute_input":"2024-01-13T10:28:10.760904Z","iopub.status.idle":"2024-01-13T10:28:10.777479Z","shell.execute_reply.started":"2024-01-13T10:28:10.760866Z","shell.execute_reply":"2024-01-13T10:28:10.776420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['author'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.778842Z","iopub.execute_input":"2024-01-13T10:28:10.779230Z","iopub.status.idle":"2024-01-13T10:28:10.790866Z","shell.execute_reply.started":"2024-01-13T10:28:10.779196Z","shell.execute_reply":"2024-01-13T10:28:10.789422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['recordist'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.792669Z","iopub.execute_input":"2024-01-13T10:28:10.793647Z","iopub.status.idle":"2024-01-13T10:28:10.806244Z","shell.execute_reply.started":"2024-01-13T10:28:10.793600Z","shell.execute_reply":"2024-01-13T10:28:10.804906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train[Train['recordist']!=Train['author']]","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.808200Z","iopub.execute_input":"2024-01-13T10:28:10.809777Z","iopub.status.idle":"2024-01-13T10:28:10.832762Z","shell.execute_reply.started":"2024-01-13T10:28:10.809717Z","shell.execute_reply":"2024-01-13T10:28:10.831531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('author',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.834588Z","iopub.execute_input":"2024-01-13T10:28:10.835320Z","iopub.status.idle":"2024-01-13T10:28:10.850646Z","shell.execute_reply.started":"2024-01-13T10:28:10.835281Z","shell.execute_reply":"2024-01-13T10:28:10.849684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['length'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.852148Z","iopub.execute_input":"2024-01-13T10:28:10.853144Z","iopub.status.idle":"2024-01-13T10:28:10.862671Z","shell.execute_reply.started":"2024-01-13T10:28:10.853108Z","shell.execute_reply":"2024-01-13T10:28:10.861413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['min_value'] = Train['length'].str.extract(r'(\\d+)')\nTrain['min_value'] = pd.to_numeric(Train['min_value'],errors='coerce')","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.864341Z","iopub.execute_input":"2024-01-13T10:28:10.865012Z","iopub.status.idle":"2024-01-13T10:28:10.924532Z","shell.execute_reply.started":"2024-01-13T10:28:10.864973Z","shell.execute_reply":"2024-01-13T10:28:10.923273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['max_value'] = Train['length'].str.extract(r'-(\\d+)')\nTrain['max_value'] = pd.to_numeric(Train['max_value'],errors='coerce')","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.926011Z","iopub.execute_input":"2024-01-13T10:28:10.926684Z","iopub.status.idle":"2024-01-13T10:28:10.972002Z","shell.execute_reply.started":"2024-01-13T10:28:10.926643Z","shell.execute_reply":"2024-01-13T10:28:10.970774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['max_value']=Train['max_value'].fillna(3)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.977016Z","iopub.execute_input":"2024-01-13T10:28:10.977364Z","iopub.status.idle":"2024-01-13T10:28:10.984517Z","shell.execute_reply.started":"2024-01-13T10:28:10.977334Z","shell.execute_reply":"2024-01-13T10:28:10.982972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['min_value'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:10.986399Z","iopub.execute_input":"2024-01-13T10:28:10.986902Z","iopub.status.idle":"2024-01-13T10:28:10.999692Z","shell.execute_reply.started":"2024-01-13T10:28:10.986853Z","shell.execute_reply":"2024-01-13T10:28:10.998287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['min_value']=Train['min_value'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.001921Z","iopub.execute_input":"2024-01-13T10:28:11.002551Z","iopub.status.idle":"2024-01-13T10:28:11.011982Z","shell.execute_reply.started":"2024-01-13T10:28:11.002357Z","shell.execute_reply":"2024-01-13T10:28:11.010805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.013282Z","iopub.execute_input":"2024-01-13T10:28:11.014052Z","iopub.status.idle":"2024-01-13T10:28:11.082774Z","shell.execute_reply.started":"2024-01-13T10:28:11.014011Z","shell.execute_reply":"2024-01-13T10:28:11.081842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('time',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.084350Z","iopub.execute_input":"2024-01-13T10:28:11.084753Z","iopub.status.idle":"2024-01-13T10:28:11.099885Z","shell.execute_reply.started":"2024-01-13T10:28:11.084717Z","shell.execute_reply":"2024-01-13T10:28:11.098590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['license'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.101414Z","iopub.execute_input":"2024-01-13T10:28:11.101799Z","iopub.status.idle":"2024-01-13T10:28:11.115804Z","shell.execute_reply.started":"2024-01-13T10:28:11.101768Z","shell.execute_reply":"2024-01-13T10:28:11.114419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\nTrain['license_enc']=le.fit_transform(Train['license'])\nunique = Train['license_enc'].unique()\nmaping = dict(zip(Train['license'],Train['license_enc']))\n\nprint(unique)\nprint(maping)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.117389Z","iopub.execute_input":"2024-01-13T10:28:11.117790Z","iopub.status.idle":"2024-01-13T10:28:11.144651Z","shell.execute_reply.started":"2024-01-13T10:28:11.117758Z","shell.execute_reply":"2024-01-13T10:28:11.143603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.drop('license',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.146214Z","iopub.execute_input":"2024-01-13T10:28:11.146616Z","iopub.status.idle":"2024-01-13T10:28:11.163762Z","shell.execute_reply.started":"2024-01-13T10:28:11.146582Z","shell.execute_reply":"2024-01-13T10:28:11.162166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.166380Z","iopub.execute_input":"2024-01-13T10:28:11.166817Z","iopub.status.idle":"2024-01-13T10:28:11.241213Z","shell.execute_reply.started":"2024-01-13T10:28:11.166783Z","shell.execute_reply":"2024-01-13T10:28:11.239783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.242718Z","iopub.execute_input":"2024-01-13T10:28:11.243031Z","iopub.status.idle":"2024-01-13T10:28:11.289148Z","shell.execute_reply.started":"2024-01-13T10:28:11.243001Z","shell.execute_reply":"2024-01-13T10:28:11.287737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (15,6))\nsns.countplot( x='rating', data = Train, order = Train['rating'].value_counts().index)\nplt.title(\"Ratings distribution\")\nplt.xlabel(\"Ratings\")\nplt.ylabel(\"Count\")\nplt.xticks(rotation = 0)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.290780Z","iopub.execute_input":"2024-01-13T10:28:11.291155Z","iopub.status.idle":"2024-01-13T10:28:11.645758Z","shell.execute_reply.started":"2024-01-13T10:28:11.291124Z","shell.execute_reply":"2024-01-13T10:28:11.644928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nsns.countplot(x='year', data=Train)\nplt.title('Count Plot of Years')\nplt.xlabel('Year')\nplt.ylabel('Count')\nplt.xticks(rotation=90, ha='right', fontsize=12)\nplt.yticks(fontsize=12)\nplt.tight_layout()\nplt.grid(axis='y', linestyle='--', alpha=0.7)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:11.646861Z","iopub.execute_input":"2024-01-13T10:28:11.648140Z","iopub.status.idle":"2024-01-13T10:28:12.409979Z","shell.execute_reply.started":"2024-01-13T10:28:11.648073Z","shell.execute_reply":"2024-01-13T10:28:12.408458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:12.412115Z","iopub.execute_input":"2024-01-13T10:28:12.412717Z","iopub.status.idle":"2024-01-13T10:28:12.463692Z","shell.execute_reply.started":"2024-01-13T10:28:12.412650Z","shell.execute_reply":"2024-01-13T10:28:12.462152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train['country'] = Train['country'].str.strip(\"'[]\").str.replace(\"'\", \"\").str.split(\", \")\ncountries = [country for sublist in Train['country'].dropna() for country in sublist]\ncounts = pd.Series(countries).value_counts().reset_index()\ncounts.columns = ['Country', 'Count']\ncounts = counts.sort_values(by='Count', ascending=False)\nplt.figure(figsize=(30, 10))\nsns.barplot(x='Country', y='Count', data=counts.head(15))\nplt.title('Country vs count(TOP-15)')\nplt.xlabel('Country')\nplt.ylabel('Count')\nplt.xticks(rotation=0, ha='right')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:12.465330Z","iopub.execute_input":"2024-01-13T10:28:12.465702Z","iopub.status.idle":"2024-01-13T10:28:13.006967Z","shell.execute_reply.started":"2024-01-13T10:28:12.465670Z","shell.execute_reply":"2024-01-13T10:28:13.005419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 6))\nsns.countplot(x='playback_used', data=Train)\nplt.title('Playback')\nplt.xlabel('playback_enc')\nplt.ylabel('Count')\nplt.xticks(rotation=0, ha='right', fontsize=12)\nplt.yticks(fontsize=12)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:13.011495Z","iopub.execute_input":"2024-01-13T10:28:13.012646Z","iopub.status.idle":"2024-01-13T10:28:13.257866Z","shell.execute_reply.started":"2024-01-13T10:28:13.012601Z","shell.execute_reply":"2024-01-13T10:28:13.256555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cartopy.crs as ccrs\n!pip install cartopy\n","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:13.259862Z","iopub.execute_input":"2024-01-13T10:28:13.260339Z","iopub.status.idle":"2024-01-13T10:28:28.381452Z","shell.execute_reply.started":"2024-01-13T10:28:13.260302Z","shell.execute_reply":"2024-01-13T10:28:28.379635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cartopy.feature as cfeature\n\nfig, ax = plt.subplots(figsize=(10, 8), subplot_kw={'projection': ccrs.PlateCarree()})\nax.set_extent([-130, -65, 20, 50]) \nsns.scatterplot(x='longitude', y='latitude', data=Train, legend='full', s=100, ax=ax)\nax.coastlines()\nax.add_feature(cfeature.BORDERS, linestyle=':')\nax.add_feature(cfeature.LAND, edgecolor='black')\nax.set_title('Map')\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2024-01-13T10:28:28.385061Z","iopub.execute_input":"2024-01-13T10:28:28.385692Z","iopub.status.idle":"2024-01-13T10:28:28.802432Z","shell.execute_reply.started":"2024-01-13T10:28:28.385624Z","shell.execute_reply":"2024-01-13T10:28:28.801109Z"},"trusted":true},"execution_count":null,"outputs":[]}]}