我的线性回归模型无法适应,需要2D数组

2024-06-26 01:55:13 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有两个1D数组,我需要绘制它们的线性回归模型,以了解它们的趋势,所以我有以下代码:

from brian2 import *
%matplotlib inline
from sklearn.linear_model import LinearRegression

start_scope()

reg = LinearRegression()
reg.fit(rates, R)
reg.coef_

#rates and R were issued beforehand

figure(figsize=(36,12))
subplot(121)
plot(rates,R,'o','b',reg,'r' )
xlabel('Time (ms)')
ylabel('V (mV)')
title("M.I. - firing rate evolution")
ylim((0,35))

然后我得到一个错误:

^{pr2}$

有人能帮我理解吗?在


Tags: 代码from模型importmatplotlib绘制inline线性
1条回答
网友
1楼 · 发布于 2024-06-26 01:55:13

如错误中所述,您可以使用

import numpy as np
rates=np.array(rates).reshape(-1, 1) 
reg = LinearRegression()
reg.fit(rates, R)
reg.coef_

另外,我猜你只有一个特性可以作为回归模型的预测因子。

相关问题 更多 >