<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import scipy . sparse as sp <EOL> from sklearn . utils . testing import assert_equal <EOL> from sklearn . utils . testing import assert_true <EOL> from sklearn . utils . testing import SkipTest <EOL> from sklearn import datasets <EOL> def test_20news ( ) : <EOL> try : <EOL> data = datasets . fetch_20newsgroups ( <EOL> subset = '<STR_LIT:all>' , download_if_missing = False , shuffle = False ) <EOL> except IOError : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> data2cats = datasets . fetch_20newsgroups ( <EOL> subset = '<STR_LIT:all>' , categories = data . target_names [ - <NUM_LIT:1> : - <NUM_LIT:3> : - <NUM_LIT:1> ] , shuffle = False ) <EOL> assert_equal ( data2cats . target_names , <EOL> data . target_names [ - <NUM_LIT:2> : ] ) <EOL> assert_equal ( np . unique ( data2cats . target ) . tolist ( ) , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> assert_equal ( len ( data2cats . filenames ) , len ( data2cats . target ) ) <EOL> assert_equal ( len ( data2cats . filenames ) , len ( data2cats . data ) ) <EOL> entry1 = data2cats . data [ <NUM_LIT:0> ] <EOL> category = data2cats . target_names [ data2cats . target [ <NUM_LIT:0> ] ] <EOL> label = data . target_names . index ( category ) <EOL> entry2 = data . data [ np . where ( data . target == label ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ] <EOL> assert_equal ( entry1 , entry2 ) <EOL> def test_20news_length_consistency ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> data = datasets . fetch_20newsgroups ( <EOL> subset = '<STR_LIT:all>' , download_if_missing = False , shuffle = False ) <EOL> except IOError : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> data = datasets . fetch_20newsgroups ( subset = '<STR_LIT:all>' ) <EOL> assert_equal ( len ( data [ '<STR_LIT:data>' ] ) , len ( data . data ) ) <EOL> assert_equal ( len ( data [ '<STR_LIT:target>' ] ) , len ( data . target ) ) <EOL> assert_equal ( len ( data [ '<STR_LIT>' ] ) , len ( data . filenames ) ) <EOL> def test_20news_vectorized ( ) : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> bunch = datasets . fetch_20newsgroups_vectorized ( subset = "<STR_LIT:train>" ) <EOL> assert_true ( sp . isspmatrix_csr ( bunch . data ) ) <EOL> assert_equal ( bunch . data . shape , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert_equal ( bunch . target . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( bunch . data . dtype , np . float64 ) <EOL> bunch = datasets . fetch_20newsgroups_vectorized ( subset = "<STR_LIT:test>" ) <EOL> assert_true ( sp . isspmatrix_csr ( bunch . data ) ) <EOL> assert_equal ( bunch . data . shape , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert_equal ( bunch . target . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( bunch . data . dtype , np . float64 ) <EOL> bunch = datasets . fetch_20newsgroups_vectorized ( subset = "<STR_LIT:all>" ) <EOL> assert_true ( sp . isspmatrix_csr ( bunch . data ) ) <EOL> assert_equal ( bunch . data . shape , ( <NUM_LIT> + <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert_equal ( bunch . target . shape [ <NUM_LIT:0> ] , <NUM_LIT> + <NUM_LIT> ) <EOL> assert_equal ( bunch . data . dtype , np . float64 ) </s>
