0
$\begingroup$

Im trying to run a linear regression model with Years as the x variable and temperature on the y variable but I keep getting errors. I manage to run a regression model using the below code and also predicting for a future date 2040. But what Im struggling with is to change the data so its running from a specific date, 1950 instead of 1880 which is the original start of the data. How do you change the date range in a linear regression model?

sns.regplot('Year','No_Smoothing',data=df)

x=df.Year
y=df.No_Smoothing
np.array(x).reshape((-1,1))

from sklearn.linear_model import LinearRegression
reg =LinearRegression()
reg.fit(df[['Year']],df.No_Smoothing)
reg.predict([[2040]])
$\endgroup$
1
  • $\begingroup$ if you're analyzing a time series with regression, you should be aware that you're probably violating the autocorrelation assumption $\endgroup$
    – Victor Ng
    Mar 13, 2020 at 19:10

1 Answer 1

0
$\begingroup$

Slice your DataFrame accordingly, and then apply your previous routine (you may want to put this in a function) to this part of the data:

df2 = df.loc[df.Year >= 1950]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.