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, 2019 in Machine Learning by Michel
8,757 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, 2019 by Hari

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer

Python script for linear regression on panda dataframe

Use the following code: from scipy import stats slope, ...READ MORE

answered May 23, 2019 in Machine Learning by Imran
1,252 views
0 votes
1 answer
0 votes
2 answers

What is supervised learning?

Supervised learning is the machine learning task ...READ MORE

answered Sep 3, 2019 in Data Analytics by anonymous
• 33,010 points
543 views
0 votes
1 answer
0 votes
1 answer

What is LassoLars? - Linear regression

LassoLars is a lasso model implemented using ...READ MORE

answered May 22, 2019 in Machine Learning by Basu
1,435 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP