{"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":"markdown","source":"<center><img alt=\"Insight logo\" src=\"https://www.addict-mobile.com/wp-content/uploads/2015/09/shutterstock_175377776-e1488459895956.jpg\" align=\"center\" hspace=\"0px\" vspace=\"0px\" width=50% height=50px ></center>","metadata":{"execution":{"iopub.status.busy":"2022-10-28T22:46:12.830660Z","iopub.execute_input":"2022-10-28T22:46:12.831745Z","iopub.status.idle":"2022-10-28T22:46:12.837676Z","shell.execute_reply.started":"2022-10-28T22:46:12.831685Z","shell.execute_reply":"2022-10-28T22:46:12.836535Z"}}},{"cell_type":"markdown","source":"\n<p style=\"font-size:20px; font-family: Trebuchet MS; font-style:italic;\"> The dataset includes information about the <span style=\"color:#122ecc;\"> click-through rate (CTR)</span>. It is a very critical metric for evaluating the performance of online ads. For sponsored search and real-time bidding, click prediction systems are essential. A variety of entities broadcast data about the CTR, including<span style=\"color:#122ecc;\"> Time, App, Site and Device Information</span>. This dataset currently contains <span style=\"color:red;\">1048576 records</span>.</p>\n<center><img src=\"https://www.dynodesoft.com/assets/img/MB-6-Quick-Tips-GoogleAds-FA-P1_4.gif\" /></center>\n","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/DataAnalysislogo.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"100\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:red\">Data Analysis</li>\n</ul>\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li> Downloading, cleaning, and preparing the Dataset</li> \n</ul>","metadata":{"id":"SkKRlLi1z4Vj"}},{"cell_type":"code","source":"# Install all the required libraries\n!pip install --root-user-action=ignore opendatasets scikit-learn --upgrade --quiet","metadata":{"id":"ZiMVPGLRz4Vl","execution":{"iopub.status.busy":"2022-11-01T15:42:46.738428Z","iopub.execute_input":"2022-11-01T15:42:46.738913Z","iopub.status.idle":"2022-11-01T15:42:58.887790Z","shell.execute_reply.started":"2022-11-01T15:42:46.738877Z","shell.execute_reply":"2022-11-01T15:42:58.885959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Import all the required libraries\nimport os\nimport numpy as np\nimport opendatasets as od\nimport pandas as pd\nimport seaborn as sns\nimport plotly.express as px\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\nfrom matplotlib.pylab import rcParams\n\nfrom sklearn.preprocessing import OrdinalEncoder\n\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeRegressor\nfrom xgboost import XGBRegressor\nfrom sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor\nfrom sklearn.tree import plot_tree\nfrom xgboost import plot_tree\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\n\nfrom sklearn.model_selection import KFold\n\nimport warnings\npd.options.mode.chained_assignment = None\nwarnings.filterwarnings('ignore')","metadata":{"id":"bc53Z-6Jz4Vm","execution":{"iopub.status.busy":"2022-11-01T15:42:58.890621Z","iopub.execute_input":"2022-11-01T15:42:58.891031Z","iopub.status.idle":"2022-11-01T15:43:00.217513Z","shell.execute_reply.started":"2022-11-01T15:42:58.890992Z","shell.execute_reply":"2022-11-01T15:43:00.216052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download the dataset from kaggle\n# dataset_url = 'https://www.kaggle.com/c/avazu-ctr-prediction'\n# od.download(dataset_url)\n# os.listdir('avazu-ctr-prediction')\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"id":"J3ADtFBCz4Vn","outputId":"285a7beb-d503-4627-93ca-521930b610cf","execution":{"iopub.status.busy":"2022-11-01T15:43:00.219095Z","iopub.execute_input":"2022-11-01T15:43:00.219641Z","iopub.status.idle":"2022-11-01T15:43:00.228860Z","shell.execute_reply.started":"2022-11-01T15:43:00.219574Z","shell.execute_reply":"2022-11-01T15:43:00.227816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# read & load the dataset into pandas dataframe\ntrainDf = pd.read_csv('/kaggle/input/avazu-ctr-prediction/train.gz',compression='gzip', nrows =4577464, header=0, sep=',', quotechar='\"')\ntestDf = pd.read_csv('/kaggle/input/avazu-ctr-prediction/test.gz',compression='gzip', nrows =4577464, header=0, sep=',', quotechar='\"')","metadata":{"id":"HDinlEGpz4Vo","execution":{"iopub.status.busy":"2022-11-01T20:20:09.316598Z","iopub.execute_input":"2022-11-01T20:20:09.317008Z","iopub.status.idle":"2022-11-01T20:20:49.417747Z","shell.execute_reply.started":"2022-11-01T20:20:09.316970Z","shell.execute_reply":"2022-11-01T20:20:49.416442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('The train dataset contains {:,d} rows & {} columns'.format(trainDf.shape[0], trainDf.shape[1]))\nprint('The test dataset contains {:,d} rows & {} columns'.format(testDf.shape[0], testDf.shape[1]))","metadata":{"id":"15qtV2CW-3VG","execution":{"iopub.status.busy":"2022-11-01T20:30:10.816790Z","iopub.execute_input":"2022-11-01T20:30:10.817276Z","iopub.status.idle":"2022-11-01T20:30:10.824443Z","shell.execute_reply.started":"2022-11-01T20:30:10.817235Z","shell.execute_reply":"2022-11-01T20:30:10.823233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainDf.info()","metadata":{"id":"YIVt94MpNe5L","execution":{"iopub.status.busy":"2022-11-01T20:30:22.706718Z","iopub.execute_input":"2022-11-01T20:30:22.707371Z","iopub.status.idle":"2022-11-01T20:30:22.721939Z","shell.execute_reply.started":"2022-11-01T20:30:22.707329Z","shell.execute_reply":"2022-11-01T20:30:22.720279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check no. of missing values in every column for training dataframe\npd.DataFrame(trainDf.isnull().sum()).T.style.background_gradient(cmap='Spectral_r')","metadata":{"id":"5pVRUpsNNuTO","execution":{"iopub.status.busy":"2022-11-01T15:43:09.711105Z","iopub.execute_input":"2022-11-01T15:43:09.711673Z","iopub.status.idle":"2022-11-01T15:43:10.232006Z","shell.execute_reply.started":"2022-11-01T15:43:09.711636Z","shell.execute_reply":"2022-11-01T15:43:10.230757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check no. of missing values in every column for test dataframe\npd.DataFrame(testDf.isnull().sum()).T.style.background_gradient(cmap='Wistia_r')","metadata":{"id":"M2Sl2mekN5H_","outputId":"bf5f11b6-8330-4dda-af88-155eedb1931a","execution":{"iopub.status.busy":"2022-11-01T15:43:10.233564Z","iopub.execute_input":"2022-11-01T15:43:10.234003Z","iopub.status.idle":"2022-11-01T15:43:10.694862Z","shell.execute_reply.started":"2022-11-01T15:43:10.233968Z","shell.execute_reply":"2022-11-01T15:43:10.693330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>It can be observed that the given Training and Test Datasets don't contain any null value.</li>\n    <br>\n</ul>\n</div>","metadata":{"id":"pDtqGCIsTQ-H"}},{"cell_type":"code","source":"trainDf.head(15).style.background_gradient(cmap='Pastel2')","metadata":{"id":"wppexu00OJRx","outputId":"e3b5a8fc-43d4-40a9-df1d-f38d5903762e","execution":{"iopub.status.busy":"2022-11-01T20:29:49.465468Z","iopub.execute_input":"2022-11-01T20:29:49.465993Z","iopub.status.idle":"2022-11-01T20:29:49.524291Z","shell.execute_reply.started":"2022-11-01T20:29:49.465947Z","shell.execute_reply":"2022-11-01T20:29:49.522772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>An overview of Training Dataset.</span></li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"testDf.head(15).style.background_gradient(cmap='icefire')","metadata":{"id":"Y6DcE6HKOpuL","outputId":"2bdf2f21-9b96-4086-f1a7-6fd5adc73da0","execution":{"iopub.status.busy":"2022-11-01T20:29:29.807824Z","iopub.execute_input":"2022-11-01T20:29:29.808567Z","iopub.status.idle":"2022-11-01T20:29:29.866855Z","shell.execute_reply.started":"2022-11-01T20:29:29.808529Z","shell.execute_reply":"2022-11-01T20:29:29.865619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>An overview of Test Dataset.</span></li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/EDA%20Training%20Data.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:red\">&emsp;Exploratory Data Analyses on Training Data</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize = (12,6), dpi = 80)\nsns.heatmap(trainDf.corr(), annot=True, cmap='crest');\nplt.title('\\nCorrelation of all columns in Training Dataframe\\n', size=20, color='grey')\nax.patch.set_edgecolor('black')  \nax.patch.set_linewidth('1')","metadata":{"id":"XWMJXpgVPS0-","outputId":"df3ae56e-abd5-4eb9-b5ea-be9ae104d0aa","execution":{"iopub.status.busy":"2022-11-01T20:29:13.187949Z","iopub.execute_input":"2022-11-01T20:29:13.188835Z","iopub.status.idle":"2022-11-01T20:29:18.126641Z","shell.execute_reply.started":"2022-11-01T20:29:13.188765Z","shell.execute_reply":"2022-11-01T20:29:18.125250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The heatmap is visualising the correlation of the columns in the Training Dataset</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/target.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:darkblue\">&emsp;Analyses by Target Data</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"# Create a subplot\nfig, ax = plt.subplots(figsize = (12,6), dpi = 80)\n\nx = trainDf.click\nax=sns.distplot(x=x, color='red')\n\n# Plot a kernel density estimate and rug plot\nplt.title('\\nDensity Estimation Of Click(target) attribue\\n', size=20, color='grey')\nplt.xticks(fontsize=12)\nplt.yticks([])\nax.grid(color='#b2d6c7', linewidth=1, axis='x', alpha=.3)\n\nax.set_facecolor((1, 1, 1))\nax.patch.set_edgecolor('grey')  \nax.patch.set_linewidth('1')\n\n\nplt.show()","metadata":{"id":"goYQTL1KVR-P","outputId":"1824c854-d1d9-4afc-a5a4-3aec6ed657e6","execution":{"iopub.status.busy":"2022-11-01T20:28:42.343570Z","iopub.execute_input":"2022-11-01T20:28:42.344043Z","iopub.status.idle":"2022-11-01T20:29:02.115670Z","shell.execute_reply.started":"2022-11-01T20:28:42.344007Z","shell.execute_reply":"2022-11-01T20:29:02.114747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The rug plot visualize the distribution through density for target attribute that is 'Click' in the Training Dataset.</span></li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"# Store all the numeric data names into a list\nnumericData = list(trainDf.loc[:,trainDf.columns != 'click'].select_dtypes(exclude=['object']).columns)\n\n# # Remove target column\n# numericData.remove('click')\n\n# Store all the categoric data names into a list\ncategoricData = list(trainDf.select_dtypes(include=['object']).columns)\n\n# Store all the feature names into a list\nwholeData = numericData + categoricData","metadata":{"id":"KYDyPjWrX6PC","execution":{"iopub.status.busy":"2022-11-01T20:28:27.394164Z","iopub.execute_input":"2022-11-01T20:28:27.394671Z","iopub.status.idle":"2022-11-01T20:28:29.118856Z","shell.execute_reply.started":"2022-11-01T20:28:27.394630Z","shell.execute_reply":"2022-11-01T20:28:29.117412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/NumericData.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:darkblue\">&emsp;Analyses by Numeric Data</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"trainDf[numericData[2:]].describe().T.style.background_gradient(cmap='coolwarm')","metadata":{"id":"4oHS1hMRds_l","outputId":"334b31d0-c306-4563-b153-fc1710bece35","execution":{"iopub.status.busy":"2022-11-01T20:28:12.353264Z","iopub.execute_input":"2022-11-01T20:28:12.354074Z","iopub.status.idle":"2022-11-01T20:28:14.545538Z","shell.execute_reply.started":"2022-11-01T20:28:12.354015Z","shell.execute_reply":"2022-11-01T20:28:14.544198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>Statical Analysis of Numeric Data</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"import itertools as it\ndef distributionOfNumeric(df, color_list, height):\n\n    column = df.columns\n    length = len(column)\n    plt.subplots(figsize = (12, height))\n    for i, j in it.zip_longest(column, range(length)):\n        plt.subplot((length), 2, j + 1)\n        plt.subplots_adjust(wspace = 0.3,hspace = 0.3)\n        df[i].hist(bins = 20, rwidth=0.9, color = color_list[j])\n        plt.title(i)\n    plt.show()\n    \ncolours = ['firebrick', 'indigo', 'indianred', 'darkviolet', 'tomato', \n          'deeppink', 'sandybrown', 'lime', 'lightsalmon', 'greenyellow', \n          'orange', 'turquoise', 'gold' ]\ndistributionOfNumeric(trainDf[numericData[2:]], colours, 50)","metadata":{"id":"32oT1aYprsos","outputId":"2f94b264-3317-4aa2-b4a4-5d788e75661d","execution":{"iopub.status.busy":"2022-11-01T20:27:54.035156Z","iopub.execute_input":"2022-11-01T20:27:54.035666Z","iopub.status.idle":"2022-11-01T20:27:57.770763Z","shell.execute_reply.started":"2022-11-01T20:27:54.035626Z","shell.execute_reply":"2022-11-01T20:27:57.769729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>These rug plots are showing the distribution of Numeric Data present in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/CatagoricData.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"120\" height=\"180\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <br>\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:darkblue\">&emsp;Analyses by Categoric Data</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"trainDf[categoricData]","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:27:36.200720Z","iopub.execute_input":"2022-11-01T20:27:36.201233Z","iopub.status.idle":"2022-11-01T20:27:36.831817Z","shell.execute_reply.started":"2022-11-01T20:27:36.201190Z","shell.execute_reply":"2022-11-01T20:27:36.830880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = trainDf[categoricData]\n\nfig = px.density_heatmap(df, x=\"site_domain\", y=\"site_id\", histfunc='count', range_x=(1,15), range_y=(1,15), color_continuous_scale=px.colors.sequential.Aggrnyl, marginal_x=\"histogram\", marginal_y=\"histogram\", text_auto=True)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T15:43:21.493888Z","iopub.execute_input":"2022-11-01T15:43:21.494258Z","iopub.status.idle":"2022-11-01T15:43:38.761545Z","shell.execute_reply.started":"2022-11-01T15:43:21.494224Z","shell.execute_reply":"2022-11-01T15:43:38.759570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The Heatmap visualizing importance of categoric column 'site_domain' in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"df = trainDf[categoricData]\n\nfig = px.density_heatmap(df, x=\"site_category\", y=\"site_id\", histfunc='count', range_x=(1,15), range_y=(1,15), marginal_x=\"histogram\", marginal_y=\"histogram\", text_auto=True)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T15:43:38.763807Z","iopub.execute_input":"2022-11-01T15:43:38.764580Z","iopub.status.idle":"2022-11-01T15:43:55.039775Z","shell.execute_reply.started":"2022-11-01T15:43:38.764490Z","shell.execute_reply":"2022-11-01T15:43:55.037741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The heatmap is visualising the importance of categoric column 'site_category' in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"px.histogram(trainDf, x= 'app_domain', color=\"app_id\", histfunc='count', range_x=(0,10))","metadata":{"execution":{"iopub.status.busy":"2022-11-01T15:43:55.041558Z","iopub.execute_input":"2022-11-01T15:43:55.042461Z","iopub.status.idle":"2022-11-01T15:44:09.516580Z","shell.execute_reply.started":"2022-11-01T15:43:55.042416Z","shell.execute_reply":"2022-11-01T15:44:09.515297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The histogram is visualising the importance of categoric column 'app_domain' in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"px.histogram(trainDf, x= 'app_category', color=\"app_id\", histfunc='count', range_x=(0,10))","metadata":{"execution":{"iopub.status.busy":"2022-11-01T15:44:09.518593Z","iopub.execute_input":"2022-11-01T15:44:09.518983Z","iopub.status.idle":"2022-11-01T15:44:23.998320Z","shell.execute_reply.started":"2022-11-01T15:44:09.518946Z","shell.execute_reply":"2022-11-01T15:44:23.996780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The histogram is visualising the importance of categoric column 'app_category' in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"plot = trainDf.groupby(['device_id'])[['device_model']].count()\ncountDeviceModelList= plot['device_model'].tolist()\nplot = trainDf.groupby(['device_id'])[['device_model']].nth(0)\nplot['device_model_count']= countDeviceModelList\nplot=plot.sort_values(by='device_model_count',ascending=False).reset_index()\nplot=trainDf.sort_values(by='device_id',ascending=False).reset_index()\ndf = plot.head(10000)\nfig = px.scatter(df, x=\"device_model\", y='device_id', color = 'device_id')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T15:44:23.999870Z","iopub.execute_input":"2022-11-01T15:44:24.000303Z","iopub.status.idle":"2022-11-01T15:44:44.949950Z","shell.execute_reply.started":"2022-11-01T15:44:24.000264Z","shell.execute_reply":"2022-11-01T15:44:44.948587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The histogram is visualising the importance of categoric column 'device_model' in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"plot = trainDf.groupby(['device_id'])[['device_ip']].count()\ncountDeviceIPList= plot['device_ip'].tolist()\nplot = trainDf.groupby(['device_id'])[['device_ip']].nth(0)\nplot['device_ip_count']= countDeviceIPList\nplot=plot.sort_values(by='device_ip_count',ascending=False).reset_index()\ndf = plot.head(10000)\nfig = px.scatter(df, x=\"device_ip\",y='device_id', color='device_id', title=\"Numeric 'size' values mean continuous color\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T15:44:44.951656Z","iopub.execute_input":"2022-11-01T15:44:44.952023Z","iopub.status.idle":"2022-11-01T15:45:22.911615Z","shell.execute_reply.started":"2022-11-01T15:44:44.951990Z","shell.execute_reply":"2022-11-01T15:45:22.910499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The histogram is visualising the importance of categoric column 'device_ip' in Training Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://github.com/warazkhan/MobileAdvertisement-MachineLearning/blob/main/Project%20Images/DataPreprocessing.png?raw=true\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:red\">&emsp;Data Preprocessing</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"# Create the input feature dataframe\ninputDf = trainDf.drop(['click'], axis=1)\n\n# Create a serise of target attribute\ntargetDf = trainDf['click']\n\n# Create a dataframe by copying the test dataframe\ninputTest = testDf.copy()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:24:11.288605Z","iopub.execute_input":"2022-11-01T20:24:11.289058Z","iopub.status.idle":"2022-11-01T20:24:12.922937Z","shell.execute_reply.started":"2022-11-01T20:24:11.289022Z","shell.execute_reply":"2022-11-01T20:24:12.921528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/Encoding.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:darkblue\">&emsp;Encoding Categoric Data</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"# Create an OrdinalEncoder object \nencoder = OrdinalEncoder(dtype=np.int64)\n\n# Fit and Transform the Categoric Data of Training Dataset\ninputDf[categoricData] = encoder.fit_transform(inputDf[categoricData])\n\n# Fit and Transform the Categoric Data of Test Dataset\ninputTest[categoricData] = encoder.fit_transform(inputTest[categoricData])","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:24:22.450406Z","iopub.execute_input":"2022-11-01T20:24:22.450820Z","iopub.status.idle":"2022-11-01T20:25:23.093143Z","shell.execute_reply.started":"2022-11-01T20:24:22.450783Z","shell.execute_reply":"2022-11-01T20:25:23.091965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inputDf.head(15).style.background_gradient(cmap='Set3')","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:25:23.094920Z","iopub.execute_input":"2022-11-01T20:25:23.095286Z","iopub.status.idle":"2022-11-01T20:25:23.158131Z","shell.execute_reply.started":"2022-11-01T20:25:23.095252Z","shell.execute_reply":"2022-11-01T20:25:23.156980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>Overview of Input Dataset after Encoding the categorical values.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"inputTest.head(15).style.background_gradient(cmap='tab20')","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:25:23.159650Z","iopub.execute_input":"2022-11-01T20:25:23.160058Z","iopub.status.idle":"2022-11-01T20:25:23.229858Z","shell.execute_reply.started":"2022-11-01T20:25:23.160027Z","shell.execute_reply":"2022-11-01T20:25:23.227960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>Overview of Test Dataset after Encoding the categorical values.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/ModelSelection.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:red\">&emsp;Model Selection</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"# Create Regressor objects of several Algorithm Classes\nLogisticRegressionModel = LogisticRegression(solver='liblinear')\nDecisionTreeRegressorModel = DecisionTreeRegressor(random_state=5)\nRandomForestRegressorModel = RandomForestRegressor(random_state=5)\nGradientBoostingRegressorModel = GradientBoostingRegressor(random_state=5)\nXGBRegressorModel = XGBRegressor(random_state=5)\n\n# Create a list of all model objects\nmodels = [LogisticRegressionModel, DecisionTreeRegressorModel, RandomForestRegressorModel, GradientBoostingRegressorModel, XGBRegressorModel]","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:25:29.983045Z","iopub.execute_input":"2022-11-01T20:25:29.983604Z","iopub.status.idle":"2022-11-01T20:25:29.993770Z","shell.execute_reply.started":"2022-11-01T20:25:29.983555Z","shell.execute_reply":"2022-11-01T20:25:29.991847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def EvaluateRMSEmodel(model):\n    \n    inputTrain, inputValid, targetTrain, targetValid = train_test_split(inputDf[:100000], targetDf[:100000], test_size=0.25, random_state=5)\n    model.fit(inputTrain, targetTrain)\n    modelPrediction = model.predict(inputValid)\n    \n    if model==DecisionTreeRegressorModel:\n        from sklearn.tree import plot_tree\n        #sns.set_style('darkgrid')\n        plot_tree(DecisionTreeRegressorModel, feature_names=inputTrain.columns, max_depth=2, filled=True, label='all')\n        plt.title('Decision Tree Regressor Model', fontsize = 50)\n    \n    elif model==XGBRegressorModel:\n        from xgboost import plot_tree\n        plot_tree(XGBRegressorModel, rankdir='LR', num_trees=1);\n        plt.title('XGB Regressor Model', fontsize = 50)\n    \n    RMSEmodel = np.sqrt(mean_squared_error(modelPrediction, targetValid))\n    \n    return RMSEmodel","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:25:31.878158Z","iopub.execute_input":"2022-11-01T20:25:31.878659Z","iopub.status.idle":"2022-11-01T20:25:31.889577Z","shell.execute_reply.started":"2022-11-01T20:25:31.878619Z","shell.execute_reply":"2022-11-01T20:25:31.888132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30,15))\nrcParams['figure.figsize'] = 30,30\n\n# Create a list of RMSE values of different models\nRMSE = [EvaluateRMSEmodel(model) for model in models]\n\n# Store the Model Regressors names into a list\nModels = [str(i).split('(')[0] for i in models]","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:25:37.971547Z","iopub.execute_input":"2022-11-01T20:25:37.972991Z","iopub.status.idle":"2022-11-01T20:26:54.886958Z","shell.execute_reply.started":"2022-11-01T20:25:37.972935Z","shell.execute_reply":"2022-11-01T20:26:54.885302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create a DataFrame using the name Model names and their RMSE values\nModelsEvaluationDf = pd.DataFrame(list(zip(Models, RMSE)), columns=['Models', 'RootMeanSquareError'])\n\nModelsEvaluationDf.sort_values(by='RootMeanSquareError').style.background_gradient(cmap='PuRd')","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:26:54.889712Z","iopub.execute_input":"2022-11-01T20:26:54.890134Z","iopub.status.idle":"2022-11-01T20:26:54.909990Z","shell.execute_reply.started":"2022-11-01T20:26:54.890095Z","shell.execute_reply":"2022-11-01T20:26:54.908797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = ModelsEvaluationDf.sort_values(by='RootMeanSquareError')\nfig = px.bar(df, x='Models', y='RootMeanSquareError', color=\"Models\", pattern_shape=\"Models\", pattern_shape_sequence=[\"|\",\".\", \"x\", \"+\",\"/\"])\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:26:54.911928Z","iopub.execute_input":"2022-11-01T20:26:54.912351Z","iopub.status.idle":"2022-11-01T20:26:55.009154Z","shell.execute_reply.started":"2022-11-01T20:26:54.912315Z","shell.execute_reply":"2022-11-01T20:26:55.007903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>Histogram visualizing a clear comparison of the Root Mean Square values of all models. XGB Regressor has the lowest RMSE value. Therefore, XGB Regressor can be the final model building.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/XGB%20Regressor.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:red\">&emsp;XGB Regressor</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"# Create a dictionary with the best values of XGBRegressor's model tunning parameters\nxgb_params = {\n    'booster': 'gbtree',\n    'n_estimators': 10000,\n    'learning_rate': 0.05,\n    'reg_lambda': 10,\n    'reg_alpha': 26,\n    'subsample': 0.9,\n    'colsample_bytree': 0.12,\n    'max_depth': 3,\n    'random_state': 5 \n}","metadata":{"execution":{"iopub.status.busy":"2022-11-01T20:31:02.841000Z","iopub.execute_input":"2022-11-01T20:31:02.842631Z","iopub.status.idle":"2022-11-01T20:31:02.848524Z","shell.execute_reply.started":"2022-11-01T20:31:02.842578Z","shell.execute_reply":"2022-11-01T20:31:02.847397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/MobileAdvertisement-MachineLearning/main/Project%20Images/KFold.png\" align=\"left\" hspace=\"25px\" vspace=\"5px\" width=\"90\" height=\"80\" ></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:35px;font-style: italic;color:red\">&emsp;K Fold Cross Validation</li>\n</ul>","metadata":{}},{"cell_type":"code","source":"#Setting the kfold parameters\nNoOfFolds = 7\nKF = KFold(n_splits= NoOfFolds, shuffle=True, random_state=1)\n\nmodelPredictions = np.zeros((inputDf.shape[0],))\ntargetPredictions = 0\nmodelFit = 0\nmeanRMSE = 0\n\nfor foldNumber, (train_idx, valid_idx) in enumerate(KF.split(inputDf[:200000])):\n    \n    # split the train data into train and validation\n    inputTrain = inputDf.iloc[train_idx][wholeData]\n    inputValid = inputDf.iloc[valid_idx][wholeData]\n    targetTrain = targetDf.iloc[train_idx]\n    targetValid = targetDf.iloc[valid_idx]\n    \n    # XGBRegressor Model fitting\n    model = XGBRegressor(**xgb_params)\n    model.fit(inputTrain, targetTrain,\n             verbose = False,\n             eval_set = [(inputValid, targetValid)],\n             eval_metric = \"rmse\",\n             early_stopping_rounds = 50)\n    \n    #Mean of the predictions\n    targetPredictions += model.predict(inputTest) / NoOfFolds\n    \n    #Mean of feature importance\n    modelFit += model.feature_importances_ / NoOfFolds \n    \n    #Out of Fold predictions\n    modelPredictions[valid_idx] = model.predict(inputValid[:4577464])\n    RMSEofFolds = np.sqrt(mean_squared_error(targetValid, modelPredictions[valid_idx]))\n    print(f\"RMSE of Fold {foldNumber+1}: {RMSEofFolds}\")\n    \n    meanRMSE += RMSEofFolds / NoOfFolds\n    \nprint(f\"\\nOverall Root Mean Square Error (RMSE): {meanRMSE}\")","metadata":{"execution":{"iopub.status.busy":"2022-11-01T23:07:05.060915Z","iopub.execute_input":"2022-11-01T23:07:05.061417Z","iopub.status.idle":"2022-11-01T23:40:51.665283Z","shell.execute_reply.started":"2022-11-01T23:07:05.061377Z","shell.execute_reply":"2022-11-01T23:40:51.663475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"featureImportanceDf = pd.DataFrame({\n    'Feature': wholeData,\n    'FeatureImportance': modelFit\n})\nfeatureImportanceDf = featureImportanceDf.sort_values(by='FeatureImportance', ascending=False)\nfeatureImportanceDf.style.background_gradient(cmap='plasma')","metadata":{"execution":{"iopub.status.busy":"2022-11-01T23:41:03.844097Z","iopub.execute_input":"2022-11-01T23:41:03.844919Z","iopub.status.idle":"2022-11-01T23:41:03.872902Z","shell.execute_reply.started":"2022-11-01T23:41:03.844870Z","shell.execute_reply":"2022-11-01T23:41:03.871581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = featureImportanceDf\nfig = px.bar(df, y='Feature', x='FeatureImportance', text_auto='.2s', color='Feature',\n            title=\"Feature Importance\")\nfig.update_traces(textfont_size=12, textangle=0, textposition=\"outside\", cliponaxis=False)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-01T23:41:32.001218Z","iopub.execute_input":"2022-11-01T23:41:32.001739Z","iopub.status.idle":"2022-11-01T23:41:32.214793Z","shell.execute_reply.started":"2022-11-01T23:41:32.001697Z","shell.execute_reply":"2022-11-01T23:41:32.213437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/Insights%20logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"180\" height=\"150\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">Insights:</li>\n</ul>\n\n<div class=\"alert alert-success\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\">\n    <li>The bar plot visualising the Impotannce of Features in Dataset.</li>\n    <br>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"# Save the predictions to a CSV file\nresult = pd.read_csv('../input/avazu-ctr-prediction/sampleSubmission.gz', compression='gzip')\nresult = pd.DataFrame({'id': result['id'], 'click': targetPredictions})\n\nresult.to_csv('submission.csv', index=False)\nresult","metadata":{"execution":{"iopub.status.busy":"2022-11-01T23:56:57.192763Z","iopub.execute_input":"2022-11-01T23:56:57.193328Z","iopub.status.idle":"2022-11-01T23:57:09.417447Z","shell.execute_reply.started":"2022-11-01T23:56:57.193281Z","shell.execute_reply":"2022-11-01T23:57:09.415792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/allinsight-logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"80\" height=\"80\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">&emsp;All Insights:</li>\n</ul>       \n<div class=\"alert alert-info\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\"> \n    <li>1. It can be observed that the given Training and Test Datasets don't contain any null value.</li>\n     <br>\n    <li>2. An overview of Training Dataset.</li>\n     <br>\n    <li>3. An overview of Test Dataset.</li>\n     <br>\n    <li>4. The heatmap is visualising the correlation of the columns in the Training Dataset.</li>\n     <br>\n    <li>5. The rug plot visualize the distribution through density for target attribute that is 'Click' in the Training Dataset.</li>\n     <br>\n    <li>6. Statical Analysis of Numeric Data</li>\n     <br>\n    <li>7. These rug plots are showing the distribution of Numeric Data present in Training Dataset.</li>\n     <br>\n    <li>8. The heatmap visualizing importance of categoric column 'site_domain' in Training Dataset.</li>\n     <br>\n    <li>9. The heatmap is visualising the importance of categoric column 'site_category' in Training Dataset.</li>\n     <br>\n    <li>10. The histogram is visualising the importance of categoric column 'app_domain' in Training Dataset.</li>\n     <br>\n    <li>11. The histogram is visualising the importance of categoric column 'app_category' in Training Dataset.</li>\n     <br>\n    <li>12. The histogram is visualising the importance of categoric column 'device_model' in Training Dataset.</li>\n     <br>\n    <li>13. The histogram is visualising the importance of categoric column 'device_ip' in Training Dataset.</li>\n     <br>\n    <li>14. Overview of Input Dataset after Encoding the categorical values.</li>\n     <br>\n    <li>15. Overview of Test Dataset after Encoding the categorical values.</li>\n     <br>\n    <li>16. Histogram visualizing a clear comparison of the Root Mean Square values of all models. XGB Regressor has the lowest RMSE value. Therefore, XGB Regressor can be the final model building.</li>\n     <br>\n    <li>17. The bar plot visualising the Impotannce of Features in Dataset.</li>\n    <br>\n    \n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<p><img alt=\"Insight logo\" src=\"https://raw.githubusercontent.com/warazkhan/Data-Analysis-Project/main/refrences-logo.png\" align=\"left\" hspace=\"0px\" vspace=\"10px\" width=\"80\" height=\"80\"></p>\n\n<ul style=\"list-style-type:none;\">\n  <li style=\"font-weight: bold;font-family:Trebuchet MS;font-size:30px;font-style: italic;color:  red\">&emsp;Refrences:</li>\n</ul>      \n\n<div class=\"alert alert-warning\" role=\"alert\">\n<ul style=\"list-style-type:none;font-family:Trebuchet MS;font-size:17px;color:black\"> \n    <li>1. <span style=\"font-weight: bold; color:#122ecc;\"> https://www.addict-mobile.com/mobile-marketing-visuals/</span></li>     \n    <br>          \n    <li>2. <span style=\"font-weight: bold; color:#122ecc;\"> https://www.dynodesoft.com/best-sem-company-in-patna/</span></li>     \n    <br>\n    <li>3. <span style=\"font-weight: bold; color:#122ecc;\">https://inria.github.io/scikit-learn-mooc/python_scripts/03_categorical_pipeline.html</span></li>\n    <br> \n    <li>4. <span style=\"font-weight: bold; color:#122ecc;\">https://www.pngegg.com/</span></li> \n    <br>\n    <li>5. <span style=\"font-weight: bold; color:#122ecc;\">https://www.behance.net/gallery/48491355/Promotional-Gif-Sets</span></li> \n    <br>   \n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<img alt=\"Insight logo\" src=\"https://mir-s3-cdn-cf.behance.net/project_modules/1400_opt_1/604f3d48491355.5899b4c989234.gif\" align=\"left\" hspace=\"0px\" vspace=\"0px\" width=100% height=0 >","metadata":{}}]}