#NEWLINE# def __init__( self , X , y = None , weights = None , copy = True ) : #NEWLINE# #INDENT# self . _ix_buf = None #NEWLINE# if copy : #NEWLINE# #INDENT# self . _X = X . copy ( ) #NEWLINE# if ( not ( y is None ) ) : #NEWLINE# #INDENT# self . _y = y . copy ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _y = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . _X = X #NEWLINE# self . _y = y #NEWLINE# #UNINDENT# if ( weights is None ) : #NEWLINE# #INDENT# weights = np . ones ( X . shape [ 0 ] ) #NEWLINE# #UNINDENT# if ( not ( type ( weights ) in [ np . array , list , np . ndarray ] ) ) : #NEWLINE# #INDENT# raise TypeError ( 'weights must be a numpy array or a list' ) #NEWLINE# #UNINDENT# if ( len ( weights ) != X . shape [ 0 ] ) : #NEWLINE# #INDENT# raise ValueError ( 'weights must have the same length as the first axis of X' ) #NEWLINE# #UNINDENT# if ( type ( weights ) is list ) : #NEWLINE# #INDENT# self . _weights = np . array ( weights ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _weights = weights #NEWLINE# #UNINDENT# self . _weights [ ( self . _weights < 0 ) ] = 0.0 #NEWLINE# self . _weights = ( self . _weights / np . sum ( self . _weights ) )