Ignore the NaN and do the linear regression on remaining values

0 votes

Is there a way to ignore the NaN and do the linear regression on remaining values?

val=([0,2,1,'NaN',6],[4,4,7,6,7],[9,7,8,9,10])
time=[0,1,2,3,4]
slope_1 = stats.linregress(time,values[1]) # This works
slope_0 = stats.linregress(time,values[0]) # This doesn't work

May 22 in Machine Learning by Michel
42 views

1 answer to this question.

0 votes

Yes, you can do this using statsmodels:

import statsmodels.api as sm
from numpy import NaN
x = [0, 2, NaN, 4, 5, 6, 7, 8]
y = [1, 3, 4,   5, 6, 7, 8, 9]
model = sm.OLS(y, x, missing='drop')
results = model.fit()
In [2]: results.params
Out[2]: array([ 1.16494845])
answered May 22 by Hari

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What is rolling linear regression?

Rolling regression is the analysis of changing ...READ MORE

answered May 23 in Machine Learning by Jinu
33 views
0 votes
1 answer

What is supervised learning?

Supervised learning is an aspect of machine learning ...READ MORE

answered May 8 in Data Analytics by Alok
22 views
0 votes
1 answer