Time Series Clustering and Classification
2014-12-23 23:58
302 查看
http://www.rdatamining.com/examples/time-series-clustering-classification
ThispageshowsRcodeexamplesontimeseriesclusteringandclassificationwithR.
TimeSeriesClusteringandClassification
ThispageshowsRcodeexamplesontimeseriesclusteringandclassificationwithR.TimeSeriesClusteringTimeseriesclusteringistopartitiontimeseriesdataintogroupsbasedonsimilarityordistance,sothattimeseriesinthesameclusteraresimilar.FortimeseriesclusteringwithR,thefirststepistoworkoutanappropriatedistance/similaritymetric,andthen,atthesecondstep,useexistingclusteringtechniques,suchask-means,hierarchicalclustering,density-basedclusteringorsubspaceclustering,tofindclusteringstructures. DynamicTimeWarping(DTW)findsoptimalalignmentbetweentwotimeseries,andDTWdistanceisusedasadistancemetricintheexamplebelow. AdatasetofSyntheticControlChartTimeSeriesisusedhere,whichcontains600examplesofcontrolcharts.Eachcontrolchartisatimeserieswith60values.Therearesixclasses:1)1-100Normal,2)101-200Cyclic,3)201-300Increasingtrend,4)301-400 Decreasingtrend,5)401-500Upwardshift,and6)501-600Downwardshift.ThedatasetisdownloadableatUCI KDDArchive. >sc<-read.table(“E:/Rtmp/synthetic_control.data”,header=F,sep=”") #randomlysampledncasesfromeachclass,tomakeiteasyforplotting >n<-10 >s<-sample(1:100,n) >idx<-c(s,100+s,200+s,300+s,400+s,500+s) >sample2<-sc[idx,] >observedLabels<-c(rep(1,n),rep(2,n),rep(3,n),rep(4,n),rep(5,n),rep(6,n)) #computeDTWdistances >library(dtw) >distMatrix<-dist(sample2,method=”DTW”) #hierarchicalclustering >hc<-hclust(distMatrix,method=”average”) >plot(hc,labels=observedLabels,main=”") TimeSeriesClassificationTimeseriesclassificationistobuildaclassificationmodelbasedonlabelledtimeseriesandthenusethemodeltopredictthelabelofunlabelledtimeseries.ThewayfortimeseriesclassificationwithRistoextractandbuildfeaturesfromtimeseriesdatafirst,andthenapplyexistingclassificationtechniques,suchasSVM,k-NN,neuralnetworks,regressionanddecisiontrees,tothefeatureset. DiscreteWaveletTransform(DWT)providesamulti-resolutionrepresentationusingwaveletsandisusedintheexamplebelow.AnotherpopularfeatureextractiontechniqueisDiscreteFourierTransform(DFT). #extractingDWTcoefficients(withHaarfilter) >library(wavelets) >wtData<-NULL >for(iin1:nrow(sc)){ +a<-t(sc[i,]) +wt<-dwt(a,filter=”haar”,boundary=”periodic”) +wtData<-rbind(wtData,unlist(c(wt@W,wt@V[[wt@level]]))) +} >wtData<-as.data.frame(wtData) #setclasslabelsintocategoricalvalues >classId<-c(rep(“1″,100),rep(“2″,100),rep(“3″,100), +rep(“4″,100),rep(“5″,100),rep(“6″,100)) >wtSc<-data.frame(cbind(classId,wtData)) #buildadecisiontreewithctree()inpackageparty >library(party) >ct<-ctree(classId~.,data=wtSc, +controls=ctree_control(minsplit=30,minbucket=10,maxdepth=5)) >pClassId<-predict(ct) #checkpredictedclassesagainstoriginalclasslabels >table(classId,pClassId) #accuracy >(sum(classId==pClassId))/nrow(wtSc) [1]0.8716667 >plot(ct,ip_args=list(pval=FALSE),ep_args=list(digits=0)) MoreexamplesontimeseriesanalysisandminingwithRandotherdataminingtechniquescanbefoundinmybook" whichisdownloadableasa.PDFfileatthelink. |
相关文章推荐
- Sensor fusion and input representation for time series classification using deep nets
- 论文阅读——Generic and Scalable Framework for Automated Time-series Anomaly Detection
- Long Term Time Series Prediction and Stock Value Prediction
- Paper list of Imbalanced Time-series Classification with Deep Learning
- Is Time Series Clustering Meaningless? (lots of dplyr)
- Introducing practical and robust anomaly detection in a time series
- Time-Series Classification with COTE: The Collective of Transformation-Based Ensembles
- High Level Microarray Analysis - Clustering and Classification (Practice)
- examples - visualizing time series data and geographic data using python
- Best Time to Buy and Sell Stock Series
- 不平衡数据下的机器学习方法简介 imbalanced time series classification
- 预测和分解时间序列数据(小时)Forecast and STL hourly time series data
- Mixing Numbers and Symbols in Time Series Charts
- System and method for controlling switching between VMM and VM using enabling value of VMM timer indicator and VMM timer value having a specified time
- When the C Run-Time (CRT) library and Microsoft Foundation Class (MFC) libraries are linked in the w
- leetcode之Best Time to Buy and Sell Stock
- leetcode Best Time to Buy and Sell Stock II
- pdflatex 笔记+资源 汇总(update everytime I meet and solve a problem)
- 【LEETCODE】309-Best Time to Buy and Sell Stock with Cooldown
- LeetCode: Best Time to Buy and Sell Stock