{"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\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":"2022-07-25T11:40:12.891158Z","iopub.execute_input":"2022-07-25T11:40:12.891661Z","iopub.status.idle":"2022-07-25T11:40:12.903322Z","shell.execute_reply.started":"2022-07-25T11:40:12.891608Z","shell.execute_reply":"2022-07-25T11:40:12.901739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')\n\npd.set_option('display.max_columns',None)\n\nimport seaborn as sns\n\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nfrom sklearn.feature_selection import SelectKBest\nfrom sklearn.feature_selection import chi2\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix, classification_report\n\n\nimport tensorflow as tf\n\nfrom lightgbm import LGBMClassifier\nfrom catboost import CatBoostClassifier\n\nfrom sklearn.tree import DecisionTreeClassifier\n\nfrom sklearn.model_selection import KFold\nfrom sklearn.model_selection import cross_val_score\n\nfrom sklearn.ensemble import VotingClassifier\n\nfrom sklearn.metrics import accuracy_score\n","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:22:57.263532Z","iopub.execute_input":"2022-07-25T11:22:57.264267Z","iopub.status.idle":"2022-07-25T11:22:57.276034Z","shell.execute_reply.started":"2022-07-25T11:22:57.264221Z","shell.execute_reply":"2022-07-25T11:22:57.274709Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data1=pd.read_csv('../input/sera-venenoso/train.csv')\ntest_data1=pd.read_csv('../input/sera-venenoso/test.csv')\ntemp_sub=pd.read_csv('../input/sera-venenoso/sample_submission.csv')\ntest_data1.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:55:50.768839Z","iopub.execute_input":"2022-07-25T11:55:50.769248Z","iopub.status.idle":"2022-07-25T11:55:50.837348Z","shell.execute_reply.started":"2022-07-25T11:55:50.769212Z","shell.execute_reply":"2022-07-25T11:55:50.836019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data1.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:53:20.681474Z","iopub.execute_input":"2022-07-25T11:53:20.682871Z","iopub.status.idle":"2022-07-25T11:53:20.690412Z","shell.execute_reply.started":"2022-07-25T11:53:20.682824Z","shell.execute_reply":"2022-07-25T11:53:20.689147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"whole_data_set=pd.concat([train_data1, test_data1],axis=0)\ndata_prep1=whole_data_set.copy()\n# data_prep1=train_data1.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:53:24.963255Z","iopub.execute_input":"2022-07-25T11:53:24.963709Z","iopub.status.idle":"2022-07-25T11:53:24.978284Z","shell.execute_reply.started":"2022-07-25T11:53:24.963673Z","shell.execute_reply":"2022-07-25T11:53:24.976952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## DATA ANALYSIS","metadata":{"execution":{"iopub.status.busy":"2022-07-25T06:44:30.545520Z","iopub.execute_input":"2022-07-25T06:44:30.545899Z","iopub.status.idle":"2022-07-25T06:44:30.551329Z","shell.execute_reply.started":"2022-07-25T06:44:30.545868Z","shell.execute_reply":"2022-07-25T06:44:30.549989Z"}}},{"cell_type":"code","source":"# data_prep1=data_prep1.sort_values(by=['id'],ascending=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:30:09.374971Z","iopub.execute_input":"2022-07-25T11:30:09.375401Z","iopub.status.idle":"2022-07-25T11:30:09.385672Z","shell.execute_reply.started":"2022-07-25T11:30:09.375365Z","shell.execute_reply":"2022-07-25T11:30:09.384541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep1.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:53:31.479260Z","iopub.execute_input":"2022-07-25T11:53:31.479682Z","iopub.status.idle":"2022-07-25T11:53:31.487311Z","shell.execute_reply.started":"2022-07-25T11:53:31.479623Z","shell.execute_reply":"2022-07-25T11:53:31.486023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep1.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:53:33.543822Z","iopub.execute_input":"2022-07-25T11:53:33.544208Z","iopub.status.idle":"2022-07-25T11:53:33.567382Z","shell.execute_reply.started":"2022-07-25T11:53:33.544176Z","shell.execute_reply":"2022-07-25T11:53:33.566185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep1.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:53:36.084837Z","iopub.execute_input":"2022-07-25T11:53:36.085429Z","iopub.status.idle":"2022-07-25T11:53:36.106500Z","shell.execute_reply.started":"2022-07-25T11:53:36.085393Z","shell.execute_reply":"2022-07-25T11:53:36.105690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep1.isna().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:53:37.600411Z","iopub.execute_input":"2022-07-25T11:53:37.601024Z","iopub.status.idle":"2022-07-25T11:53:37.627002Z","shell.execute_reply.started":"2022-07-25T11:53:37.600971Z","shell.execute_reply":"2022-07-25T11:53:37.625728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep1_index=data_prep1.iloc[:,0]\ndata_prep1_index.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:29.462660Z","iopub.execute_input":"2022-07-25T11:54:29.463074Z","iopub.status.idle":"2022-07-25T11:54:29.472139Z","shell.execute_reply.started":"2022-07-25T11:54:29.463043Z","shell.execute_reply":"2022-07-25T11:54:29.470708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"execution":{"iopub.status.busy":"2022-07-25T09:00:19.145303Z","iopub.execute_input":"2022-07-25T09:00:19.145689Z","iopub.status.idle":"2022-07-25T09:00:19.152564Z","shell.execute_reply.started":"2022-07-25T09:00:19.145658Z","shell.execute_reply":"2022-07-25T09:00:19.151449Z"}}},{"cell_type":"code","source":"data_prep2=data_prep1.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:31.718942Z","iopub.execute_input":"2022-07-25T11:54:31.719383Z","iopub.status.idle":"2022-07-25T11:54:31.726418Z","shell.execute_reply.started":"2022-07-25T11:54:31.719347Z","shell.execute_reply":"2022-07-25T11:54:31.725133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"for i in data_prep2.columns:\n    if i!='id':\n        print('{}'.format(data_prep2[i].value_counts()))\n        print()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:33.581094Z","iopub.execute_input":"2022-07-25T11:54:33.581528Z","iopub.status.idle":"2022-07-25T11:54:33.622111Z","shell.execute_reply.started":"2022-07-25T11:54:33.581492Z","shell.execute_reply":"2022-07-25T11:54:33.620661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep2.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:40:35.783585Z","iopub.execute_input":"2022-07-25T11:40:35.784042Z","iopub.status.idle":"2022-07-25T11:40:35.790475Z","shell.execute_reply.started":"2022-07-25T11:40:35.784007Z","shell.execute_reply":"2022-07-25T11:40:35.789396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def clean_data(df):\n    df2=df.copy()\n    index_to_drop=[]\n    [index_to_drop.append(x) for x in df2[df2['cap-surface']=='Grooves'].index.values.tolist()]\n    [index_to_drop.append(x) for x in df2.loc[(df2['cap-shape']=='c') | (df2['cap-shape']=='Sunken')].index.values.tolist()]\n    [index_to_drop.append(x) for x in df2.loc[(df2['cap-color']=='Cinnamon') | (df2['cap-shape']=='Purple')].index.values.tolist()]\n    [index_to_drop.append(x) for x in df2[df2['odor']=='Musty'].index.values.tolist()]\n    [index_to_drop.append(x) for x in df2[df2['stalk-color-above-ring']=='Yellow'].index.values.tolist()]\n    [index_to_drop.append(x) for x in df2[df2['veil-color']=='Yellow'].index.values.tolist()]\n    return index_to_drop","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:40:00.758731Z","iopub.execute_input":"2022-07-25T11:40:00.759193Z","iopub.status.idle":"2022-07-25T11:40:00.769201Z","shell.execute_reply.started":"2022-07-25T11:40:00.759161Z","shell.execute_reply":"2022-07-25T11:40:00.768304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep3=data_prep2.copy()\n# data_prep3.drop(clean_data(data_prep2),axis=0,inplace=True)\ndata_prep3.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:38.692183Z","iopub.execute_input":"2022-07-25T11:54:38.693303Z","iopub.status.idle":"2022-07-25T11:54:38.701164Z","shell.execute_reply.started":"2022-07-25T11:54:38.693259Z","shell.execute_reply":"2022-07-25T11:54:38.700064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep3.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:40.276112Z","iopub.execute_input":"2022-07-25T11:54:40.276543Z","iopub.status.idle":"2022-07-25T11:54:40.304935Z","shell.execute_reply.started":"2022-07-25T11:54:40.276510Z","shell.execute_reply":"2022-07-25T11:54:40.303399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in data_prep3.columns:\n    if i!='id':\n        data_prep3=pd.concat([pd.get_dummies(data_prep3[i],prefix=i+\" \"),data_prep3],axis=1)\n    if i != 'class' and i!='id':\n        data_prep3.drop(i,axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:45.703588Z","iopub.execute_input":"2022-07-25T11:54:45.704007Z","iopub.status.idle":"2022-07-25T11:54:45.802954Z","shell.execute_reply.started":"2022-07-25T11:54:45.703975Z","shell.execute_reply":"2022-07-25T11:54:45.801605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in data_prep3.columns:\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:48.395788Z","iopub.execute_input":"2022-07-25T11:54:48.396238Z","iopub.status.idle":"2022-07-25T11:54:48.403343Z","shell.execute_reply.started":"2022-07-25T11:54:48.396201Z","shell.execute_reply":"2022-07-25T11:54:48.402332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep4=data_prep3.copy()\ndata_prep4.drop(['class _Poisonous','bruises _Bruises','gill-attachment _Attached','gill-spacing _Crowded','gill-size _Narrow','stalk-shape _Enlarging','class _Edible','veil-type _Partial'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:52.738441Z","iopub.execute_input":"2022-07-25T11:54:52.739435Z","iopub.status.idle":"2022-07-25T11:54:52.747497Z","shell.execute_reply.started":"2022-07-25T11:54:52.739385Z","shell.execute_reply":"2022-07-25T11:54:52.746113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep4.replace({'Edible':0,'Poisonous':1},inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:55.857667Z","iopub.execute_input":"2022-07-25T11:54:55.858099Z","iopub.status.idle":"2022-07-25T11:54:55.869029Z","shell.execute_reply.started":"2022-07-25T11:54:55.858062Z","shell.execute_reply":"2022-07-25T11:54:55.867843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep4.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:59.144949Z","iopub.execute_input":"2022-07-25T11:54:59.145341Z","iopub.status.idle":"2022-07-25T11:54:59.192188Z","shell.execute_reply.started":"2022-07-25T11:54:59.145309Z","shell.execute_reply":"2022-07-25T11:54:59.190745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30,20))\nsns.heatmap(data_prep4.drop('id',axis=1).corr())","metadata":{"execution":{"iopub.status.busy":"2022-07-25T10:09:45.873335Z","iopub.execute_input":"2022-07-25T10:09:45.873774Z","iopub.status.idle":"2022-07-25T10:09:49.852431Z","shell.execute_reply.started":"2022-07-25T10:09:45.873739Z","shell.execute_reply":"2022-07-25T10:09:49.851542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_prep4.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:41:26.503821Z","iopub.execute_input":"2022-07-25T11:41:26.504256Z","iopub.status.idle":"2022-07-25T11:41:26.512912Z","shell.execute_reply.started":"2022-07-25T11:41:26.504220Z","shell.execute_reply":"2022-07-25T11:41:26.511196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_new_data=data_prep4.iloc[0:4599,0:]\ntest_new_data=data_prep4.iloc[4599:,0:]\ntrain_new_data.tail()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:58:28.254317Z","iopub.execute_input":"2022-07-25T11:58:28.254869Z","iopub.status.idle":"2022-07-25T11:58:28.314625Z","shell.execute_reply.started":"2022-07-25T11:58:28.254829Z","shell.execute_reply":"2022-07-25T11:58:28.313175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_new_data_x=train_new_data.drop(['class','id'],axis=1)\ntrain_new_data_y=train_new_data['class']","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:58:12.495996Z","iopub.execute_input":"2022-07-25T11:58:12.496558Z","iopub.status.idle":"2022-07-25T11:58:12.504750Z","shell.execute_reply.started":"2022-07-25T11:58:12.496517Z","shell.execute_reply":"2022-07-25T11:58:12.503763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_features = SelectKBest(chi2, k=2).fit(train_new_data_x, train_new_data_y)\nbest_features.scores_\ndfscores = pd.DataFrame(best_features.scores_)\ndfcolumns = pd.DataFrame(train_new_data_x.columns)\nimp_cols=pd.concat([dfscores,dfcolumns],axis=1)\nimp_cols.columns = ['Score','Specs'] \nimp_cols.nlargest(100,'Score')","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:58:38.663942Z","iopub.execute_input":"2022-07-25T11:58:38.664341Z","iopub.status.idle":"2022-07-25T11:58:38.701254Z","shell.execute_reply.started":"2022-07-25T11:58:38.664310Z","shell.execute_reply":"2022-07-25T11:58:38.698278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test =train_test_split(train_new_data_x,train_new_data_y,train_size=0.7, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:58:56.021243Z","iopub.execute_input":"2022-07-25T11:58:56.021651Z","iopub.status.idle":"2022-07-25T11:58:56.032966Z","shell.execute_reply.started":"2022-07-25T11:58:56.021605Z","shell.execute_reply":"2022-07-25T11:58:56.031864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:58:57.707205Z","iopub.execute_input":"2022-07-25T11:58:57.707599Z","iopub.status.idle":"2022-07-25T11:58:57.716149Z","shell.execute_reply.started":"2022-07-25T11:58:57.707570Z","shell.execute_reply":"2022-07-25T11:58:57.714845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtc=DecisionTreeClassifier()\ndtc.fit(X_train, y_train)\ndtcp=dtc.predict(X_test)\nprint(accuracy_score(dtcp,y_test))\n\ncb=CatBoostClassifier(verbose=0)\ncb.fit(X_train, y_train)\nm=cb.predict(X_test)\nprint(accuracy_score(m,y_test))\n\nlg=LGBMClassifier()\nlg.fit(X_train, y_train)\nll=lg.predict(X_test)\nprint(accuracy_score(ll,y_test))\n\nfrom sklearn.ensemble import RandomForestClassifier\nclf = RandomForestClassifier(max_depth=10, random_state=0)\nclf.fit(X_train,y_train)\nds=clf.predict(X_test)\nprint(accuracy_score(ds,y_test))\n","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:59:08.268171Z","iopub.execute_input":"2022-07-25T11:59:08.268586Z","iopub.status.idle":"2022-07-25T11:59:10.726624Z","shell.execute_reply.started":"2022-07-25T11:59:08.268556Z","shell.execute_reply":"2022-07-25T11:59:10.725739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_new_data_x=test_new_data.drop(['class','id'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:59:17.092037Z","iopub.execute_input":"2022-07-25T11:59:17.093382Z","iopub.status.idle":"2022-07-25T11:59:17.101221Z","shell.execute_reply.started":"2022-07-25T11:59:17.093330Z","shell.execute_reply":"2022-07-25T11:59:17.099734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dsa=clf.predict(test_new_data_x)\nlen(dsa)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:00:30.829557Z","iopub.execute_input":"2022-07-25T12:00:30.830008Z","iopub.status.idle":"2022-07-25T12:00:30.872444Z","shell.execute_reply.started":"2022-07-25T12:00:30.829971Z","shell.execute_reply":"2022-07-25T12:00:30.871588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:00:39.459561Z","iopub.execute_input":"2022-07-25T12:00:39.460038Z","iopub.status.idle":"2022-07-25T12:00:39.471413Z","shell.execute_reply.started":"2022-07-25T12:00:39.460000Z","shell.execute_reply":"2022-07-25T12:00:39.469878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_sub['class']=dsa\ntemp_sub['class'] = np.where(temp_sub['class']==0,  'Edible','Poisonous')","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:01:32.686547Z","iopub.execute_input":"2022-07-25T12:01:32.687377Z","iopub.status.idle":"2022-07-25T12:01:32.697502Z","shell.execute_reply.started":"2022-07-25T12:01:32.687333Z","shell.execute_reply":"2022-07-25T12:01:32.695343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_sub","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:01:33.977514Z","iopub.execute_input":"2022-07-25T12:01:33.978495Z","iopub.status.idle":"2022-07-25T12:01:34.078388Z","shell.execute_reply.started":"2022-07-25T12:01:33.978452Z","shell.execute_reply":"2022-07-25T12:01:34.077219Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_sub.to_csv(\"submission_be.csv\",index=False)\nprint('Submission file shape is', temp_sub.shape )","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:01:53.992559Z","iopub.execute_input":"2022-07-25T12:01:53.993306Z","iopub.status.idle":"2022-07-25T12:01:54.005920Z","shell.execute_reply.started":"2022-07-25T12:01:53.993262Z","shell.execute_reply":"2022-07-25T12:01:54.004664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}