import numpy as np
n, p = [int(x) for x in input().split()]
X = []
for i in range(n):
X.append([float(x) for x in input().split()])
y = [float(x) for x in input().split()]
c=np.array(X)
d=np.array(y)
#A = np.vstack([c, np.ones(len(c))]).T
f=np.round(np.linalg.lstsq(c,d,rcond=None)[0],2)
print(f)
========
Data Science - Ordinary Squares
Ordinary least squares for linear regression.
Ordinary least squares (OLS) is a method to estimate the parameters β in a simple linear regression, Xβ = y, where X is the feature matrix and y is the dependent variable (or target), by minimizing the sum of the squares of the differences between the observed dependent variable in the given dataset and those predicted by the linear function. Mathematically, the solution is given by the formula in the image, where the superscript T means the transpose of a matrix, and the superscript -1 means it is an inverse of a matrix.
Task
Given a 2D array feature matrix X and a vector y, return the coefficient vector; see the formula.
Input Format
First line: two integers separated by spaces, the first indicates the rows of the feature matrix X (n) and the second indicates the columns of X (p)
Next n lines: values of the row in the feature matrix
Last line: p values of target y
Output Format
An numpy 1d array of values rounded to the second decimal.
Sample Input
2 2
1 0
0 2
2 3
Sample Output
[2. , 1.5]
相关推荐
2022Fall - Courses - Ordinary Differential Equations 1(1).md
npm install --save-dev react-ordinary-calendar 用法 import React from 'react' ; import ReactDOM from 'react-dom' ; import Calendar from 'react-ordinary-calendar' ; let wrapper = document . ...
Numerical Python: Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib By 作者: Robert Johansson ISBN-10 书号: 1484242459 ISBN-13 书号: 9781484242452 Edition 版本: 2nd ...
神经歧管常微分方程(ODE) 我们在此存储库中提供了的代码。 摘要:我们介绍了神经流形常微分方程,神经ODE的流形泛化,并构造了流形连续归一化流(MCNF)。 MCNF仅需要局部几何形状(因此可以推广到任意歧管),...
ordinary-and-partial-differential-equation-routines-in-c-c-fortran-java-maple-and-matlab.pdf
Data Science and Analytics for Ordinary People.pdf ebook.7z.tmp Econometrics Streamlined, Applied and e-Aware.pdf Forecasting in Economics, Business, Finance and Beyond.pdf Foundations of Data Science...
1C:用于普通应用程序的GitConverter 1C扩展1C 允许您转换“常规应用程序”的配置。 注意力! EDT不支持使用“普通应用程序”启动模式开发配置,但要转换1C存储的历史记录(其中配置的初始版本可能包含此设置),则...
matlab的egde源代码
Ordinary differential equations and dynamical systems-G. Teschl
• Linear and nonlinear least-squares fitting • Ordinary differential equations • Special functions • Statistics (descriptive statistics, hypothesis testing) • Data ...
Research of assembling optimized classification algorithm by neural network based on Ordinary Least Squares (OLS)
Robinson - An Introduction to Ordinary Differential Equations.pdf
The 25Q series offers flexibility and performance well beyond ordinary Serial Flash devices. They are ideal for code shadowing to RAM, executing code directly from Dual/Quad SPI (XIP) and storing ...
二阶盲分离算法,包括AMUSE、SOBI、JADER、EFICA、ERICA、WASOBI等,代码详细,由注释,便于理解学习。
Neural Ordinary Differential Equations 这是一篇论文
Anyone who may be called upon to produce a report based on database data can profit from the information contained in this book. It’s also valuable to managers who may never personally produce a ...
Solving Ordinary Differential Equations I全书资源
Ordinary_Differential_Equations_V.Arnold,djv文件,用WinDjView查看。
《Ordinary Differential Equations》——William A. Adkins;图书教材;常微分方程
SUMS61 Ordinary Differential Equations -- Analysis, Qualitative Theory and Control, Hartmut Logemann, Eugene P. Ryan (2014).zip