10.11.2016 Views

Learning Data Mining with Python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Getting Started <strong>with</strong> <strong>Data</strong> <strong>Mining</strong><br />

We can then print out the top five rules:<br />

for index in range(5):<br />

print("Rule #{0}".format(index + 1))<br />

premise, conclusion = sorted_support[index][0]<br />

print_rule(premise, conclusion, support, confidence, features)<br />

The result will look like the following:<br />

Similarly, we can print the top rules based on confidence. First, compute the sorted<br />

confidence list:<br />

sorted_confidence = sorted(confidence.items(), key=itemgetter(1),<br />

reverse=True)<br />

Next, print them out using the same method as before. Note the change to<br />

sorted_confidence on the third line;<br />

for index in range(5):<br />

print("Rule #{0}".format(index + 1))<br />

premise, conclusion = sorted_confidence[index][0]<br />

print_rule(premise, conclusion, support, confidence, features)<br />

[ 14 ]

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

Saved successfully!

Ooh no, something went wrong!