Skip to Main Content
Python 机器学习实践:测试驱动的开发方法
book

Python 机器学习实践:测试驱动的开发方法

by Matthew Kirk
January 2018
Intermediate to advanced content levelIntermediate to advanced
211 pages
8h 31m
Chinese
China Machine Press
Content preview from Python 机器学习实践:测试驱动的开发方法
朴素贝叶斯分类
55
import email
from BeautifulSoup import BeautifulSoup
class EmailObject:
def __init__(self, filepath, category = None):
self.filepath = filepath
self.category = category
self.mail = email.message_from_file(self.filepath)
def subject(self):
return self.mail.get('Subject')
def body(self):
return self.mail.get_payload(decode=True)
BeautifulSoup is a library that parses HTML and XML.
Now that we have captured the case of plaintext, we need to solve the case of HTML.
For that, we want to capture only the
inner_text. But first we need a test case, which
looks something like this:
import unittest
import io
import re
from BeautifulSoup import BeautifulSoup ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Bioinformatics

Mastering Python for Bioinformatics

Ken Youens-Clark

Publisher Resources

ISBN: 9787111581666