Exemplo n.º 1
0
#!-*-coding:utf-8-*-
import lib
import sys
import numpy as np
"""
1 Matrix Calculus
"""
lib.title("#############1 Matrix Calculus#############")
#####データを読み取る#####
artifical_dataset = lib.load(filename="artificial.csv")
explanatories = ["x1", "x2"]
explained = ["y"]

#####各変数を定義#####
X = lib.df2mat(df=artifical_dataset, columns=explanatories)
Y = lib.df2mat(df=artifical_dataset, columns=explained)
b = lib.reg(X=X, Y=Y)
"""
1-1の解答
"""
lib.chaper("<大問1.1の回答>")

#####解答#####
lib.add_suffix(b)
print("\n")
"""
1-2の解答
"""
lib.chaper("<大問1.2の回答>")

#####各変数を定義#####
Exemplo n.º 2
0
#!-*-coding:utf-8-*-
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
Exemplo n.º 3
0
#!-*-coding:utf-8-*-
import lib
import sys
import numpy as np
"""
3 Multiple Regression
"""
lib.title("#############3 Multiple Regression#############")
#####データを読み取る#####
CEOSAL2_dataset = lib.load(filename="CEOSAL2.csv")
explanatories = ["const", "lsales", "lmktval"]
explained = ["lsalary"]
"""
3-1の解答
"""
lib.chaper("大問3.1の回答")
X = lib.df2mat(df=CEOSAL2_dataset, columns=explanatories)
Y = lib.df2mat(df=CEOSAL2_dataset, columns=explained)
b = lib.reg(X=X, Y=Y)
lib.add_suffix(coefs=b, labels=explanatories)
print("\n")
"""
3-2の解答
"""
lib.chaper("大問3.2の回答")
CEOSAL2_dataset = lib.load(filename="CEOSAL2.csv")
explanatories = ["const", "lsales", "lmktval", "profits"]
explained = ["lsalary"]

X = lib.df2mat(df=CEOSAL2_dataset, columns=explanatories)
Y = lib.df2mat(df=CEOSAL2_dataset, columns=explained)
Exemplo n.º 4
0
#!-*-coding:utf-8-*-
import lib
import sys
import numpy as np
"""
2 Simple Regression
"""
lib.title("#############2 Simple Regression#############")
CEOSAL2_dataset = lib.load(filename="CEOSAL2.csv")
explanatories = ["salary"]
explained = ["lsalary"]

#####各変数を定義#####
X = lib.df2mat(df=CEOSAL2_dataset, columns=explanatories)
"""
2-1の解答
"""
lib.chaper("<大問2.1の回答>")
print("Salaryの平均値 :", round(np.average(X), 3))
explanatories = ["ceoten"]
X = lib.df2mat(df=CEOSAL2_dataset, columns=explanatories)
print("Tenureの平均値 :", round(np.average(X), 3))
print("\n")
"""
2-2の解答
"""
lib.chaper("<大問2.2の回答>")
ceoten = CEOSAL2_dataset[CEOSAL2_dataset["ceoten"] <= 0]
ceoten_max = np.max(np.array(CEOSAL2_dataset["ceoten"]))

#####解答#####
Exemplo n.º 5
0
#!-*-coding:utf-8-*-
import lib
import sys
import numpy as np
"""
8 Instrumental Variable And 2SLS
"""
lib.title("#############8 Instrumental Variable And 2SLS#############")

FERTIL2_dataset = lib.load( filename="FERTIL2.csv" )
FERTIL2_dataset = lib.cross_var( df=FERTIL2_dataset , var1="age" , var2="age" )

"""
8-1の解答
"""
lib.chaper("<8.1の解答>")
#####説明変数を定義#####
explanatories = ["const","educ","age","age*age"]
explained = ["children"]

X = lib.df2mat( df=FERTIL2_dataset , columns=explanatories )
Y = lib.df2mat( df=FERTIL2_dataset , columns=explained )
b = lib.reg( X=X , Y=Y )
lib.add_suffix( coefs=b , labels=explanatories )
const , educ , age , age_aqure = b[0] , b[1] , b[2] , b[3]
y = educ * 100

print( y )
print( "9人減る" )

print("\n")
Exemplo n.º 6
0
#!-*-coding:utf-8-*-
import lib
import sys
import numpy as np
"""
5 Inference
"""
lib.title("#############5 Inference#############")
VOTE_dataset = lib.load( filename="VOTE1.csv" )

"""
5-1の解答
"""
lib.chaper("<5.1の解答>")
print("expendAが1%上がると、voteAが100分のβ1だけ上昇する")
print("\n")

"""
5-2の解答
"""
lib.chaper("<5.2の解答>")
print( "β1 - β2 = 0" )
print("\n")

"""
5-3の解答
"""
lib.chaper("<5.3の解答>")
#####説明変数を定義#####
explanatories = ["const","lexpendA","lexpendB","prtystrA"]
explained = ["voteA"]
Exemplo n.º 7
0
#!-*-coding:utf-8-*-
import lib
import sys
import numpy as np
"""
7 Panel Data
"""
lib.title("#############7 Panel Data#############")

grunfeld_dataset = lib.load(filename="grunfeld.csv")
"""
7-1の解答
"""
lib.chaper("<7.1の解答>")
explanatories = ["const", "value", "capital"]
explained = ["invest"]

#B = lib.random_effect( df=grunfeld_dataset , group="year" , X_cols=explanatories , Y_cols=explained )
X = lib.df2mat(df=grunfeld_dataset, columns=explanatories)
Y = lib.df2mat(df=grunfeld_dataset, columns=explained)
b = lib.reg(X=X, Y=Y)
print("提出の時は、βにちゃんと係数をいれましょう ")
lib.add_suffix(coefs=b, labels=explanatories)
print("\n")
"""
7-2の解答
"""
lib.not_done("<7.2の解答>")
print("土屋くんに聞く")
firms = list(set(list(grunfeld_dataset["firm"])))