23
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonで重回帰式

Last updated at Posted at 2014-03-16

##課題

  • 以下のデータにおいて、配向度を温度と圧力から説明する重回帰式を求める。
No. 配向度 温度 圧力
1 45 17.5 30
2 38 17.0 25
3 41 18.5 20
4 34 16.0 30
5 59 19.0 45
6 47 19.5 35
7 35 16.0 25
8 43 18.0 35
9 54 19.0 35
10 52 19.5 40

##手法

##内容

  • スクリプト
stat.py
# coding: UTF-8
import numpy as np

def stat(obj, exp):

    n = exp.shape[1]

    exp = np.vstack([np.ones(n), exp]) # 定数項、説明変数

    coef = np.linalg.lstsq(exp.T, obj)[0] # 偏回帰係数

    return coef

if __name__ == '__main__':

    f = (45, 38, 41, 34, 59, 47, 35, 43, 54, 52)                     # 配向度
    t = (17.5, 17.0, 18.5, 16.0, 19.0, 19.5, 16.0, 18.0, 19.0, 19.5) # 温度
    p = (30, 25, 20, 30, 45, 35, 25, 35, 35, 40)                     # 圧力

    obj = np.array(f)      # 目的変数
    exp = np.array([t, p]) # 説明変数

    b0, bt, bp = stat(obj, exp)

    print "重回帰式: 配向度 = %f + %f*温度 + %f*圧力" % (b0, bt, bp)
  • 実行結果
> python stat.py 
重回帰式: 配向度 = -34.712931 + 3.469813*温度 + 0.533009*圧力

##参考

23
21
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?