Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
865 views
in Technique[技术] by (71.8m points)

matrix - is there a way to use least squares for 2 arrays in python?ValueError: too many values to unpack (expected 2)

import matplotlib.pyplot as plt
x =np.array([[65, 53, 73, 53, 14, ], [46, 70, 72, 19, 32], [22, 76, 29, 55, 61], [35, 74, 24, 32, 78]])
y =np.array([[900, 785, 969, 681, 206], [632, 850, 941, 326, 487], [334, 963, 430, 784, 769], [487, 954, 351, 461, 856]])


a,b = np.linalg.lstsq(x.transpose(), y.transpose(), rcond=None)[0]
plt.plot(x[0], y, 'go', label='Original data', markersize=10)
plt.plot(x[0], a*x[0] + b, 'r-.', label='Fitted line')

plt.ylabel('υ')
plt.xlabel('κ')
plt.title('Υ vs Κ')
plt.legend(['Original','Least Squares'])
plt.grid(color='k', linestyle=':', linewidth=2)
plt.show()

this is whata i came up with,the problem i suspect is with the arrays.basically i want a plot with a line and markers

question from:https://stackoverflow.com/questions/66045397/is-there-a-way-to-use-least-squares-for-2-arrays-in-pythonvalueerror-too-many

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...