python评分功能(代码片段)

author author     2022-12-28     658

关键词:

import numpy as np
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import mean_squared_error
 
 
# calculate general error
error = fcst - obs # "fcst" and "obs" are numpy arrays
 
# calculate scores
bias = np.mean(error)
mae = np.mean(np.abs(error))
mse = np.mean(error**2)
rmse = np.sqrt(mse)
 
# other ways
mae = mean_absolute_error(obs,fcst)
mse = mean_squared_error(obs,fcst)
"""
calculate rmse

inputs: list of numpy arrays with same length

"""
def rmse(y_true, y_pred):
    from sklearn.metrics import mean_squared_error
    from math import sqrt
    # validation input
    assert len(y_true) == len(y_pred)
    # calculate and return
    return sqrt(mean_squared_error(y_true, y_pred))


"""
Root Mean Squared Logarithmic Error
"""
def rmsle(y_true:'array',y_pred:'array'):
  import numpy as np
  assert len(y_true) == len(y_pred)
  return np.square(np.log(y_pred + 1) - np.log(y_true + 1)).mean() ** 0.5
   


"""
calculate bias

inputs: list of numpy arrays with same length

"""
def bias(predictions, observation):
  import numpy as np

  # validation input
  if len(observation) != len(predictions): 
  	print("ERROR: observation and prediction numpy arraies dont have same length")
  	return None
	# calculate and return
  return np.mean([ (ifore - iobs) for ifore,iobs in list(zip(predictions,observation)) ])
    


"""
calculate mae (mean absolute error)

inputs: list or numpy arrays

"""
def mae(predictions,observation):
    from sklearn.metrics import mean_absolute_error

    # validation input
    if len(observation) != len(predictions): 
        print("ERROR: observation and prediction numpy arraies dont have same length")
        return None

    return mean_absolute_error(observation, predictions)


    

"""
calculate mape

inputs: list of numpy arrays with same length

"""
def mape(predictions, observation):
    import numpy as np
    # initialize
    lmape = list()
    for iobs, ifore in list(zip(observation,predictions)):
        if float(iobs) != 0.: lmape.append(abs((iobs-ifore) / iobs))
    # average and return
    return np.mean(lmape)*100
	


"""
Pearson correlation

input: numpy arrays

"""	
def correlation(x1,x2):
	from scipy.stats import pearsonr
	corr,pvalue = pearsonr(x1,x2)
	return corr


"""
Residual Standard Error (standar deviation of epsilon=mean-zero random error: Y = f(X) + epsilon )

units: same than Y.
"""
def RSE(y_obs,y_predict):
    import numpy
    residue = (y_obs - y_predict)**2
    RSS = np.sum(residue)
    return np.sqrt((1/(len(residue)-2))*RSS)
    

python弹球评分用于概率预测(代码片段)

查看详情

python调用百度ai对颜值评分(代码片段)

...杨紫的图片为例进行年龄、性别、颜值的识别。  具体python代码如下:‍importosimportbase64fromaipimportAipFaceos.chdir(r'F:\\公众号\\28.人脸识别')#设置图片存放的路径pictureName='1_yz.jpg'defget_picture_content(pictureName):withope... 查看详情

python爬取豆瓣电影图片并生成评分柱状图(代码片段)

博主在学习python爬虫后,实现了一个爬取豆瓣电影评分并形成柱状图,并下载电影海报,实现效果如图所示python爬取电影信息需要按此步骤模拟浏览器发送请求(获取网页代码)->提取有用的数据->存放于数据库或文... 查看详情

vue实现rate组件(星星评分)(代码片段)

这个功能就类似于某宝在购物之后,对商品进行评价先看一下效果那么实现这个功能也很简单,新建一个my-rate组件,然后上代码1<template>2<divclass="rate":class="‘disabled‘:disabled">3<spanv-if="showText"class="text">curScore||score分... 查看详情

评分卡应用-利用toad进行有监督分箱(卡方分箱/决策树分箱)(代码片段)

toad是针对工业届建模而开发的工具包,针对风险评分卡的建模有针对性的功能。toad持续更新优化中,本教程针对toad的各类主要功能进行介绍,包括:EDA相关功能如何使用toad高效分箱并进行特征筛选WOE转化逐步回... 查看详情

评分卡应用-利用toad进行有监督分箱(卡方分箱/决策树分箱)(代码片段)

toad是针对工业届建模而开发的工具包,针对风险评分卡的建模有针对性的功能。toad持续更新优化中,本教程针对toad的各类主要功能进行介绍,包括:EDA相关功能如何使用toad高效分箱并进行特征筛选WOE转化逐步回... 查看详情

python:爬取豆瓣短评用户数据(城市注册时间发表时间评分评论内容)(代码片段)

最近因为泰迪实习需要,做一些这样的数据分析。分享一下相关代码。修改其中的url(注意应用规则,需要对爬虫有一定了解)即可用。importrequestsimportrefromtask_getUserInfimportgetUserInfimportpandasaspdimportemoji#用户数据获... 查看详情

python:学习爬取数据以分析(城市注册时间发表时间评分评论内容)(代码片段)

最近因为泰迪实习需要,做一些这样的数据分析。分享一下相关代码。修改其中的url(注意应用规则,需要对爬虫有一定了解)即可用。importrequestsimportrefromtask_getUserInfimportgetUserInfimportpandasaspdimportemoji#用户数据获... 查看详情

python练习题(代码片段)

一、选秀评分需求:某比赛评分规则如下:由5位评委进行打分,最终结果去掉一个最高分和最低分后求平均成绩。代码:list=[0,0,0,0,0]i=j=sum=0whilei<5:list[i]=input("请输入第%s位评委评分:"%(... 查看详情

python线性回归分析练手:用大众点评500家的评分数据拟合线性回归(代码片段)

python线性回归分析大家好!我是未来村村长!就是那个“请你跟我这样做,我就跟你那样做!”的村长👨‍🌾!一、简单说明1、数据源2、探究目的我们通过线性回归方法,探究’评论人数’,‘人... 查看详情

助教小结(代码片段)

...cnblogs.com/zy456/p/10594890.html请开启仓库代码访问权限,很多评分将基于仓库中的数据进行评分。另外,建议时间表和功能清单以excel表格形式,然后在截图发出,也可以直接在博客中以HTML形式插入表格(2)https://www.cnblogs.com/Fall825/... 查看详情

text评分(代码片段)

查看详情

java学生评分(代码片段)

查看详情

javascript更新环境评分(代码片段)

查看详情

因果推断笔记——python倾向性匹配psm实现示例(代码片段)

因果推断笔记——相关理论:RubinPotential、Pearl、倾向性得分、与机器学习异同(二)因果推断笔记——因果图建模之微软开源的dowhy(一)文章目录1从matching->倾向性得分1.1精准匹配1.2倾向性得分/倾向评分... 查看详情

因果推断笔记——python倾向性匹配psm实现示例(代码片段)

因果推断笔记——相关理论:RubinPotential、Pearl、倾向性得分、与机器学习异同(二)因果推断笔记——因果图建模之微软开源的dowhy(一)文章目录1从matching->倾向性得分1.1精准匹配1.2倾向性得分/倾向评分... 查看详情

php评分最高的产品(代码片段)

查看详情

markdown豆瓣高评分书籍(代码片段)

查看详情