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) # This works
slope_0 = stats.linregress(time,values) # This doesn't work``` May 22, 2019 4,700 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 : results.params
Out: array([ 1.16494845])``` answered May 22, 2019 by Hari

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

## Python code for basic linear regression

Hi @Dipti, you could try something like ...READ MORE

0 votes
1 answer

## Create dataframe using Pandas - Linear Regression

You can read excel files df = pd.read_excel(...) You ...READ MORE

0 votes
1 answer

## What is rolling linear regression?

Rolling regression is the analysis of changing ...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