Scipy Draw 指数 - 我如何更好地适应它?

我是 Python 绘图的新手,所以请耐心等待。我今天搜索并阅读了很多,但无法弄清楚这一点。


import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

from scipy.optimize import curve_fit


def exp_func(x,a,b,c):

    return a*np.exp(-b*x)+c


x = np.array(df_auction_cat['AgeAdj'])

y = np.array(df_auction_cat['SP/ABCost'])


plt.scatter(x, y, s=50, cmap='Blues', alpha=0.7, edgecolor='gray', linewidth=1)

popt, pcov = curve_fit(exp_func, x, y)

plt.plot(x, exp_func(x, *popt))

在前面的代码中,我处理了一些数据并将 df_auction_cat 数据集放在一起。散布看起来像这样,指数根本不适合:

http://img.mukewang.com/616e26000001a96f16470926.jpg

任何帮助将非常感激。数据点如下:


AgeAdj SP/ABCost

26 0.051851813

8 0.342104363

28 0.142081738

23 0.1

22 0.056330527

19 0.157692308

18 0.157301407

17 0.15

17 0.236690872

17 0.173041737

14 0.223076923

12 0.247294549

12 0.242445636

10 0.464864865

17 0.233333333

17 0.253333333

10 0.292307692

28 0.126554024

19 0.322973634

14 0.270684988

18 0.174560858

12 0.203654335

23 0.133144882

17 0.119076601

12 0.381578947

17 0.232747811

14 0.365465999

11 0.574056541

19 0.153471963

29 0.128023925

15 0.164999835

28 0.140513444

22 0.089770069

16 0.16001412

15 0.283422611


喵喔喔
浏览 369回答 2
2回答

呼唤远方

我创建了自己的 x、y 并工作,你能发布你的输入数据吗?import numpy as npimport matplotlib.pyplot as pltimport pandas as pdfrom scipy.optimize import curve_fitdef exp_func(x,a,b,c):    return a*np.exp(-b*x)+cx = np.array(range(0,100))y = np.array(exp_func(x,0.1,0.1,.1)*50+np.random.rand(100))plt.scatter(x, y, s=50, cmap='Blues', alpha=0.7, edgecolor='gray', linewidth=1)popt, pcov = curve_fit(exp_func,x, y)plt.plot(x, exp_func(x, *popt))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python