<s> '''<STR_LIT>''' <EOL> from __future__ import print_function <EOL> import six <EOL> import numpy as np <EOL> import sklearn <EOL> import sklearn . cluster <EOL> import sklearn . linear_model <EOL> import sklearn . datasets <EOL> import pescador <EOL> from nose . tools import raises <EOL> def generate_data ( size = <NUM_LIT:32> , supervised = True ) : <EOL> data = sklearn . datasets . load_iris ( ) <EOL> X , Y = data . data , data . target <EOL> n , d = X . shape <EOL> while True : <EOL> i = np . random . randint ( <NUM_LIT:0> , n , size = size ) <EOL> noise = np . random . randn ( size , d ) <EOL> if supervised : <EOL> yield { '<STR_LIT:X>' : X [ i ] + noise , '<STR_LIT:Y>' : Y [ i ] } <EOL> else : <EOL> yield { '<STR_LIT:X>' : X [ i ] + noise } <EOL> def test_unsupervised ( ) : <EOL> def __test ( sup , max_steps ) : <EOL> stream = pescador . Streamer ( generate_data , supervised = sup ) <EOL> estimator = sklearn . cluster . MiniBatchKMeans ( ) <EOL> model = pescador . StreamLearner ( estimator , max_steps = max_steps ) <EOL> model . iter_fit ( stream . generate ( max_batches = <NUM_LIT:100> ) ) <EOL> for sup in [ False , True ] : <EOL> for max_steps in [ - <NUM_LIT:1> , None , <NUM_LIT:1> ] : <EOL> if not sup and max_steps != - <NUM_LIT:1> : <EOL> yield __test , sup , max_steps <EOL> else : <EOL> yield ( raises ( RuntimeError , AssertionError ) ( __test ) , <EOL> sup , max_steps ) <EOL> def test_supervised ( ) : <EOL> def __test ( sup , max_steps ) : <EOL> stream = pescador . Streamer ( generate_data , supervised = sup ) <EOL> estimator = sklearn . linear_model . SGDClassifier ( ) <EOL> model = pescador . StreamLearner ( estimator , max_steps = max_steps ) <EOL> model . iter_fit ( stream . generate ( max_batches = <NUM_LIT:100> ) , <EOL> classes = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> for sup in [ False , True ] : <EOL> for max_steps in [ - <NUM_LIT:1> , None , <NUM_LIT:1> ] : <EOL> if sup and max_steps != - <NUM_LIT:1> : <EOL> yield __test , sup , max_steps <EOL> else : <EOL> yield ( raises ( RuntimeError , AssertionError ) ( __test ) , <EOL> sup , max_steps ) </s>
