skewness z 分数_z分数用于异常检测

skewness z 分数

重点 (Top highlight)

Most of the time I write longer articles on data science topics but recently I’ve been thinking about writing small, bite-sized pieces around specific concepts, algorithms and applications. This is my first attempt in that direction, hoping people will like these pieces.

大多数时候,我都会撰写有关数据科学主题的较长文章,但最近我一直在考虑围绕特定概念,算法和应用程序编写小巧的文章。 这是我朝这个方向的第一次尝试,希望人们会喜欢这些作品。

In today’s “small-bite” I’m writing about Z-score in the context of anomaly detection.

在当今的“小叮咬”中,我是在异常检测的背景下编写有关Z分数的文章。

Anomaly detection is a process for identifying unexpected data, event or behavior that require some examination. It is a well-established field within data science and there is a large number of algorithms to detect anomalies in a dataset depending on data type and business context. Z-score is probably the simplest algorithm that can rapidly screen candidates for further examination to determine whether t

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以根据您的需求对程序进行修改,下面是一些可能有用的修改建议: 1. 检查数据是否成功读取:可以在读取数据后添加一行代码,如`print(data.head())`,以便检查数据是否成功读取。 2. 指定日期列的格式:如果日期列的格式不是标准的日期格式,可能需要使用`pd.to_datetime`函数将其转换为日期类型。例如:`data['date'] = pd.to_datetime(data['date'], format='%Y-%m-%d')`。 3. 绘制更加详细的图表:如果需要绘制更加详细的图表,可以添加一些参数,例如:`plt.plot(data['date'], r)`。这样可以将时间序列数据的横坐标设置为日期。 4. 提取更多的统计量:除了原始数据的平均值、标准差、偏度、峰度、最大值、最小值和自相关系数之外,还可以提取其他的统计量。例如:中位数、四分位数、方差、协方差等等。 5. 使用更加规范的变量名:为了使代码更加易于阅读和理解,可以使用更加规范的变量名,例如:`returns_df`代替`r_df`,`num_returns`代替`num_trading_days`,`autocorrelation`代替`autocorr`等等。 下面是一个修改后的程序,供您参考: ```python import pandas as pd import matplotlib.pyplot as plt # 读取数据并指定列名 data = pd.read_excel('RESSET_DRESSTK2.xlsx', header=None) data.columns = ['code', 'date', 'return'] # 将日期列转换为日期类型 data['date'] = pd.to_datetime(data['date'], format='%Y-%m-%d') # 绘制时间序列图 plt.plot(data['date'], data['return']) plt.title('Stock Returns') plt.xlabel('Date') plt.ylabel('Returns') plt.show() # 计算统计量 returns_df = pd.DataFrame({'return': data['return'].values}) num_returns = len(returns_df) mean_return = returns_df.mean().values[0] std_return = returns_df.std().values[0] skewness = returns_df.skew().values[0] kurtosis = returns_df.kurtosis().values[0] max_return = returns_df.max().values[0] min_return = returns_df.min().values[0] autocorrelation = returns_df['return'].autocorr() # 打印统计量 print(f'Number of trading days: {num_returns}') print(f'Mean return: {mean_return:.4f}') print(f'Standard deviation of return: {std_return:.4f}') print(f'Skewness: {skewness:.4f}') print(f'Kurtosis: {kurtosis:.4f}') print(f'Maximum return: {max_return:.4f}') print(f'Minimum return: {min_return:.4f}') print(f'Autocorrelation: {autocorrelation:.4f}') ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值