Last active
January 21, 2020 00:11
-
-
Save monhime/5a8bf8f4cd65b6e865f18ef7a2283286 to your computer and use it in GitHub Desktop.
検索流入の解析(130日目以降,線形近似とデータ適合)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 初期設定 | |
INIT_DAY = 130; % 後半の近似に用いる最初の日 | |
LAST_DAY = 225; % 最後の日 | |
%% 定義 | |
% 非線形モデル式 | |
% k(1): K, k(2): p, k(3): T, k(4):a(ズレ補償) | |
f3 = @(k,x) k(1)*(0.5*k(2)*x.^2-k(3)*x)+k(4); | |
% 各パラメータの初期値 | |
k0 = [0.4, 0.5, -1, 0]; | |
% 各パラメータの最小値 | |
l_k = [0, 0, -1000,0]; | |
% 各パラメータの最大値 | |
u_k = [2, 2, 0,200]; | |
%% 線形近似 | |
% 線形近似 | |
[yfit2, gof2]= fit(access.day(INIT_DAY:LAST_DAY),access.Search(INIT_DAY:LAST_DAY),'poly1'); | |
% 係数の値・信頼区間の表示 | |
disp(['係数の値と信頼区間']) | |
disp(yfit2); | |
% 統計データの表示 | |
disp(['統計データ']); | |
disp(gof2); | |
% 線形近似直線の定義 | |
f2 = @(x) yfit2.p1*x+yfit2.p2; | |
%% 非線形近似 | |
k = lsqcurvefit(f3, k0, access.day(INIT_DAY:LAST_DAY), access.Search(INIT_DAY:LAST_DAY),l_k,u_k); | |
% 各パラメータの表示 | |
disp(k); | |
% 非線形近似の結果を使って近似曲線を定義 | |
f3_new = @(x) k(1)*(0.5*k(2)*x.^2-k(3)*x)+k(4); | |
%% figure を作成 | |
% i==1: 300日目まで表示 | |
% i==2: 1000日目まで表示 | |
for i=1:2 | |
figure; | |
% axes を作成 | |
axes1 = axes('Position',... | |
[0.135000000066642 0.198492462311558 0.729285702321904 0.726507537688442]); | |
hold(axes1,'on'); | |
yyaxis(axes1,'left'); | |
plot(access.day,access.article,'DisplayName','累計記事数'); | |
xlabel({'独自ドメイン移行後の日数'}); | |
ylabel({'累計記事数'}); | |
if i==1 | |
ylim(axes1,[0 300]); | |
else | |
ylim(axes1,[0 500]); | |
end | |
set(axes1,'YColor',[0 0 0]); | |
yyaxis(axes1,'right'); | |
plot(access.day,access.Search,'DisplayName','検索流入件数'); | |
plot2 = fplot(f2,'r-'); | |
set(plot2,'DisplayName','線形近似'); | |
plot3 = fplot(f3_new,'r-'); | |
set(plot3,'DisplayName','データ適合'); | |
% ylabel を作成 | |
ylabel({'検索流入件数'}); | |
% 残りの座標軸プロパティの設定 | |
set(axes1,'YColor',[0.85 0.325 0.098]); | |
if i==1 | |
xlim(axes1,[-1 300]); | |
ylim(axes1,[0 150]); | |
else | |
xlim(axes1,[-1 1000]); | |
ylim(axes1,[0 1000]); | |
end | |
box(axes1,'on'); | |
grid(axes1,'on'); | |
legend1 = legend(axes1,'show'); | |
set(legend1,'Location','northwest','FontSize',14.9); | |
hold(axes1,'off'); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment