24.07.2016 Views

www.allitebooks.com

Learning%20Data%20Mining%20with%20Python

Learning%20Data%20Mining%20with%20Python

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Extracting Features with Transformers<br />

We then create a mask of all of the samples that belong to the current class:<br />

mask = (y == cur_class).values<br />

Finally, we use the scatter function in pyplot to show where these are. We use the<br />

first two features as our x and y values in this plot.<br />

plt.scatter(Xd[mask,0], Xd[mask,1], marker='o', color=color,<br />

label=int(cur_class))<br />

Finally, outside the loop, we create a legend and show the graph, showing where the<br />

samples from each class appear:<br />

plt.legend()<br />

plt.show()<br />

Creating your own transformer<br />

As the <strong>com</strong>plexity and type of dataset changes, you might find that you can't find an<br />

existing feature extraction transformer that fits your needs. We will see an example<br />

of this in Chapter 7, Discovering Accounts to Follow Using Graph Mining, where we<br />

create new features from graphs.<br />

[ 98 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!