#NEWLINE# def trainModel( self , train ) : #NEWLINE# #INDENT# instances = train . get_features ( ) #NEWLINE# ones = np . ones ( ( instances . shape [ 0 ] , 1 ) ) #NEWLINE# instances = np . matrix ( np . concatenate ( ( ones , instances ) , axis = 1 ) ) #NEWLINE# targets = np . array ( train . get_targets ( ) ) #NEWLINE# xTx = np . dot ( instances . T , instances ) #NEWLINE# xTx += np . dot ( self . __complexity , np . eye ( xTx . shape [ 0 ] , xTx . shape [ 1 ] ) ) #NEWLINE# xTy = np . dot ( instances . T , targets ) #NEWLINE# solution = np . linalg . lstsq ( xTx , xTy ) #NEWLINE# self . __model = solution [ 0 ] #NEWLINE# self . __rss = 0 #NEWLINE# self . __rmse = np . sqrt ( ( self . __rss / ( train . get_numInstances ( ) - 2 ) ) )