forked from scikit-learn/scikit-learn
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into multiple_grid_search
Conflicts: sklearn/cross_validation.py sklearn/feature_selection/rfe.py sklearn/grid_search.py sklearn/learning_curve.py sklearn/metrics/scorer.py sklearn/metrics/tests/test_score_objects.py sklearn/tests/test_grid_search.py
- Loading branch information
Showing
32 changed files
with
1,487 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# cruft | ||
.*.swp | ||
*.pyc | ||
.DS_Store | ||
|
||
# folder to be used for working on the exercises | ||
workspace | ||
|
||
# output of the sphinx build of the documentation | ||
tutorial/_build | ||
|
||
# datasets to be fetched from the web and cached locally | ||
data/twenty_newsgroups/20news-bydate.tar.gz | ||
data/twenty_newsgroups/20news-bydate-train | ||
data/twenty_newsgroups/20news-bydate-test | ||
|
||
data/movie_reviews/txt_sentoken | ||
data/movie_reviews/poldata.README.2.0 | ||
|
||
data/languages/paragraphs | ||
data/languages/short_paragraphs | ||
data/languages/html | ||
|
||
data/labeled_faces_wild/lfw_preprocessed/ |
105 changes: 105 additions & 0 deletions
105
doc/tutorial/text_analytics/data/languages/fetch_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
# simple python script to collect text paragraphs from various languages on the | ||
# same topic namely the Wikipedia encyclopedia itself | ||
|
||
import os | ||
try: | ||
# Python 2 compat | ||
from urllib2 import Request, build_opener | ||
except ImportError: | ||
# Python 3 | ||
from urllib.request import Request, build_opener | ||
|
||
import lxml.html | ||
from lxml.etree import ElementTree | ||
import numpy as np | ||
|
||
pages = { | ||
u'ar': u'http://ar.wikipedia.org/wiki/%D9%88%D9%8A%D9%83%D9%8A%D8%A8%D9%8A%D8%AF%D9%8A%D8%A7', | ||
u'de': u'http://de.wikipedia.org/wiki/Wikipedia', | ||
u'en': u'http://en.wikipedia.org/wiki/Wikipedia', | ||
u'es': u'http://es.wikipedia.org/wiki/Wikipedia', | ||
u'fr': u'http://fr.wikipedia.org/wiki/Wikip%C3%A9dia', | ||
u'it': u'http://it.wikipedia.org/wiki/Wikipedia', | ||
u'ja': u'http://ja.wikipedia.org/wiki/Wikipedia', | ||
u'nl': u'http://nl.wikipedia.org/wiki/Wikipedia', | ||
u'pl': u'http://pl.wikipedia.org/wiki/Wikipedia', | ||
u'pt': u'http://pt.wikipedia.org/wiki/Wikip%C3%A9dia', | ||
u'ru': u'http://ru.wikipedia.org/wiki/%D0%92%D0%B8%D0%BA%D0%B8%D0%BF%D0%B5%D0%B4%D0%B8%D1%8F', | ||
# u'zh': u'http://zh.wikipedia.org/wiki/Wikipedia', | ||
} | ||
|
||
html_folder = u'html' | ||
text_folder = u'paragraphs' | ||
short_text_folder = u'short_paragraphs' | ||
n_words_per_short_text = 5 | ||
|
||
|
||
if not os.path.exists(html_folder): | ||
os.makedirs(html_folder) | ||
|
||
for lang, page in pages.items(): | ||
|
||
text_lang_folder = os.path.join(text_folder, lang) | ||
if not os.path.exists(text_lang_folder): | ||
os.makedirs(text_lang_folder) | ||
|
||
short_text_lang_folder = os.path.join(short_text_folder, lang) | ||
if not os.path.exists(short_text_lang_folder): | ||
os.makedirs(short_text_lang_folder) | ||
|
||
opener = build_opener() | ||
html_filename = os.path.join(html_folder, lang + '.html') | ||
if not os.path.exists(html_filename): | ||
print("Downloading %s" % page) | ||
request = Request(page) | ||
# change the User Agent to avoid being blocked by Wikipedia | ||
# downloading a couple of articles ones should not be abusive | ||
request.add_header('User-Agent', 'OpenAnything/1.0') | ||
html_content = opener.open(request).read() | ||
open(html_filename, 'wb').write(html_content) | ||
|
||
# decode the payload explicitly as UTF-8 since lxml is confused for some | ||
# reason | ||
html_content = open(html_filename).read() | ||
if hasattr(html_content, 'decode'): | ||
html_content = html_content.decode('utf-8') | ||
tree = ElementTree(lxml.html.document_fromstring(html_content)) | ||
i = 0 | ||
j = 0 | ||
for p in tree.findall('//p'): | ||
content = p.text_content() | ||
if len(content) < 100: | ||
# skip paragraphs that are too short - probably too noisy and not | ||
# representative of the actual language | ||
continue | ||
|
||
text_filename = os.path.join(text_lang_folder, | ||
'%s_%04d.txt' % (lang, i)) | ||
print("Writing %s" % text_filename) | ||
open(text_filename, 'wb').write(content.encode('utf-8', 'ignore')) | ||
i += 1 | ||
|
||
# split the paragraph into fake smaller paragraphs to make the | ||
# problem harder e.g. more similar to tweets | ||
if lang in ('zh', 'ja'): | ||
# FIXME: whitespace tokenizing does not work on chinese and japanese | ||
continue | ||
words = content.split() | ||
n_groups = len(words) / n_words_per_short_text | ||
if n_groups < 1: | ||
continue | ||
groups = np.array_split(words, n_groups) | ||
|
||
for group in groups: | ||
small_content = u" ".join(group) | ||
|
||
short_text_filename = os.path.join(short_text_lang_folder, | ||
'%s_%04d.txt' % (lang, j)) | ||
print("Writing %s" % short_text_filename) | ||
open(short_text_filename, 'wb').write( | ||
small_content.encode('utf-8', 'ignore')) | ||
j += 1 | ||
if j >= 1000: | ||
break | ||
|
27 changes: 27 additions & 0 deletions
27
doc/tutorial/text_analytics/data/movie_reviews/fetch_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Script to download the movie review dataset""" | ||
|
||
import os | ||
import tarfile | ||
try: | ||
from urllib import urlopen | ||
except ImportError: | ||
from urllib.request import urlopen | ||
|
||
|
||
URL = ("http://www.cs.cornell.edu/people/pabo/" | ||
"movie-review-data/review_polarity.tar.gz") | ||
|
||
ARCHIVE_NAME = URL.rsplit('/', 1)[1] | ||
DATA_FOLDER = "txt_sentoken" | ||
|
||
|
||
if not os.path.exists(DATA_FOLDER): | ||
|
||
if not os.path.exists(ARCHIVE_NAME): | ||
print("Downloading dataset from %s (3 MB)" % URL) | ||
opener = urlopen(URL) | ||
open(ARCHIVE_NAME, 'wb').write(opener.read()) | ||
|
||
print("Decompressing %s" % ARCHIVE_NAME) | ||
tarfile.open(ARCHIVE_NAME, "r:gz").extractall(path='.') | ||
os.remove(ARCHIVE_NAME) |
Oops, something went wrong.