duckertito duckertito - 1 year ago 149
Python Question

Creation of scatter_matrix

I want to get a chart similar to the one pubished here. In my dataset I have 3 features and 1 binary target. When target=0, then the dots should be colored e.g. in red. When target=1, then the dots should be colored e.g. in blue.

When I run this code, it looks like all dots have the same color:

from import scatter_matrix
scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')

How to I specify different colors for target values 0 and 1, so that I can observe possible groupings?

Answer Source

To plot this data using the pandas plotting tools, as you are now, pass color=['blue' if target == 1 else 'red'] as an argument.

However, I recommending using the seaborn pairplot facility instead. This will result in a plot that is much closer to the one in the tutorial, and to colorize based on a data point you need only specify hue='my_data_column' as a parameter. Cf. here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download