Pythonクラスの継承:線形回帰を継承してリッジ回帰

f:id:ryamada:20181124160507p:plain

  • クラスを作ると、パイソンのhelp()関数が持つ仕組みと、クラスを作る仕組みが、最上流のクラスに結び付けてくれる仕組とから、クラスの継承構造、Methods、Data descriptorsとを表示してくれる
help(lr) # lrはMyLinRegクラスのインスタンス
help(rr) # rrはMyRidgeRegクラスのインスタンス
Help on MyLinReg in module __main__ object:

class MyLinReg(builtins.object)
 |  Methods defined here:
 |  
 |  __init__(self, X=None, y=None)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  fit(self)
 |      # 回帰係数を求めるインスタンス関数
 |  
 |  input(self, X, y)
 |  
 |  predict(self, X)
 |      # 予測値を返すインスタンス関数
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
Help on MyRidgeReg in module __main__ object:

class MyRidgeReg(MyLinReg)
 |  Method resolution order:
 |      MyRidgeReg
 |      MyLinReg
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, X=None, y=None, lmd=1.0)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  fit(self)
 |      # 回帰係数を求めるインスタンス関数
 |  
 |  setlambda(self, lmd)
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from MyLinReg:
 |  
 |  input(self, X, y)
 |  
 |  predict(self, X)
 |      # 予測値を返すインスタンス関数
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from MyLinReg:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)