Python提取曲线函数,python提取曲线数据线

Python 怎么用曲线拟合数据

Python中利用guiqwt进行曲线数据拟合。

创新互联致力于互联网品牌建设与网络营销,包括成都网站制作、成都网站建设、SEO优化、网络推广、整站优化营销策划推广、电子商务、移动互联网营销等。创新互联为不同类型的客户提供良好的互联网应用定制及解决方案,创新互联核心团队十多年专注互联网开发,积累了丰富的网站经验,为广大企业客户提供一站式企业网站建设服务,在网站建设行业内树立了良好口碑。

示例程序:

图形界面如下:

python之KS曲线

# 自定义绘制ks曲线的函数

def plot_ks(y_test, y_score, positive_flag):

# 对y_test,y_score重新设置索引

y_test.index = np.arange(len(y_test))

#y_score.index = np.arange(len(y_score))

# 构建目标数据集

target_data = pd.DataFrame({'y_test':y_test, 'y_score':y_score})

# 按y_score降序排列

target_data.sort_values(by = 'y_score', ascending = False, inplace = True)

# 自定义分位点

cuts = np.arange(0.1,1,0.1)

# 计算各分位点对应的Score值

index = len(target_data.y_score)*cuts

scores = target_data.y_score.iloc[index.astype('int')]

# 根据不同的Score值,计算Sensitivity和Specificity

Sensitivity = []

Specificity = []

for score in scores:

    # 正例覆盖样本数量与实际正例样本量

    positive_recall = target_data.loc[(target_data.y_test == positive_flag) (target_data.y_scorescore),:].shape[0]

    positive = sum(target_data.y_test == positive_flag)

    # 负例覆盖样本数量与实际负例样本量

    negative_recall = target_data.loc[(target_data.y_test != positive_flag) (target_data.y_score=score),:].shape[0]

    negative = sum(target_data.y_test != positive_flag)

    Sensitivity.append(positive_recall/positive)

    Specificity.append(negative_recall/negative)

# 构建绘图数据

plot_data = pd.DataFrame({'cuts':cuts,'y1':1-np.array(Specificity),'y2':np.array(Sensitivity),

                          'ks':np.array(Sensitivity)-(1-np.array(Specificity))})

# 寻找Sensitivity和1-Specificity之差的最大值索引

max_ks_index = np.argmax(plot_data.ks)

plt.plot([0]+cuts.tolist()+[1], [0]+plot_data.y1.tolist()+[1], label = '1-Specificity')

plt.plot([0]+cuts.tolist()+[1], [0]+plot_data.y2.tolist()+[1], label = 'Sensitivity')

# 添加参考线

plt.vlines(plot_data.cuts[max_ks_index], ymin = plot_data.y1[max_ks_index],

          ymax = plot_data.y2[max_ks_index], linestyles = '--')

# 添加文本信息

plt.text(x = plot_data.cuts[max_ks_index]+0.01,

        y = plot_data.y1[max_ks_index]+plot_data.ks[max_ks_index]/2,

        s = 'KS= %.2f' %plot_data.ks[max_ks_index])

# 显示图例

plt.legend()

# 显示图形

plt.show()

# 调用自定义函数,绘制K-S曲线

plot_ks(y_test = y_test, y_score = y_score, positive_flag = 1)

Python如何画函数的曲线

输入以下代码导入我们用到的函数库。

import numpy as np

import matplotlib.pyplot as plt

x=np.arange(0,5,0.1);

y=np.sin(x);

plt.plot(x,y)

采用刚才代码后有可能无法显示下图,然后在输入以下代码就可以了:

plt.show()

名称栏目:Python提取曲线函数,python提取曲线数据线
URL分享:https://www.cdcxhl.com/article34/hshpse.html

成都网站建设公司_创新互联,为您提供网站维护网站制作定制网站建站公司动态网站Google

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站建设网站维护公司