{"cells":[{"metadata":{},"cell_type":"markdown","source":"## This notebook aims at some of basic preprocessing steps of tabular data available with this competition.","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":false},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport os\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"sns.set(style='darkgrid')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv('../input/siim-isic-melanoma-classification/train.csv')\ntest = pd.read_csv('../input/siim-isic-melanoma-classification/test.csv')\nsample = pd.read_csv('../input/siim-isic-melanoma-classification/sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Filling unknown values with relevant data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train['sex'].fillna('unknown', inplace=True)\ntest['sex'].fillna('unknown', inplace=True)\n\ntrain['age_approx'].fillna(train['age_approx'].mode().values[0], inplace=True)\ntest['age_approx'].fillna(test['age_approx'].mode().values[0], inplace=True)\n\ntrain['anatom_site_general_challenge'].fillna('unknown', inplace=True)\ntest['anatom_site_general_challenge'].fillna('unknown', inplace=True)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Label Encoding categorical values","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nenc = LabelEncoder()\n\ntrain['sex_enc'] = enc.fit_transform(train.sex.astype('str'))\ntest['sex_enc'] = enc.transform(test.sex.astype('str'))\n\ntrain['age_enc'] = enc.fit_transform(train.age_approx.astype('str'))\ntest['age_enc'] = enc.transform(test.age_approx.astype('str'))\n\ntrain['anatom_enc'] = enc.fit_transform(train.anatom_site_general_challenge.astype('str'))\ntest['anatom_enc'] = enc.transform(test.anatom_site_general_challenge.astype('str'))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head(5)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Mean Normalization","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train['age_enc'] = train['age_enc'] / np.mean(train['age_enc'])\ntest['age_enc'] = test['age_enc'] / np.mean(test['age_enc'])\n\ntrain['anatom_enc'] = train['anatom_enc'] / np.mean(train['anatom_enc'])\ntest['anatom_enc'] = test['anatom_enc'] / np.mean(test['anatom_enc'])\n\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Building our XGBoost Regression model","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nfrom sklearn.model_selection import StratifiedKFold\nfrom xgboost import XGBClassifier, XGBRegressor\nfrom sklearn.metrics import roc_auc_score\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.columns","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Selecting only relevant feature columns from tabular data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"features = [\n            'sex_enc',\n            'age_enc',\n            'anatom_enc'\n]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X = train[features]\ny = train['target']\n\nx_test = test[features]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = XGBRegressor(base_score=0.5, booster=None, colsample_bylevel=1,\n                    importance_type='gain', interaction_constraints=None,\n                     min_child_weight=1, missing=None, monotone_constraints=None,\n                     n_estimators=700, n_jobs=-1, nthread=-1, num_parallel_tree=1\n                    )\n\nkfold = StratifiedKFold(n_splits=10, random_state=42, shuffle=True)\ncv_results = cross_val_score(model, X, y, cv=kfold, scoring='roc_auc', verbose=3)\ncv_results.mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"xgb =XGBRegressor(base_score=0.5, booster=None, colsample_bylevel=1,\n                    importance_type='gain', interaction_constraints=None,\n                     min_child_weight=1, missing=None, monotone_constraints=None,\n                     n_estimators=700, n_jobs=-1, nthread=-1, num_parallel_tree=1\n                    )\nxgb.fit(X, y)\npred = xgb.predict(x_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub = pd.DataFrame({'image_name':test.image_name.values,\n                    'target':pred})\nsub.to_csv('submission.csv',index = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# If you like my work, do upvote :)","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}