Error in linear regression for multiple data-frames with matplotlib
1
0
Entering edit mode
2.1 years ago
Amr ▴ 180

Error in linear regression for multiple data-frames with matplotlib

I want to make a 3 linear regression lines for different 3 data-frames one per each. there is one data-frame that has NA values maybe that's why an error has raised:

ValueError                                Traceback (most recent call last)
ValueError: On entry to DLASCL parameter number 4 had an illegal value

How to fix that error so that I am able to make 3 regression lines one per each data?

lo_sig = -1 *np.log2(df_significance['p.adjustMANOVA'])

lo_eff = -1 *np.log2(df_effect['p.adjustMANOVA'])

lo_sd = -1 *np.log2(df_sd['p.adjustMANOVA'])

df = pd.DataFrame({'Significance':lo_sig,'Effect_size':lo_eff,'Standard_deviation':lo_sd})

lo_sig2 = df_significance['s.dist']
lo_eff2 = df_effect['s.dist']
lo_sd2 = df_sd['s.dist']

df2 = pd.DataFrame({'Significance':lo_sig2,'Effect_size':lo_eff2,'Standard_deviation':lo_sd2})

ax.grid()


plt.scatter(y = df['Significance'],x = df2['Significance'], label='Significance', color='mediumseagreen',s=250)

plt.scatter(y = df['Effect_size'],x = df2['Effect_size'], label='Effect_size', color='indianred',s= 100)

plt.scatter(y = df['Standard_deviation'],x = df2['Standard_deviation'], label='Standard_deviation', color='orange',s = 20)

#Linear regression

a, b = np.polyfit(df2['Significance'], df['Significance'], 1)

plt.plot(df2['Significance'], a*df2['Significance'] + b,color = 'mediumseagreen', linewidth=4)

c, d = np.polyfit(df2['Effect_size'], df['Effect_size'], 1)

plt.plot(df2['Effect_size'], c*df2['Effect_size'] + d,color = 'indianred',linewidth=2)

e, f = np.polyfit(df2['Standard_deviation'], df['Standard_deviation'], 1)

#Here is the error

plt.plot(df2['Standard_deviation'], e*df2['Standard_deviation'] + f,color = 'blue',linewidth=4)

plt.show()

Thanks

linear_regression matplotlib • 893 views
ADD COMMENT
1
Entering edit mode
2.1 years ago
Amr ▴ 180

The solution is to drop NA values and the regression line will be plotted, NA removed by df.dropna()

ADD COMMENT

Login before adding your answer.

Traffic: 2033 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6