{"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.504592Z","iopub.execute_input":"2023-02-15T19:03:34.504999Z","iopub.status.idle":"2023-02-15T19:03:34.511751Z","shell.execute_reply.started":"2023-02-15T19:03:34.504967Z","shell.execute_reply":"2023-02-15T19:03:34.510619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.513505Z","iopub.execute_input":"2023-02-15T19:03:34.513831Z","iopub.status.idle":"2023-02-15T19:03:34.57038Z","shell.execute_reply.started":"2023-02-15T19:03:34.513803Z","shell.execute_reply":"2023-02-15T19:03:34.569331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.572089Z","iopub.execute_input":"2023-02-15T19:03:34.5726Z","iopub.status.idle":"2023-02-15T19:03:34.587319Z","shell.execute_reply.started":"2023-02-15T19:03:34.572571Z","shell.execute_reply":"2023-02-15T19:03:34.586014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.588557Z","iopub.execute_input":"2023-02-15T19:03:34.588871Z","iopub.status.idle":"2023-02-15T19:03:34.595491Z","shell.execute_reply.started":"2023-02-15T19:03:34.588845Z","shell.execute_reply":"2023-02-15T19:03:34.594568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.598639Z","iopub.execute_input":"2023-02-15T19:03:34.599076Z","iopub.status.idle":"2023-02-15T19:03:34.611689Z","shell.execute_reply.started":"2023-02-15T19:03:34.599052Z","shell.execute_reply":"2023-02-15T19:03:34.610825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We could see that \"prediction_id \" column has the combination of \"patient_id \" & \"Laterality \" feature in Test dataset","metadata":{}},{"cell_type":"code","source":"print(train.shape)\nprint(test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.612932Z","iopub.execute_input":"2023-02-15T19:03:34.61375Z","iopub.status.idle":"2023-02-15T19:03:34.619252Z","shell.execute_reply.started":"2023-02-15T19:03:34.613717Z","shell.execute_reply":"2023-02-15T19:03:34.618147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"train dataset has 14 columns whereas test dataset has 9 columns","metadata":{}},{"cell_type":"code","source":"submission=pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.620688Z","iopub.execute_input":"2023-02-15T19:03:34.620988Z","iopub.status.idle":"2023-02-15T19:03:34.631281Z","shell.execute_reply.started":"2023-02-15T19:03:34.620958Z","shell.execute_reply":"2023-02-15T19:03:34.630032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.632841Z","iopub.execute_input":"2023-02-15T19:03:34.633711Z","iopub.status.idle":"2023-02-15T19:03:34.649743Z","shell.execute_reply.started":"2023-02-15T19:03:34.633599Z","shell.execute_reply":"2023-02-15T19:03:34.648796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analysis on Train dataset ","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.651217Z","iopub.execute_input":"2023-02-15T19:03:34.651703Z","iopub.status.idle":"2023-02-15T19:03:34.673964Z","shell.execute_reply.started":"2023-02-15T19:03:34.65166Z","shell.execute_reply":"2023-02-15T19:03:34.672842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train.isna(),yticklabels=False,cbar=False,cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:34.675088Z","iopub.execute_input":"2023-02-15T19:03:34.675328Z","iopub.status.idle":"2023-02-15T19:03:35.531086Z","shell.execute_reply.started":"2023-02-15T19:03:34.675306Z","shell.execute_reply":"2023-02-15T19:03:35.530102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We could see that higher proportion of null values containing in \"BIRADS\" and \"denisty\" columns, hence we delete these columns .","metadata":{}},{"cell_type":"code","source":"train.drop(['BIRADS','density'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:35.534514Z","iopub.execute_input":"2023-02-15T19:03:35.535539Z","iopub.status.idle":"2023-02-15T19:03:35.543527Z","shell.execute_reply.started":"2023-02-15T19:03:35.535488Z","shell.execute_reply":"2023-02-15T19:03:35.542384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train.isna())","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:35.544832Z","iopub.execute_input":"2023-02-15T19:03:35.545148Z","iopub.status.idle":"2023-02-15T19:03:36.741245Z","shell.execute_reply.started":"2023-02-15T19:03:35.545124Z","shell.execute_reply":"2023-02-15T19:03:36.740301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.select_dtypes(include='object')","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:36.742341Z","iopub.execute_input":"2023-02-15T19:03:36.743198Z","iopub.status.idle":"2023-02-15T19:03:36.758562Z","shell.execute_reply.started":"2023-02-15T19:03:36.743172Z","shell.execute_reply":"2023-02-15T19:03:36.756624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['view'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:36.760244Z","iopub.execute_input":"2023-02-15T19:03:36.760858Z","iopub.status.idle":"2023-02-15T19:03:36.774141Z","shell.execute_reply.started":"2023-02-15T19:03:36.760822Z","shell.execute_reply":"2023-02-15T19:03:36.772915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Explorative Data Anlysis","metadata":{}},{"cell_type":"code","source":"sns.countplot(x='laterality',data=train,hue='cancer')","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:36.775926Z","iopub.execute_input":"2023-02-15T19:03:36.778339Z","iopub.status.idle":"2023-02-15T19:03:36.978503Z","shell.execute_reply.started":"2023-02-15T19:03:36.778282Z","shell.execute_reply":"2023-02-15T19:03:36.977572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Dataset contains equal count for Left and Rigt Laterality . It is observed the count of having malignant cancer is lesser ","metadata":{}},{"cell_type":"code","source":"malignant=train.loc[train['cancer']==1]","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:36.979746Z","iopub.execute_input":"2023-02-15T19:03:36.980825Z","iopub.status.idle":"2023-02-15T19:03:36.987473Z","shell.execute_reply.started":"2023-02-15T19:03:36.980789Z","shell.execute_reply":"2023-02-15T19:03:36.986112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(malignant['age'],bins=20)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:04:33.480989Z","iopub.execute_input":"2023-02-15T19:04:33.481464Z","iopub.status.idle":"2023-02-15T19:04:33.689293Z","shell.execute_reply.started":"2023-02-15T19:04:33.481431Z","shell.execute_reply":"2023-02-15T19:04:33.688368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We could see that people who are having malignant cancer of the age between 60 to 75","metadata":{}},{"cell_type":"code","source":"sns.histplot(train['age'],bins=20)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:04:41.964046Z","iopub.execute_input":"2023-02-15T19:04:41.964396Z","iopub.status.idle":"2023-02-15T19:04:42.20487Z","shell.execute_reply.started":"2023-02-15T19:04:41.964369Z","shell.execute_reply":"2023-02-15T19:04:42.20371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Age distribution on entire dataset having cancer 1 or 0 . age distributed  50 to 70","metadata":{}},{"cell_type":"code","source":"sns.boxplot(train['age'])","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:37.592962Z","iopub.execute_input":"2023-02-15T19:03:37.593292Z","iopub.status.idle":"2023-02-15T19:03:37.717575Z","shell.execute_reply.started":"2023-02-15T19:03:37.593259Z","shell.execute_reply":"2023-02-15T19:03:37.716654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['age'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:37.718719Z","iopub.execute_input":"2023-02-15T19:03:37.719002Z","iopub.status.idle":"2023-02-15T19:03:37.725909Z","shell.execute_reply.started":"2023-02-15T19:03:37.718974Z","shell.execute_reply":"2023-02-15T19:03:37.725185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#lets fill the null value present in 'age 'column with mean value.\ntrain['age']=train['age'].fillna(train['age'].mean())","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:37.72689Z","iopub.execute_input":"2023-02-15T19:03:37.72746Z","iopub.status.idle":"2023-02-15T19:03:37.734157Z","shell.execute_reply.started":"2023-02-15T19:03:37.727431Z","shell.execute_reply":"2023-02-15T19:03:37.733398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"axes=sns.countplot(train['cancer'])\naxes.bar_label(axes.containers[0])\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:37.735149Z","iopub.execute_input":"2023-02-15T19:03:37.735915Z","iopub.status.idle":"2023-02-15T19:03:37.83936Z","shell.execute_reply.started":"2023-02-15T19:03:37.735885Z","shell.execute_reply":"2023-02-15T19:03:37.838623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Higest count contributing here is people having no malignant .","metadata":{}},{"cell_type":"code","source":"print(train.shape)\nprint(test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:37.840405Z","iopub.execute_input":"2023-02-15T19:03:37.841231Z","iopub.status.idle":"2023-02-15T19:03:37.845771Z","shell.execute_reply.started":"2023-02-15T19:03:37.841201Z","shell.execute_reply":"2023-02-15T19:03:37.845021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax=sns.countplot(x='implant',data=train,hue='cancer')\nax.bar_label(ax.containers[0])\nax.bar_label(ax.containers[1])","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:37.846816Z","iopub.execute_input":"2023-02-15T19:03:37.847781Z","iopub.status.idle":"2023-02-15T19:03:38.03516Z","shell.execute_reply.started":"2023-02-15T19:03:37.847749Z","shell.execute_reply":"2023-02-15T19:03:38.034156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we could infer from the graph that majority of the patient who are having the malignant cancer , have not done the implant ","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(data=train, x='implant')\nax.bar_label(ax.containers[0])","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:38.036477Z","iopub.execute_input":"2023-02-15T19:03:38.036777Z","iopub.status.idle":"2023-02-15T19:03:38.174031Z","shell.execute_reply.started":"2023-02-15T19:03:38.036752Z","shell.execute_reply":"2023-02-15T19:03:38.173134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sns.countplot(train.groupby('patient_id').image_id.count())","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:38.175207Z","iopub.execute_input":"2023-02-15T19:03:38.175501Z","iopub.status.idle":"2023-02-15T19:03:38.179439Z","shell.execute_reply.started":"2023-02-15T19:03:38.175473Z","shell.execute_reply":"2023-02-15T19:03:38.178408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['image_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:38.180536Z","iopub.execute_input":"2023-02-15T19:03:38.180824Z","iopub.status.idle":"2023-02-15T19:03:38.195144Z","shell.execute_reply.started":"2023-02-15T19:03:38.180797Z","shell.execute_reply":"2023-02-15T19:03:38.194175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax=sns.countplot(data=train,x='invasive',hue='cancer')\nax.bar_label(ax.containers[0])\nax.bar_label(ax.containers[1])","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:38.200765Z","iopub.execute_input":"2023-02-15T19:03:38.20107Z","iopub.status.idle":"2023-02-15T19:03:38.385685Z","shell.execute_reply.started":"2023-02-15T19:03:38.201046Z","shell.execute_reply":"2023-02-15T19:03:38.384678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Wherever the breast is positive for Cancer , then  the mjority are having malignant cancer . also where there is breast negative for cancer then also we can see few contribution towards ,malignant cancer.\n\nMain point here is where the breast showed up negative for Cancer (invasive is Zero)then they are not having the Malignant Cancer ","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(20, 12))\nsns.heatmap(train.corr(),annot=True)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:38.386942Z","iopub.execute_input":"2023-02-15T19:03:38.387202Z","iopub.status.idle":"2023-02-15T19:03:39.083818Z","shell.execute_reply.started":"2023-02-15T19:03:38.387178Z","shell.execute_reply":"2023-02-15T19:03:39.082522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We could see that from correlation graph is there a higher correlation between \"Cancer\" & \"Biopsy \"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.violinplot(x=\"cancer\", y=\"age\", data=train)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.085281Z","iopub.execute_input":"2023-02-15T19:03:39.085533Z","iopub.status.idle":"2023-02-15T19:03:39.354328Z","shell.execute_reply.started":"2023-02-15T19:03:39.08551Z","shell.execute_reply":"2023-02-15T19:03:39.35339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='machine_id',data=train,hue='cancer')","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.355874Z","iopub.execute_input":"2023-02-15T19:03:39.356214Z","iopub.status.idle":"2023-02-15T19:03:39.594896Z","shell.execute_reply.started":"2023-02-15T19:03:39.356172Z","shell.execute_reply":"2023-02-15T19:03:39.593897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Machine ID 49 shown more result for Malignant Cancer ","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.596144Z","iopub.execute_input":"2023-02-15T19:03:39.597214Z","iopub.status.idle":"2023-02-15T19:03:39.616568Z","shell.execute_reply.started":"2023-02-15T19:03:39.597174Z","shell.execute_reply":"2023-02-15T19:03:39.615395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Coverting Categorical Data to Numerics","metadata":{}},{"cell_type":"code","source":"train['laterality_left']=pd.get_dummies(train['laterality'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.618058Z","iopub.execute_input":"2023-02-15T19:03:39.618401Z","iopub.status.idle":"2023-02-15T19:03:39.628888Z","shell.execute_reply.started":"2023-02-15T19:03:39.618369Z","shell.execute_reply":"2023-02-15T19:03:39.627559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['laterality_left']","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.630456Z","iopub.execute_input":"2023-02-15T19:03:39.63135Z","iopub.status.idle":"2023-02-15T19:03:39.63885Z","shell.execute_reply.started":"2023-02-15T19:03:39.631322Z","shell.execute_reply":"2023-02-15T19:03:39.637876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.63992Z","iopub.execute_input":"2023-02-15T19:03:39.640816Z","iopub.status.idle":"2023-02-15T19:03:39.657542Z","shell.execute_reply.started":"2023-02-15T19:03:39.640788Z","shell.execute_reply":"2023-02-15T19:03:39.656524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('laterality',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.658945Z","iopub.execute_input":"2023-02-15T19:03:39.659254Z","iopub.status.idle":"2023-02-15T19:03:39.668606Z","shell.execute_reply.started":"2023-02-15T19:03:39.659232Z","shell.execute_reply":"2023-02-15T19:03:39.667322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.66998Z","iopub.execute_input":"2023-02-15T19:03:39.670321Z","iopub.status.idle":"2023-02-15T19:03:39.689702Z","shell.execute_reply.started":"2023-02-15T19:03:39.670292Z","shell.execute_reply":"2023-02-15T19:03:39.688535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see , we have only two categorical column left .Lets covert this to numerical by using another technique called Label Encoder","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\n","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.691169Z","iopub.execute_input":"2023-02-15T19:03:39.691419Z","iopub.status.idle":"2023-02-15T19:03:39.698569Z","shell.execute_reply.started":"2023-02-15T19:03:39.691395Z","shell.execute_reply":"2023-02-15T19:03:39.697327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le=LabelEncoder()\ncol_list=['view','difficult_negative_case']\nfor col in col_list:\n    train[col]=le.fit_transform(train[col])\n\n","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.7001Z","iopub.execute_input":"2023-02-15T19:03:39.700422Z","iopub.status.idle":"2023-02-15T19:03:39.722921Z","shell.execute_reply.started":"2023-02-15T19:03:39.70039Z","shell.execute_reply":"2023-02-15T19:03:39.721817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.724254Z","iopub.execute_input":"2023-02-15T19:03:39.72455Z","iopub.status.idle":"2023-02-15T19:03:39.741359Z","shell.execute_reply.started":"2023-02-15T19:03:39.724525Z","shell.execute_reply":"2023-02-15T19:03:39.740398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#lets check if we have any other null values beforw we proceed with Training ","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.742399Z","iopub.execute_input":"2023-02-15T19:03:39.742846Z","iopub.status.idle":"2023-02-15T19:03:39.746807Z","shell.execute_reply.started":"2023-02-15T19:03:39.742822Z","shell.execute_reply":"2023-02-15T19:03:39.745734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.748329Z","iopub.execute_input":"2023-02-15T19:03:39.748908Z","iopub.status.idle":"2023-02-15T19:03:39.76456Z","shell.execute_reply.started":"2023-02-15T19:03:39.748872Z","shell.execute_reply":"2023-02-15T19:03:39.763334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Model Building and Prediction","metadata":{}},{"cell_type":"code","source":"x=train.drop('cancer',axis=1)\ny=train['cancer']","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.765624Z","iopub.execute_input":"2023-02-15T19:03:39.76597Z","iopub.status.idle":"2023-02-15T19:03:39.773645Z","shell.execute_reply.started":"2023-02-15T19:03:39.765944Z","shell.execute_reply":"2023-02-15T19:03:39.772551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.775202Z","iopub.execute_input":"2023-02-15T19:03:39.775529Z","iopub.status.idle":"2023-02-15T19:03:39.783691Z","shell.execute_reply.started":"2023-02-15T19:03:39.775498Z","shell.execute_reply":"2023-02-15T19:03:39.782556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split( x, y, test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.78522Z","iopub.execute_input":"2023-02-15T19:03:39.785536Z","iopub.status.idle":"2023-02-15T19:03:39.80102Z","shell.execute_reply.started":"2023-02-15T19:03:39.785505Z","shell.execute_reply":"2023-02-15T19:03:39.79998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.802244Z","iopub.execute_input":"2023-02-15T19:03:39.80336Z","iopub.status.idle":"2023-02-15T19:03:39.807966Z","shell.execute_reply.started":"2023-02-15T19:03:39.80332Z","shell.execute_reply":"2023-02-15T19:03:39.80703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random=RandomForestClassifier(n_estimators=200)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.809151Z","iopub.execute_input":"2023-02-15T19:03:39.810331Z","iopub.status.idle":"2023-02-15T19:03:39.819243Z","shell.execute_reply.started":"2023-02-15T19:03:39.81028Z","shell.execute_reply":"2023-02-15T19:03:39.818237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:39.820501Z","iopub.execute_input":"2023-02-15T19:03:39.820813Z","iopub.status.idle":"2023-02-15T19:03:43.381158Z","shell.execute_reply.started":"2023-02-15T19:03:39.820787Z","shell.execute_reply":"2023-02-15T19:03:43.3803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=random.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.382176Z","iopub.execute_input":"2023-02-15T19:03:43.382426Z","iopub.status.idle":"2023-02-15T19:03:43.51091Z","shell.execute_reply.started":"2023-02-15T19:03:43.382403Z","shell.execute_reply":"2023-02-15T19:03:43.509941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.514428Z","iopub.execute_input":"2023-02-15T19:03:43.515562Z","iopub.status.idle":"2023-02-15T19:03:43.521701Z","shell.execute_reply.started":"2023-02-15T19:03:43.515522Z","shell.execute_reply":"2023-02-15T19:03:43.520707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report,confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.523002Z","iopub.execute_input":"2023-02-15T19:03:43.523359Z","iopub.status.idle":"2023-02-15T19:03:43.533623Z","shell.execute_reply.started":"2023-02-15T19:03:43.523309Z","shell.execute_reply":"2023-02-15T19:03:43.532442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(pred,y_test))\nprint('\\n')\nprint(confusion_matrix(pred,y_test))","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.535032Z","iopub.execute_input":"2023-02-15T19:03:43.535382Z","iopub.status.idle":"2023-02-15T19:03:43.557935Z","shell.execute_reply.started":"2023-02-15T19:03:43.53535Z","shell.execute_reply":"2023-02-15T19:03:43.557029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.559403Z","iopub.execute_input":"2023-02-15T19:03:43.559718Z","iopub.status.idle":"2023-02-15T19:03:43.568611Z","shell.execute_reply.started":"2023-02-15T19:03:43.559686Z","shell.execute_reply":"2023-02-15T19:03:43.567606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.569774Z","iopub.execute_input":"2023-02-15T19:03:43.570227Z","iopub.status.idle":"2023-02-15T19:03:43.578962Z","shell.execute_reply.started":"2023-02-15T19:03:43.570201Z","shell.execute_reply":"2023-02-15T19:03:43.578087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['cancer'] = pred[:len(test)]\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.579966Z","iopub.execute_input":"2023-02-15T19:03:43.580545Z","iopub.status.idle":"2023-02-15T19:03:43.596277Z","shell.execute_reply.started":"2023-02-15T19:03:43.580514Z","shell.execute_reply":"2023-02-15T19:03:43.595643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = test.groupby('prediction_id')['cancer'].max().to_frame().reset_index()\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.59705Z","iopub.execute_input":"2023-02-15T19:03:43.597311Z","iopub.status.idle":"2023-02-15T19:03:43.609007Z","shell.execute_reply.started":"2023-02-15T19:03:43.597288Z","shell.execute_reply":"2023-02-15T19:03:43.608159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv(\"submission.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2023-02-15T19:03:43.610043Z","iopub.execute_input":"2023-02-15T19:03:43.610362Z","iopub.status.idle":"2023-02-15T19:03:43.620752Z","shell.execute_reply.started":"2023-02-15T19:03:43.61033Z","shell.execute_reply":"2023-02-15T19:03:43.619708Z"},"trusted":true},"execution_count":null,"outputs":[]}]}