시계열 Data

1
2
3
4
5
6
7
> uspop
Time Series:
Start = 1790
End = 1970
Frequency = 0.1
[1] 3.93 5.31 7.24 9.64 12.90 17.10 23.20 31.40 39.80 50.20 62.90 76.00 92.00 105.70 122.80 131.70 151.30 179.30
[19] 203.20
Read more »

변수 지우기

1
2
3
> rm(list=ls())
> ls()
character(0)
  • ls()는 지금까지 생성한 변수들의 목록을 문자열들로 반환하는 함수(list의 약자)
Read more »

R

1
2
3
4
5
6
7
8
9
10
11
12
13
#전산실습 Day 1
speed=c(4,7,8,9,10,11,12,13,13,14);speed #Multi input #Ctrl+R is compiling of only one line
dist=c(2,4,16,10,18,17,24,34,26,26);dist #대소문자 구분
mean(speed)
mean(dist) #결측값이 있는 data에서 수식이용시 결과는 결측값
#함수이용시 결과는 결측값 제외하고 계산
sd(speed) #Standard variation
#수치자료 : 대표값(mean),산포도(sd),비대칭도-왜도(skew)
#평균-중심위치
min(speed);max(speed) #Find Error
summary(speed)
plot(speed,dist)
cor(speed,dist) #상관계수(산점도 확인 후)-직선적인 정도 
Read more »

Species classification by sepal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
clear

%Load data
load fisheriris
x=meas(:,1:2);
y=categorical(species);
labels = categories(y);
figure(1)
gscatter(x(:,1),x(:,2),species,'rgb','osd');
xlabel('Sepal length');
ylabel('Sepal width');

%Learning by data
classifier{1}=ClassificationDiscriminant.fit(x,y);
classifier{2}=ClassificationTree.fit(x,y);
classifier{3}=ClassificationKNN.fit(x,y);
%classifier{4}=NaiveBayes.fit(x,y); 2019 ver
classifier_name={'Discriminant Analysis','Classification Tree','Nearest Neighbor'}; %'Naive Bayes'

%Check the result
[xx1,xx2]=meshgrid(4:.01:8,2:.01:4.5);
figure(2)
for ii=1:numel(classifier)
ypred=predict(classifier{ii},[xx1(:) xx2(:)]);
h(ii)=subplot(2,2,ii);
gscatter(xx1(:),xx2(:),ypred,'rgb');
title(classifier_name{ii},'FontSize',15)
legend off
axis tight
end

%Confusion Matrix
figure(3)
predictResult=predict(classifier{2},x);
y=categorical(y);
predictResult=categorical(predictResult);
plotconfusion(y,predictResult);
Read more »