def random_effect( df , group , X_cols , Y_cols ): """ 変量効果モデル(※ではない。今後修正) """ fixed = _convert( df=df , group=group ) params = {} for key , value in fixed.items(): X = lib.df2mat( df=value , columns=X_cols ) Y = lib.df2mat( df=value , columns=Y_cols ) b = lib.reg( X=X , Y=Y ) params[key] = b return params
import lib import sys import numpy as np """ 6 Inference2 """ lib.title("#############6 Inference2#############") #####データを読み取る##### HPRICE_dataset = lib.load(filename="HPRICE1.csv") explanatories = ["const", "sqrft", "bdrms"] explained = ["lprice"] #####各変数を定義##### X = lib.df2mat(df=HPRICE_dataset, columns=explanatories) Y = lib.df2mat(df=HPRICE_dataset, columns=explained) b = lib.reg(X=X, Y=Y) """ 6-1の解答 """ lib.chaper("<6.1の解答>") #####解答##### lib.add_suffix(b, labels=explanatories) print("\n") """ 6-2の解答 """ lib.chaper("<6.2の解答>") #####回帰係数の取得##### const, sqrft, bdrms = b[0], b[1], b[2] y_bdrms = bdrms