1
$\begingroup$

My dependent variable is binary. Most of my independent variables are not. I am at the exploratory stage right now.

Y     X1     X2
0     23    0
1     29    1
0     15    1
1     40    0
1     25    1
0     22    1
This is just a portion of my data.

I was thinking scatter plot to find out the relationship between Y X1 and X2. What other plots I can do to see the relationship more clearly.

$\endgroup$
1
  • $\begingroup$ Can you give us more data such that the plots can look nicer please :) $\endgroup$
    – JahKnows
    Commented May 17, 2018 at 3:00

2 Answers 2

1
$\begingroup$

First we will load this data into a Pandas DataFrame

import pandas as pd
df = pd.DataFrame(data = {'Y': [0,1,0,1,1,0], 
                          'X1':[23,29,15,40,25,22],
                          'X2':[0,1,1,0,1,1]})

You want to see which variables best describe your output $Y$. First step plot your features against your output to see how they are distributed.

plt.figure(figsize=(14,5))

plt.subplot(1,2,1)
plt.scatter(df['X1'], df['Y'])
plt.ylabel('Feature Y')
plt.xlabel('Feature X1')

plt.subplot(1,2,2)
plt.scatter(df['X2'], df['Y'])
plt.ylabel('Feature Y')
plt.xlabel('Feature X2')

plt.show()

enter image description here

Then you can split your data based on the output and see the output distributions separability. This will give you information regarding the importance of each feature for building a classifier.

plt.figure(figsize=(14,5))

plt.subplot(1,2,1)
plt.hist(df['X1'][df['Y'] == 0], bins=3, alpha = 0.7, label = 'Y = 0')
plt.hist(df['X1'][df['Y'] == 1], bins=3, alpha = 0.7, label = 'Y = 1')
plt.ylabel('Distribution')
plt.xlabel('Feature X1')
plt.legend()

plt.subplot(1,2,2)
plt.hist(df['X2'][df['Y'] == 0], bins=3, alpha = 0.7, label = 'Y = 0')
plt.hist(df['X2'][df['Y'] == 1], bins=3, alpha = 0.7, label = 'Y = 1')
plt.ylabel('Distribution')
plt.xlabel('Feature X2')
plt.legend()

plt.show()

enter image description here

From this point we can see that feature X2 alone is useless in classifying Y. However, when we consider both X1 and X2 on the output we can see that X2 can help us make a better prediction of Y. We can see a linear separator would do the trick for this data.

plt.scatter(df['X1'], df['X2'], c = df['Y'], cmap = 'autumn')
plt.ylabel('Feature X2')
plt.xlabel('Feature X1')
plt.colorbar()
plt.show()

enter image description here

$\endgroup$
1
$\begingroup$

There is package named Boruta in R/Python. This is also called as predictor importance test. Used to pick the important variable.

Uses of this package:

Boruta is a feature selection algorithm. Precisely, it works as a wrapper algorithm around Random Forest. This package derive its name from a demon in Slavic mythology who dwelled in pine forests.

We know that feature selection is a crucial step in predictive modeling. This technique achieves supreme importance when a data set comprised of several variables is given for model building.

Boruta can be your algorithm of choice to deal with such data sets. Particularly when one is interested in understanding the mechanisms related to the variable of interest, rather than just building a black box predictive model with good prediction accuracy.

The outcome would be a box whisker plot with their importance with the target variable. You need not worry about categorical and continuous variables. you just need to cast them correctly before passing the data to the algorithm.

You can go through this Link for better understanding on the package and implementation of the same.

This is the sample plot: sample plot Let me know if you need any additional information.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.