2016-11-23 20 views
0

나는 일련의 숫자가 있습니다방법은 크게

numbers = [100, 101, 99, 102, 99, 98, 100, 97.5, 98, 99, 95, 93, 90, 85, 80] 

plot of numbers

그것은 숫자가 급격히 약 약 10 하락할 것으로 시작하는 것이 눈으로 보는 것은 매우이다, 그러나 x 축에서 그 점을 (또는 그것에 가까운) 식별하는 간단한 방법이 있습니까?

이 작업은 회귀 적으로 수행되므로 전체 숫자 목록을 사용하여 감소가 가속화되는 x 축 지점을 선택할 수 있습니다.

파이썬 솔루션이 선호되지만 의사 코드 또는 일반적인 방법론도 좋습니다.

+0

다음 하나 개의 번호의 차이를 표준 편차의 절반보다 큰 점? –

+0

나는 그것이 평평한 기간이 얼마나 오래 지속되는지에 달려 있다고 생각한다. 이전에 방울이 발생하면 전체 계열의 표준 편차가 표준 편차만큼 관련되지 않습니다. – Chris

+0

누적 Z 점수가 아마도 효과가있을 것입니다. – Chris

답변

0

좋아, 결국 내 필요에 맞게. 나는 연속적인 평균, 표준 편차 및 cdf를 t 분포로부터 계산하여 각각의 연속적인 값이 얼마나 희박한지를 말해 준다.

이것은 단지 cdf < 0.05 만 확인하기 때문에 감소와 함께 작동하지만 아주 잘 작동합니다. 아마도

import numpy as np 
from scipy import stats 
import matplotlib.pyplot as plt 

numbers = np.array([100, 101, 99, 102, 99, 98, 100, 97.5, 98, 99, 95, 93, 90, 85, 80]) 

# Calculate a running mean 
cum_mean = numbers.cumsum()/(np.arange(len(numbers)) + 1) 

# Calculate a running standard deviation 
cum_std = np.array([numbers[:i].std() for i in range(len(numbers))]) 

# Calculate a z value 
cum_z = (numbers[1:] - cum_mean[:-1])/cum_std[:-1] 

# Add in NA vals to account for records without sample size 
z_vals = np.concatenate((np.zeros(1+2), cum_z[2:]), axis=0) 

# Calculate cdf 
cum_t = np.array([stats.t.cdf(z, i) for i, z in enumerate(z_vals)]) 

# Identify first number to fall below threshold 
first_deviation = np.where(cum_t < 0.05)[0].min() 

fig, ax = plt.subplots() 

# plot the numbers and the point immediately prior to the decrease 
ax.plot(numbers) 
ax.axvline(first_deviation-1, color='red') 

numbers with drop detected