{"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 seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.metrics import classification_report, accuracy_score, confusion_matrix, roc_curve, plot_roc_curve","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-07T17:09:41.443611Z","iopub.execute_input":"2023-01-07T17:09:41.444007Z","iopub.status.idle":"2023-01-07T17:09:41.450757Z","shell.execute_reply.started":"2023-01-07T17:09:41.443974Z","shell.execute_reply":"2023-01-07T17:09:41.449276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.452946Z","iopub.execute_input":"2023-01-07T17:09:41.453366Z","iopub.status.idle":"2023-01-07T17:09:41.46866Z","shell.execute_reply.started":"2023-01-07T17:09:41.453329Z","shell.execute_reply":"2023-01-07T17:09:41.467585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.470003Z","iopub.execute_input":"2023-01-07T17:09:41.470665Z","iopub.status.idle":"2023-01-07T17:09:41.483268Z","shell.execute_reply.started":"2023-01-07T17:09:41.470627Z","shell.execute_reply":"2023-01-07T17:09:41.482322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ndf_test = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.48478Z","iopub.execute_input":"2023-01-07T17:09:41.486266Z","iopub.status.idle":"2023-01-07T17:09:41.571243Z","shell.execute_reply.started":"2023-01-07T17:09:41.486209Z","shell.execute_reply":"2023-01-07T17:09:41.569792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainset_copy=df_train.copy()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.574494Z","iopub.execute_input":"2023-01-07T17:09:41.574892Z","iopub.status.idle":"2023-01-07T17:09:41.583242Z","shell.execute_reply.started":"2023-01-07T17:09:41.574858Z","shell.execute_reply":"2023-01-07T17:09:41.582028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.584375Z","iopub.execute_input":"2023-01-07T17:09:41.584718Z","iopub.status.idle":"2023-01-07T17:09:41.607672Z","shell.execute_reply.started":"2023-01-07T17:09:41.584679Z","shell.execute_reply":"2023-01-07T17:09:41.606234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.info() # gives insights such as column_label, non_null_values, column_datatypes etc..","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.609446Z","iopub.execute_input":"2023-01-07T17:09:41.609988Z","iopub.status.idle":"2023-01-07T17:09:41.637022Z","shell.execute_reply.started":"2023-01-07T17:09:41.609938Z","shell.execute_reply":"2023-01-07T17:09:41.63576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe() # computes and display the statistical summary of our data","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.640477Z","iopub.execute_input":"2023-01-07T17:09:41.64087Z","iopub.status.idle":"2023-01-07T17:09:41.699238Z","shell.execute_reply.started":"2023-01-07T17:09:41.640834Z","shell.execute_reply":"2023-01-07T17:09:41.698281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# DATA CLEANING\n","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# finding unique elements in the column 'laterality' \ndf_train['laterality'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.700648Z","iopub.execute_input":"2023-01-07T17:09:41.701161Z","iopub.status.idle":"2023-01-07T17:09:41.711097Z","shell.execute_reply.started":"2023-01-07T17:09:41.701127Z","shell.execute_reply":"2023-01-07T17:09:41.709927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# finding unique elements in the column view \ndf_train['view'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.712449Z","iopub.execute_input":"2023-01-07T17:09:41.71286Z","iopub.status.idle":"2023-01-07T17:09:41.729036Z","shell.execute_reply.started":"2023-01-07T17:09:41.712826Z","shell.execute_reply":"2023-01-07T17:09:41.727462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# finding unique elements in the column 'difficult_negative_case'\ndf_train['difficult_negative_case'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.730733Z","iopub.execute_input":"2023-01-07T17:09:41.731274Z","iopub.status.idle":"2023-01-07T17:09:41.74303Z","shell.execute_reply.started":"2023-01-07T17:09:41.731231Z","shell.execute_reply":"2023-01-07T17:09:41.741712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# finding unique elements in the column 'Survived' \ndf_train['cancer'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.744779Z","iopub.execute_input":"2023-01-07T17:09:41.745135Z","iopub.status.idle":"2023-01-07T17:09:41.757125Z","shell.execute_reply.started":"2023-01-07T17:09:41.745103Z","shell.execute_reply":"2023-01-07T17:09:41.756189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# check for duplicate entries\ndf_train.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.758424Z","iopub.execute_input":"2023-01-07T17:09:41.758836Z","iopub.status.idle":"2023-01-07T17:09:41.797404Z","shell.execute_reply.started":"2023-01-07T17:09:41.758783Z","shell.execute_reply":"2023-01-07T17:09:41.796077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X= df_train.drop('cancer', axis=1)\n# y = df['cancer']","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.802248Z","iopub.execute_input":"2023-01-07T17:09:41.802645Z","iopub.status.idle":"2023-01-07T17:09:41.807523Z","shell.execute_reply.started":"2023-01-07T17:09:41.802604Z","shell.execute_reply":"2023-01-07T17:09:41.806331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checking for total null values\ndf_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.809239Z","iopub.execute_input":"2023-01-07T17:09:41.81007Z","iopub.status.idle":"2023-01-07T17:09:41.837615Z","shell.execute_reply.started":"2023-01-07T17:09:41.810024Z","shell.execute_reply":"2023-01-07T17:09:41.836465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# drop unwanted columns\ndf_train.drop(['BIRADS','density','biopsy','invasive','difficult_negative_case'],axis=1,inplace=True)\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.838824Z","iopub.execute_input":"2023-01-07T17:09:41.839333Z","iopub.status.idle":"2023-01-07T17:09:41.857127Z","shell.execute_reply.started":"2023-01-07T17:09:41.839299Z","shell.execute_reply":"2023-01-07T17:09:41.855842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# filling missing values for the column 'Age'\ndf_train['age']=df_train['age'].fillna(value=df_train['age'].mean())","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.859086Z","iopub.execute_input":"2023-01-07T17:09:41.859498Z","iopub.status.idle":"2023-01-07T17:09:41.870319Z","shell.execute_reply.started":"2023-01-07T17:09:41.859448Z","shell.execute_reply":"2023-01-07T17:09:41.869193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.87181Z","iopub.execute_input":"2023-01-07T17:09:41.872208Z","iopub.status.idle":"2023-01-07T17:09:41.891986Z","shell.execute_reply.started":"2023-01-07T17:09:41.872173Z","shell.execute_reply":"2023-01-07T17:09:41.890627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# get_dummies is used to convert categorical data into dummy or indicator variable\nS=df_train.laterality\ndummy=pd.get_dummies(S)\ndummy.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.893656Z","iopub.execute_input":"2023-01-07T17:09:41.894293Z","iopub.status.idle":"2023-01-07T17:09:41.915624Z","shell.execute_reply.started":"2023-01-07T17:09:41.894242Z","shell.execute_reply":"2023-01-07T17:09:41.914083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train=pd.concat([dummy,df_train],axis=1)\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.917486Z","iopub.execute_input":"2023-01-07T17:09:41.91794Z","iopub.status.idle":"2023-01-07T17:09:41.940205Z","shell.execute_reply.started":"2023-01-07T17:09:41.917903Z","shell.execute_reply":"2023-01-07T17:09:41.938679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(['laterality'],axis=1,inplace=True)\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.941672Z","iopub.execute_input":"2023-01-07T17:09:41.942014Z","iopub.status.idle":"2023-01-07T17:09:41.962291Z","shell.execute_reply.started":"2023-01-07T17:09:41.941982Z","shell.execute_reply":"2023-01-07T17:09:41.960973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"E=df_train.view\ndummies=pd.get_dummies(E)\ndummies.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.964529Z","iopub.execute_input":"2023-01-07T17:09:41.965169Z","iopub.status.idle":"2023-01-07T17:09:41.985912Z","shell.execute_reply.started":"2023-01-07T17:09:41.965119Z","shell.execute_reply":"2023-01-07T17:09:41.984998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(['view'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.987151Z","iopub.execute_input":"2023-01-07T17:09:41.98835Z","iopub.status.idle":"2023-01-07T17:09:41.995573Z","shell.execute_reply.started":"2023-01-07T17:09:41.988309Z","shell.execute_reply":"2023-01-07T17:09:41.99441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train=pd.concat([dummies,df_train],axis=1)\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:41.997378Z","iopub.execute_input":"2023-01-07T17:09:41.998237Z","iopub.status.idle":"2023-01-07T17:09:42.021065Z","shell.execute_reply.started":"2023-01-07T17:09:41.998172Z","shell.execute_reply":"2023-01-07T17:09:42.019896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.022943Z","iopub.execute_input":"2023-01-07T17:09:42.023771Z","iopub.status.idle":"2023-01-07T17:09:42.102656Z","shell.execute_reply.started":"2023-01-07T17:09:42.023718Z","shell.execute_reply":"2023-01-07T17:09:42.101823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(3,3))\nsns.countplot(x='cancer',data=df_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.103928Z","iopub.execute_input":"2023-01-07T17:09:42.104459Z","iopub.status.idle":"2023-01-07T17:09:42.299301Z","shell.execute_reply.started":"2023-01-07T17:09:42.104424Z","shell.execute_reply":"2023-01-07T17:09:42.298322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=df_train.drop(['cancer'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.30077Z","iopub.execute_input":"2023-01-07T17:09:42.301978Z","iopub.status.idle":"2023-01-07T17:09:42.310897Z","shell.execute_reply.started":"2023-01-07T17:09:42.301929Z","shell.execute_reply":"2023-01-07T17:09:42.30962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train=df_train.cancer","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.312853Z","iopub.execute_input":"2023-01-07T17:09:42.31337Z","iopub.status.idle":"2023-01-07T17:09:42.321025Z","shell.execute_reply.started":"2023-01-07T17:09:42.313328Z","shell.execute_reply":"2023-01-07T17:09:42.319849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"TEST DATA ANALYSIS","metadata":{}},{"cell_type":"code","source":"df_test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.322765Z","iopub.execute_input":"2023-01-07T17:09:42.323209Z","iopub.status.idle":"2023-01-07T17:09:42.342343Z","shell.execute_reply.started":"2023-01-07T17:09:42.323164Z","shell.execute_reply":"2023-01-07T17:09:42.340945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.344162Z","iopub.execute_input":"2023-01-07T17:09:42.34467Z","iopub.status.idle":"2023-01-07T17:09:42.363133Z","shell.execute_reply.started":"2023-01-07T17:09:42.344619Z","shell.execute_reply":"2023-01-07T17:09:42.361879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checking for duplicates\ndf_test.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.364894Z","iopub.execute_input":"2023-01-07T17:09:42.365947Z","iopub.status.idle":"2023-01-07T17:09:42.378463Z","shell.execute_reply.started":"2023-01-07T17:09:42.365891Z","shell.execute_reply":"2023-01-07T17:09:42.377264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checking for null values\ndf_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.380178Z","iopub.execute_input":"2023-01-07T17:09:42.380691Z","iopub.status.idle":"2023-01-07T17:09:42.393828Z","shell.execute_reply.started":"2023-01-07T17:09:42.380655Z","shell.execute_reply":"2023-01-07T17:09:42.392815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # dropping unwanted columns\n# df_test.drop(columns=['prediction_id'],axis=1,inplace=True)\n# df_test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.395377Z","iopub.execute_input":"2023-01-07T17:09:42.395846Z","iopub.status.idle":"2023-01-07T17:09:42.40186Z","shell.execute_reply.started":"2023-01-07T17:09:42.395803Z","shell.execute_reply":"2023-01-07T17:09:42.400638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"S1=df_test.laterality\ndummy1=pd.get_dummies(S1)\ndummy1.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.40324Z","iopub.execute_input":"2023-01-07T17:09:42.404096Z","iopub.status.idle":"2023-01-07T17:09:42.420814Z","shell.execute_reply.started":"2023-01-07T17:09:42.404056Z","shell.execute_reply":"2023-01-07T17:09:42.419767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test=pd.concat([dummy1,df_test],axis=1)\ndf_test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.421913Z","iopub.execute_input":"2023-01-07T17:09:42.422272Z","iopub.status.idle":"2023-01-07T17:09:42.439072Z","shell.execute_reply.started":"2023-01-07T17:09:42.422241Z","shell.execute_reply":"2023-01-07T17:09:42.437898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.drop(['laterality'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.441005Z","iopub.execute_input":"2023-01-07T17:09:42.441441Z","iopub.status.idle":"2023-01-07T17:09:42.450442Z","shell.execute_reply.started":"2023-01-07T17:09:42.441398Z","shell.execute_reply":"2023-01-07T17:09:42.449669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"E1=df_test.view\ndummy2=pd.get_dummies(E1)\ndummy2.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.452055Z","iopub.execute_input":"2023-01-07T17:09:42.453008Z","iopub.status.idle":"2023-01-07T17:09:42.467376Z","shell.execute_reply.started":"2023-01-07T17:09:42.452957Z","shell.execute_reply":"2023-01-07T17:09:42.465926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test=pd.concat([dummy2,df_test],axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.469464Z","iopub.execute_input":"2023-01-07T17:09:42.469892Z","iopub.status.idle":"2023-01-07T17:09:42.476892Z","shell.execute_reply.started":"2023-01-07T17:09:42.46986Z","shell.execute_reply":"2023-01-07T17:09:42.47558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.drop(['view'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.478503Z","iopub.execute_input":"2023-01-07T17:09:42.479003Z","iopub.status.idle":"2023-01-07T17:09:42.488783Z","shell.execute_reply.started":"2023-01-07T17:09:42.478956Z","shell.execute_reply":"2023-01-07T17:09:42.487742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.490469Z","iopub.execute_input":"2023-01-07T17:09:42.490965Z","iopub.status.idle":"2023-01-07T17:09:42.510088Z","shell.execute_reply.started":"2023-01-07T17:09:42.490919Z","shell.execute_reply":"2023-01-07T17:09:42.509039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nfeatures=['CC','MLO', 'L', 'R', 'site_id', 'patient_id',\n       'image_id', 'age','implant', 'machine_id']\nX=pd.get_dummies(df_train[features])\ny=df_train['cancer']\n\nX_test=pd.get_dummies(df_test[features])\nmodel=RandomForestClassifier(n_estimators=100,max_depth=3,random_state=2)\nmodel.fit(X,y)\nprediction = model.predict(X_test)\nresult=pd.DataFrame({'prediction_id':df_test.prediction_id,'cancer':prediction})","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:42.51638Z","iopub.execute_input":"2023-01-07T17:09:42.516908Z","iopub.status.idle":"2023-01-07T17:09:44.897114Z","shell.execute_reply.started":"2023-01-07T17:09:42.516869Z","shell.execute_reply":"2023-01-07T17:09:44.896007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T17:09:44.898863Z","iopub.execute_input":"2023-01-07T17:09:44.899828Z","iopub.status.idle":"2023-01-07T17:09:44.907811Z","shell.execute_reply.started":"2023-01-07T17:09:44.899777Z","shell.execute_reply":"2023-01-07T17:09:44.906284Z"},"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":"","metadata":{},"execution_count":null,"outputs":[]}]}