【发布时间】:2025-06-04 12:25:01
【问题描述】:
我想创建一个线性回归模型图,显示每年的自行车销量总和,而不是像现在分别有两个点。
这是我的代码:
from sklearn.linear_model import LinearRegression
from sklearn import datasets, linear_model
## Wzrost lub maleje zakup rowerow
## (Purchase of bicycles increases or decreases)
plot1 = df.groupby('Year')['Product_Category'].value_counts().rename('count').reset_index()
x = plot1['Year'].values.reshape(-1, 1)
y = plot1['count'].values.reshape(-1, 1)
# plot #
## linear ##
regr = linear_model.LinearRegression()
regr.fit(x, y)
y_pred = regr.predict(x_test)
#plot#
plt.scatter(x, y, color='black')
plt.plot(x, y, color='blue', linewidth=3)
这是我的情节:
【问题讨论】:
-
所以你想在 y 轴和 x 轴上显示年份??
-
非常好,但我不知道为什么我每年有两个积分而不是一个累积积分
标签: python pandas plot linear-regression sklearn-pandas