How to Excel linear regression of the data matrix operations

Code section:
# -*- coding: utf-8 -*-
import numpy as np
import xlrd
 
path="C:/Users/Desktop/temp/aprotest/2creatmodel/123.xlsx"
data = xlrd.open_workbook(path)
table = data.sheets()[2]
 
cols = table.col_values(0)
cols1 = np.matrix (cols) # list convert the matrix
cols2=np.transpose(cols1)#转置
print cols2
 
cols11 = table.col_values(1)
cols21 = table.col_values(2)
cols31 = table.col_values(3)
cols4 = np.vstack ((cols11, cols21, cols31)) # vstack combined sideways after row, the need transpose
cols5=np.matrix(cols4)
cols6 = np.transpose (cols5) # transpose
print cols6
 
z = np.linalg.inv (cols6.T * cols6) * cols6.T * cols2 # post code duplication show abnormal multiplication
print the
 
Ideas:
First data reading xlrd excel; then convert the data matrix matrix, combined and used for data numpy matrix transpose period; finally do numpy matrix calculation, a linear regression to obtain results.
 
Knowledge points:
The matrix transpose numpy
cols6=np.transpose(cols5)
numpy of data consolidation
cols4 np.vstack = ((cols11, cols21, cols31))
If (cols11, cols21, cols31) has first been used as the matrix transpose, and then merge, it should hstack, rather than vstack.
Can be simply understood as: vstack is the line merger, hstack is the column merger. Specific reference:
 
 

Guess you like

Origin www.cnblogs.com/myshuzhimei/p/12112507.html