尝试使用 numpy.polyfit 计算线性回归的方程式,但得到的值太多无法解包(预期为 2)
Trying to calculate de equation for linear regression with numpy.polyfit but getting too many values to unpack (expected 2)
我需要阅读“Horas Estudo”专栏和数字 (x) = 5.95,然后计算 y= ax + b.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_csv("https://www.dropbox.com/s/k3owtgaywmjhk66/fake-classrooms-correl03.csv?dl=1")
col = input()
x = round(float(input()),2)
(a,b) = np.polyfit(df[col],df["Nota Final"], deg=2)
print(a,b)
ValueError Traceback (most recent call last)
<ipython-input-81-7e077f926863> in <module>()
7 x = round(float(input()),2)
8
----> 9 (a,b) = np.polyfit(df[col],df["Nota Final"], deg=2)
10 print(a,b)
ValueError: too many values to unpack (expected 2)
np.polyfit returns ndarray 而非元组形式的多项式系数。所以在左边放一个单一的变量并打印出来。
此外,如果您试图找到线性拟合 (y=ax+b),请将 deg=1 放入函数调用
我需要阅读“Horas Estudo”专栏和数字 (x) = 5.95,然后计算 y= ax + b.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_csv("https://www.dropbox.com/s/k3owtgaywmjhk66/fake-classrooms-correl03.csv?dl=1")
col = input()
x = round(float(input()),2)
(a,b) = np.polyfit(df[col],df["Nota Final"], deg=2)
print(a,b)
ValueError Traceback (most recent call last)
<ipython-input-81-7e077f926863> in <module>()
7 x = round(float(input()),2)
8
----> 9 (a,b) = np.polyfit(df[col],df["Nota Final"], deg=2)
10 print(a,b)
ValueError: too many values to unpack (expected 2)
np.polyfit returns ndarray 而非元组形式的多项式系数。所以在左边放一个单一的变量并打印出来。 此外,如果您试图找到线性拟合 (y=ax+b),请将 deg=1 放入函数调用