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 14,846 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])```
```Step into the AI Future, Enroll now in the GitHub Copilot training today!
```
answered May 22, 2019 by Hari

0 votes
1 answer

## What is the difference between linear regression and logistic regression?

Hi Dev, to answer your question Linear Regression ...READ MORE

0 votes
1 answer

## Alternatives to linear regression for dataset with many points with small value and some extreme values

The above situation is the case where ...READ MORE

0 votes
1 answer

## Python script for linear regression on panda dataframe

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

0 votes
1 answer

## Can someone explain to me the difference between a cost function and the gradient descent equation in logistic regression?

when we train a model with data, ...READ MORE

0 votes
1 answer

## Show python implementation of Lasso class - regression

Hey @Tanmay, try something like this: >>> from ...READ MORE

0 votes
1 answer

## Can you give LassoLars python example?

Hey @Vivek, Try something like this: >>> from ...READ MORE

0 votes
2 answers

## What is supervised learning?

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

0 votes
1 answer

## Difference between reinforcement learning and supervised learning?

In reinforcement learning, the output depends on ...READ MORE

0 votes
1 answer

## When do I use simple exponential smoothing and what is the math behind it?

Hey @Ruth, you can use this model ...READ MORE

0 votes
1 answer

## What is LassoLars? - Linear regression

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