Qiita's first post! !! It's easy for a new graduate first year engineer (* ´ ▽ ` *) Reference site: [changefinder] (http://argmax.jp/index.php?changefinder)
I recently heard a voice saying "I want to know if PV is skyrocketing!" And tried it. In such cases, it seems that measurement is often performed using change point detection and outlier detection. While investigating, there were some examples where a model called changefinder was used.
[Introduction of the method and system for identifying soaring words using "Ameba" and "Twitter"] (https://www.cyberagent.co.jp/techinfo/techreport/report/id=9749)
There are packages in R and Python, so this time I tried the sample code of the python package that I have never touched!
R: [I made a package for anomaly detection (change point detection)] (http://d.hatena.ne.jp/yokkuns/20120930/1348978641)
Python: [changefinder] (http://argmax.jp/index.php?changefinder)
The editor used jupyter, which is a hot topic in the Python area recently. How to install jupyter nootbook is summarized in here. jupyter is a recommended editor for interactive code modification, data acquisition and plotting.
When I hit the sample code with jupyter, it looks like this
First, install the changefinder package Install the required libraries
pip install changefinder
matplotlib.pyplot is a standard library of graph plots. numpy is a convenient library that various functions that generate random numbers say. Pandas contains types that make data manipulation convenient, such as data frames.
import changefinder as cf
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
Create the data to be analyzed. Random numbers with low, high, low, and high mean values are created and stored.
data=np.concatenate([
np.random.normal(0.7, 0.05, 300),
np.random.normal(1.5, 0.05, 300),
np.random.normal(0.6, 0.05, 300),
np.random.normal(1.3, 0.05, 300)])
Set the parameters.
cf = changefinder.ChangeFinder(r=0.01, order=1, smooth=100)
Put the score in an array
ret = []
for i in data:
score = cf.update(i)
ret.append(score)
It is a graph plot.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(ret)
ax2 = ax.twinx()
ax2.plot(data,'r')
plt.show()
With jupyter, you can do it interactively, so you can easily try various packages!
Recommended Posts