Commit 38cba913 authored by ashivani's avatar ashivani
Browse files

changed baseline

parent d8481009
Pipeline #4154 passed with stages
in 5 minutes and 53 seconds
......@@ -5,11 +5,11 @@
![](https://pngimage.net/wp-content/uploads/2018/05/ad-png-1.png)
They popped up when you were browsing, they popped up when you were streaming videos, they popped up when you were playing an intense video game. Did you give in? Did you find those advertisements catchy enough to click!
Well we made a challenge out of it!
Given information about an advertisement, can you predict whether it will be clicked upon?
Well we made a challenge out of it!
Given information about an `advertisement`, can you `predict` whether it will be `clicked` upon?
</br>Understand with code! Here is [`getting started code`](https://discourse.aicrowd.com/t/baseline-mnist/2757) for you.`😄`
Understand with code! Here is [`getting started code`](https://discourse.aicrowd.com/t/baseline-adclk/3024) for you.`😄`
# 💾 Dataset
The dataset provided contains advertisements that were shown along side search results and whether or not they were clicked on. For each advertisement 11 properties are given:
......@@ -38,7 +38,7 @@ Following files are available in the `resources` section:
- Name of the above file should be `submission.csv`.
- Sample submission format available at `sample_submission.csv` in the resorces section.
**Make your first submission [here](https://www.aicrowd.com/challenges/adclk-predict-if-an-ad-will-be-clicked/submissions/new) 🚀 !!**
**Make your first submission [here](https://www.aicrowd.com/challenges/adclk/submissions/new) 🚀 !!**
# 🖊 Evaluation Criteria
During evaluation [F1 score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html) will be used to test the efficiency of the model where,
......@@ -47,12 +47,12 @@ During evaluation [F1 score](https://scikit-learn.org/stable/modules/generated/s
# 🔗 Links
* 💪 Challenge Page: [https://www.aicrowd.com/challenges/adclk](https://www.aicrowd.com/challenges/adclk-predict-if-an-ad-will-be-clicked)
* 🗣️ Discussion Forum: [https://www.aicrowd.com/challenges/adclk/discussion](https://www.aicrowd.com/challenges/adclk-predict-if-an-ad-will-be-clicked/discussion)
* 🏆 Leaderboard: [https://www.aicrowd.com/challenges/adclk/leaderboards](https://www.aicrowd.com/challenges/adclk-predict-if-an-ad-will-be-clicked/leaderboards)
* 💪 Challenge Page: [https://www.aicrowd.com/challenges/adclk](https://www.aicrowd.com/challenges/adclk)
* 🗣️ Discussion Forum: [https://www.aicrowd.com/challenges/adclk/discussion](https://www.aicrowd.com/challenges/adclk/discussion)
* 🏆 Leaderboard: [https://www.aicrowd.com/challenges/adclk/leaderboards](https://www.aicrowd.com/challenges/adclk/leaderboards)
# 📱 Contact
- [Sanjay Pokkali](mailto:sanjay@ext.aicrowd.com)
# 📚 References
- https://pngimage.net/wp-content/uploads/2018/05/ad-png-1.png
\ No newline at end of file
- [Image Source](https://pngimage.net/wp-content/uploads/2018/05/ad-png-1.png)
\ No newline at end of file
%% Cell type:markdown id: tags:
# Baseline for ADCLK Educational Challenge on AIcrowd
#### Author : Sanjay Pokkali
![AIcrowd-Logo](https://raw.githubusercontent.com/AIcrowd/AIcrowd/master/app/assets/images/misc/aicrowd-horizontal.png)
%% Cell type:markdown id: tags:
## To open this notebook on Google Computing platform Colab, click below!
%% Cell type:markdown id: tags:
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)
# Getting Started Code for [ADCLK Educational Challenge](https://www.aicrowd.com/challenges/adclk)
#### Author : Sanjay Pokkali
%% Cell type:markdown id: tags:
## Download Necessary Packages
%% Cell type:code id: tags:
``` python
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip install pandas
!{sys.executable} -m pip install scikit-learn
!pip install numpy
!pip install pandas
!pip install scikit-learn
```
%% Cell type:markdown id: tags:
## Download data
......@@ -33,12 +28,16 @@
%% Cell type:code id: tags:
``` python
#Donwload the datasets
!rm -rf data
!mkdir data
!wget https://s3.eu-central-1.wasabisys.com/aicrowd-practice-challenges/public/adclk/v0.1/train.csv
!wget https://s3.eu-central-1.wasabisys.com/aicrowd-practice-challenges/public/adclk/v0.1/test.csv
!mv train.csv data/train.csv
!mv test.csv data/test.csv
```
%% Cell type:markdown id: tags:
......@@ -57,32 +56,34 @@
```
%% Cell type:markdown id: tags:
## Load Data
We use pandas library to load our data. Pandas loads them into dataframes which helps us analyze our data easily. Learn more about it [here](https://www.tutorialspoint.com/python_data_science/python_pandas.htm)
- We use pandas 🐼 library to load our data.
- Pandas loads the data into dataframes and facilitates us to analyse the data.
- Learn more about it [here](https://www.tutorialspoint.com/python_data_science/python_pandas.htm) 🤓
%% Cell type:code id: tags:
``` python
train_data_path = "train.csv" #path where data is stored
all_data_path = "data/train.csv" #path where data is stored
```
%% Cell type:code id: tags:
``` python
train_data = pd.read_csv(train_data_path) #load data in dataframe using pandas
all_data = pd.read_csv(all_data_path) #load data in dataframe using pandas
```
%% Cell type:markdown id: tags:
## Visualize the data
## Visualize the data 👀
%% Cell type:code id: tags:
``` python
train_data.head()
all_data.head()
```
%% Cell type:markdown id: tags:
We can see the dataset contains 12 columns,where columns 2-12 denotes the information about the person that is called and the first column tell whether he clicked on the ad or not.
......@@ -92,32 +93,38 @@
Let us now pre-process the data to remove any unwanted columns. We remove url_hash and advertiser_id
%% Cell type:code id: tags:
``` python
train_data.drop(["url_hash","advertiser_id"],axis=1,inplace=True)
train_data
all_data.drop(["url_hash","advertiser_id"],axis=1,inplace=True)
all_data
```
%% Cell type:markdown id: tags:
## Split Data into Train and Validation
Now we want to see how well our classifier is performing, but we dont have the test data labels with us to check. What do we do ? So we split our dataset into train and validation. The idea is that we test our classifier on validation set in order to get an idea of how well our classifier works. This way we can also ensure that we dont [overfit](https://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/) on the train dataset. There are many ways to do validation like [k-fold](https://machinelearningmastery.com/k-fold-cross-validation/),[leave one out](https://en.wikipedia.org/wiki/Cross-validation_(statistics), etc
## Split Data into Train and Validation 🔪
- The next step is to think of a way to test how well our model is performing. we cannot use the test data given as it does not contain the data labels for us to verify.
- The workaround this is to split the given training data into training and validation. Typically validation sets give us an idea of how our model will perform on unforeseen data. it is like holding back a chunk of data while training our model and then using it to for the purpose of testing. it is a standard way to fine-tune hyperparameters in a model.
- There are multiple ways to split a dataset into validation and training sets. following are two popular ways to go about it, [k-fold](https://machinelearningmastery.com/k-fold-cross-validation/), [leave one out](https://en.wikipedia.org/wiki/Cross-validation_statistics). 🧐
- Validation sets are also used to avoid your model from [overfitting](https://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/) on the train dataset.
%% Cell type:code id: tags:
``` python
X_train, X_val= train_test_split(train_data, test_size=0.2, random_state=42)
X_train, X_val= train_test_split(all_data, test_size=0.2, random_state=42)
```
%% Cell type:markdown id: tags:
Here we have selected the size of the testing data to be 20% of the total data. You can change it and see what effect it has on the accuracies. To learn more about the train_test_split function [click here](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html).
- We have decided to split the data with 20 % as validation and 80 % as training.
- To learn more about the train_test_split function [click here](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html). 🧐
- This is of course the simplest way to validate your model by simply taking a random chunk of the train set and setting it aside solely for the purpose of testing our train model on unseen data. as mentioned in the previous block, you can experiment 🔬 with and choose more sophisticated techniques and make your model better.
%% Cell type:markdown id: tags:
Now, since we have our data splitted into train and validation sets, we need to get the label separated from the data.
- Now, since we have our data splitted into train and validation sets, we need to get the corresponding labels separated from the data.
- with this step we are all set move to the next step with a prepared dataset.
%% Cell type:code id: tags:
``` python
X_train,y_train = X_train.iloc[:,1:],X_train.iloc[:,0]
......@@ -125,13 +132,23 @@
print(X_train)
```
%% Cell type:markdown id: tags:
## Define the Classifier
Now we come to the juicy part. We have fixed our data and now we train a classifier. The classifier will learn the function by looking at the inputs and corresponding outputs. There are a ton of classifiers to choose from some being [Logistic Regression](https://towardsdatascience.com/logistic-regression-detailed-overview-46c4da4303bc), [SVM](https://towardsdatascience.com/support-vector-machine-introduction-to-machine-learning-algorithms-934a444fca47), [Random Forests](https://towardsdatascience.com/support-vector-machine-introduction-to-machine-learning-algorithms-934a444fca47), [Decision Trees](https://towardsdatascience.com/decision-trees-in-machine-learning-641b9c4e8052), etc.
Tip: A good model doesnt depend solely on the classifier but on the features(columns) you choose. So make sure to play with your data and keep only whats important.
# TRAINING PHASE 🏋️
%% Cell type:markdown id: tags:
## Define the Model
- We have fixed our data and now we are ready to train our model.
- There are a ton of classifiers to choose from some being [Logistic Regression](https://towardsdatascience.com/logistic-regression-detailed-overview-46c4da4303bc), [SVM](https://towardsdatascience.com/support-vector-machine-introduction-to-machine-learning-algorithms-934a444fca47), [Random Forests](https://towardsdatascience.com/support-vector-machine-introduction-to-machine-learning-algorithms-934a444fca47), [Decision Trees](https://towardsdatascience.com/decision-trees-in-machine-learning-641b9c4e8052), etc.🧐
- Remember that there are no hard-laid rules here. you can mix and match classifiers, it is advisable to read up on the numerous techniques and choose the best fit for your solution , experimentation is the key.
- A good model does not depend solely on the classifier but also on the features you choose. So make sure to analyse and understand your data well and move forward with a clear view of the problem at hand. you can gain important insight from [here](https://towardsdatascience.com/the-5-feature-selection-algorithms-every-data-scientist-need-to-know-3a6b566efd2).🧐
%% Cell type:code id: tags:
``` python
classifier = SVC(gamma='auto')
......@@ -142,19 +159,21 @@
# classifier = LogisticRegression()
```
%% Cell type:markdown id: tags:
We have used [Support Vector Machines](https://scikit-learn.org/stable/modules/svm.html#classification) as a classifier here and set few of the parameteres. But one can set more parameters and increase the performance. To see the list of parameters visit [here](https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html).
- To start you off, We have used a basic [Support Vector Machines](https://scikit-learn.org/stable/modules/svm.html#classification) classifier here.
- But you can tune parameters and increase the performance. To see the list of parameters visit [here](https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html).
- Do keep in mind there exist sophisticated techniques for everything, the key as quoted earlier is to search them and experiment to fit your implementation.
%% Cell type:markdown id: tags:
We can also use other classifiers. To read more about sklean classifiers visit [here](https://scikit-learn.org/stable/supervised_learning.html). Try and use other classifiers to see how the performance of your model changes. Try using [Logistic Regression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) or [MLP](http://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html) and compare how the performance changes.
To read more about other sklearn classifiers visit [here 🧐](https://scikit-learn.org/stable/supervised_learning.html). Try and use other classifiers to see how the performance of your model changes. Try using [Logistic Regression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) or [MLP](http://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html) and compare how the performance changes.
%% Cell type:markdown id: tags:
## Train the classifier
## Train the Model
%% Cell type:code id: tags:
``` python
classifier.fit(X_train, y_train)
......@@ -166,12 +185,18 @@
%% Cell type:markdown id: tags:
# Validation Phase 🤔
Wonder how well your model learned! Lets check it.
%% Cell type:markdown id: tags:
## Predict on Validation
Now we predict our trained classifier on the validation set and evaluate our model
Now we predict using our trained model on the validation set we created and evaluate our model on unforeseen data.
%% Cell type:code id: tags:
``` python
y_pred = classifier.predict(X_val)
......@@ -179,12 +204,15 @@
```
%% Cell type:markdown id: tags:
## Evaluate the Performance
We use the same metrics as that will be used for the test set.
[F1 score](https://en.wikipedia.org/wiki/F1_score) and [Log Loss](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html) are the metrics for this challenge
- We have used basic metrics to quantify the performance of our model.
- This is a crucial step, you should reason out the metrics and take hints to improve aspects of your model.
- Do read up on the meaning and use of different metrics. there exist more metrics and measures, you should learn to use them correctly with respect to the solution,dataset and other factors.
- [F1 score](https://en.wikipedia.org/wiki/F1_score) and [Log Loss](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html) are the metrics for this challenge
%% Cell type:code id: tags:
``` python
precision = precision_score(y_val,y_pred,average='micro')
......@@ -203,30 +231,33 @@
print("F1 score of the model is :" ,f1)
```
%% Cell type:markdown id: tags:
# Prediction on Evaluation Set
# Testing Phase 😅
We are almost done. We trained and validated on the training data. Now its the time to predict on test set and make a submission.
%% Cell type:markdown id: tags:
## Load Test Set
Load the test data now
Load the test data on which final submission is to be made.
%% Cell type:code id: tags:
``` python
final_test_path = "test.csv"
final_test_path = "data/test.csv"
final_test = pd.read_csv(final_test_path)
final_test.drop(["url_hash","advertiser_id"],axis=1,inplace=True)
len(final_test)
```
%% Cell type:markdown id: tags:
## Predict Test Set
Time for the moment of truth! Predict on test set and time to make the submission.
Predict on the test set and you are all set to make the submission !
%% Cell type:code id: tags:
``` python
submission = classifier.predict(final_test)
......@@ -245,34 +276,37 @@
%% Cell type:code id: tags:
``` python
submission = pd.DataFrame(submission)
submission.to_csv('/tmp/submission.csv',header=['click'],index=False)
submission.to_csv('submission.csv',header=['click'],index=False)
```
%% Cell type:markdown id: tags:
Note: Do take a look at the submission format.The submission file should contain a header.
🚧 Note :
- Do take a look at the submission format.
- The submission file should contain a header.
- Follow all submission guidelines strictly to avoid inconvenience.
%% Cell type:markdown id: tags:
## To download the generated csv in colab run the below command
%% Cell type:code id: tags:
``` python
try:
from google.colab import files
files.download('/tmp/submission.csv')
except:
print("only in colab")
from google.colab import files
files.download('submission.csv')
except ImportError as e:
print("Only for Collab")
```
%% Cell type:markdown id: tags:
### Go to [platform](https://www.aicrowd.com/challenges/bkmkt-bank-marketing-stategy-analysis). Participate in the challenge and submit the submission.csv.
### Well Done! 👍 We are all set to make a submission and see your name on leaderborad. Let navigate to [challenge page](https://www.aicrowd.com/challenges/adclk) and make one.
%% Cell type:code id: tags:
``` python
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment