第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用已知指數(shù)擬合冪律并在 Python 中提取系數(shù)

用已知指數(shù)擬合冪律并在 Python 中提取系數(shù)

不負相思意 2021-11-23 16:23:05
我有一個數(shù)據(jù)集,我知道它適合以下形式的曲線:y = a x2我想提取a.在 Python(使用 scipy 等)中解決這個問題的最佳方法是什么?
查看完整描述

1 回答

?
慕的地6264312

TA貢獻1817條經(jīng)驗 獲得超6個贊

這是使用 scipy 的 curve_fit() 的圖形擬合器示例:


import numpy, scipy, matplotlib

import matplotlib.pyplot as plt

from scipy.optimize import curve_fit


xData = numpy.array([1.1, 2.2, 3.3, 4.4, 5.0, 6.6, 7.7])

yData = numpy.array([1.1, 20.2, 30.3, 60.4, 50.0, 60.6, 70.7])



def func(x, a):

    return (a * numpy.square(x))



# same as the scipy default

initialParameters = numpy.array([1.0])


# curve fit the test data

fittedParameters, pcov = curve_fit(func, xData, yData, initialParameters)


modelPredictions = func(xData, *fittedParameters) 


absError = modelPredictions - yData


SE = numpy.square(absError) # squared errors

MSE = numpy.mean(SE) # mean squared errors

RMSE = numpy.sqrt(MSE) # Root Mean Squared Error, RMSE

Rsquared = 1.0 - (numpy.var(absError) / numpy.var(yData))


print('Parameters:', fittedParameters)

print('RMSE:', RMSE)

print('R-squared:', Rsquared)


print()



##########################################################

# graphics output section

def ModelAndScatterPlot(graphWidth, graphHeight):

    f = plt.figure(figsize=(graphWidth/100.0, graphHeight/100.0), dpi=100)

    axes = f.add_subplot(111)


    # first the raw data as a scatter plot

    axes.plot(xData, yData,  'D')


    # create data for the fitted equation plot

    xModel = numpy.linspace(min(xData), max(xData))

    yModel = func(xModel, *fittedParameters)


    # now the model as a line plot

    axes.plot(xModel, yModel)


    axes.set_xlabel('X Data') # X axis data label

    axes.set_ylabel('Y Data') # Y axis data label


    plt.show()

    plt.close('all') # clean up after using pyplot


graphWidth = 800

graphHeight = 600

ModelAndScatterPlot(graphWidth, graphHeight)



查看完整回答
反對 回復 2021-11-23
  • 1 回答
  • 0 關注
  • 219 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號