Multiple regression expressions in Python

Task

No. Degree of orientation temperature pressure
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

Method

Contents

stat.py


# coding: UTF-8
import numpy as np

def stat(obj, exp):

    n = exp.shape[1]

    exp = np.vstack([np.ones(n), exp]) #Constant term, explanatory variable

    coef = np.linalg.lstsq(exp.T, obj)[0] #Partial regression coefficient

    return coef

if __name__ == '__main__':

    f = (45, 38, 41, 34, 59, 47, 35, 43, 54, 52)                     #Degree of orientation
    t = (17.5, 17.0, 18.5, 16.0, 19.0, 19.5, 16.0, 18.0, 19.0, 19.5) #temperature
    p = (30, 25, 20, 30, 45, 35, 25, 35, 35, 40)                     #pressure

    obj = np.array(f)      #Objective variable
    exp = np.array([t, p]) #Explanatory variable

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

    print "Multiple regression equation:Degree of orientation= %f + %f*temperature+ %f*pressure" % (b0, bt, bp)
> python stat.py 
Multiple regression equation:Degree of orientation= -34.712931 + 3.469813*temperature+ 0.533009*pressure

reference

Recommended Posts

Multiple regression expressions in Python
Regression analysis in Python
Use regular expressions in Python
Wrap long expressions in python
Simple regression analysis in Python
Avoid multiple loops in Python
Online linear regression in Python
Prohibit multiple launches in python
2. Multivariate analysis spelled out in Python 2-1. Multiple regression analysis (scikit-learn)
Extract multiple list duplicates in Python
[Python] Show multiple windows in Tkinter
First simple regression analysis in Python
Statistical test (multiple test) in Python: scikit_posthocs
Delete multiple elements in python list
When using regular expressions in Python
Handle multiple python versions in one jupyter
When specifying multiple keys in python sort
Overlapping regular expressions in Python and Java
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Linear regression in Python (statmodels, scikit-learn, PyMC3)
Meta-analysis in Python
difference between statements (statements) and expressions (expressions) in Python
Unittest in python
Online Linear Regression in Python (Robust Estimate)
Predictive statistics (practice edition multiple regression) python
Send email to multiple recipients in Python (Python 3)
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Process multiple lists with for in Python
I implemented Cousera's logistic regression in Python
Plink in Python
[Python] Regular Expressions Regular Expressions
Replace non-ASCII with regular expressions in Python
Constant in python
Don't use \ d in Python 3 regular expressions!
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
2. Multivariate analysis spelled out in Python 2-3. Multiple regression analysis [COVID-19 infection rate]
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3