<s> import numpy as np <EOL> from sys import stderr <EOL> from time import time <EOL> class _TfBaseRegressor ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , print_progress = <NUM_LIT:0> , random_seed = None ) : <EOL> self . print_progress = print_progress <EOL> self . random_seed = random_seed <EOL> self . _is_fitted = False <EOL> def fit ( self , X , y , init_weights = True ) : <EOL> """<STR_LIT>""" <EOL> self . _is_fitted = False <EOL> if not ( init_weights is None or isinstance ( init_weights , bool ) ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> self . _check_arrays ( X = X , y = y ) <EOL> if self . random_seed is not None : <EOL> np . random . seed ( self . random_seed ) <EOL> self . _fit ( X = X , y = y , init_weights = init_weights ) <EOL> self . _is_fitted = True <EOL> return self <EOL> def _fit ( self , X , y , init_weights = True ) : <EOL> pass <EOL> def predict ( self , X ) : <EOL> """<STR_LIT>""" <EOL> self . _check_arrays ( X ) <EOL> if not self . _is_fitted : <EOL> raise AttributeError ( '<STR_LIT>' ) <EOL> return self . _predict ( X ) <EOL> def _predict ( self , X ) : <EOL> pass <EOL> def _shuffle ( self , arrays ) : <EOL> """<STR_LIT>""" <EOL> r = np . random . permutation ( len ( arrays [ <NUM_LIT:0> ] ) ) <EOL> return [ ary [ r ] for ary in arrays ] <EOL> def _print_progress ( self , epoch , cost = None , time_interval = <NUM_LIT:10> ) : <EOL> if self . print_progress > <NUM_LIT:0> : <EOL> s = '<STR_LIT>' % ( epoch , self . epochs ) <EOL> if cost : <EOL> s += '<STR_LIT>' % cost <EOL> if self . print_progress > <NUM_LIT:1> : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . ela_str_ = '<STR_LIT>' <EOL> if not epoch % time_interval : <EOL> ela_sec = time ( ) - self . init_time_ <EOL> self . ela_str_ = self . _to_hhmmss ( ela_sec ) <EOL> s += '<STR_LIT>' % self . ela_str_ <EOL> if self . print_progress > <NUM_LIT:2> : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . eta_str_ = '<STR_LIT>' <EOL> if not epoch % time_interval : <EOL> eta_sec = ( ( ela_sec / float ( epoch ) ) * <EOL> self . epochs - ela_sec ) <EOL> self . eta_str_ = self . _to_hhmmss ( eta_sec ) <EOL> s += '<STR_LIT>' % self . eta_str_ <EOL> stderr . write ( s ) <EOL> stderr . flush ( ) <EOL> def _to_hhmmss ( self , sec ) : <EOL> m , s = divmod ( sec , <NUM_LIT> ) <EOL> h , m = divmod ( m , <NUM_LIT> ) <EOL> return "<STR_LIT>" % ( h , m , s ) <EOL> def _check_arrays ( self , X , y = None ) : <EOL> if isinstance ( X , list ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not len ( X . shape ) == <NUM_LIT:2> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> try : <EOL> if y is None : <EOL> return <EOL> except ( AttributeError ) : <EOL> pass <EOL> else : <EOL> if not isinstance ( y , np . ndarray ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not len ( y . shape ) == <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not len ( y ) == X . shape [ <NUM_LIT:0> ] : <EOL> raise ValueError ( '<STR_LIT>' ) </s>
