Stan과 R로 베이스 통계 모델링(오리본)을 Python-7.3 비선형 관계로 설정합니다.
가져오기
import numpy as np
import pandas as pd
import pystan
import matplotlib.pyplot as plt
from matplotlib.figure import figaspect
%matplotlib inline
데이터 읽기
aircon = pd.read_csv('./data/data-aircon.txt')
conc = pd.read_csv('./data/data-conc.txt')
7.3 비선형 관계 N_new = 60
X_new = np.linspace(-3, 32, N_new)
data = dict(
    N=aircon.index.size,
    X=aircon['X'],
    Y=aircon['Y'],
    N_new=N_new,
    X_new=X_new
)
fit = pystan.stan('./stan/model7-3.stan', data=data, seed=1234)
 ms = fit.extract()
d_est = np.percentile(ms['y_new'], (2.5, 25, 50, 75, 97.5), axis=0)
_, (ax1, ax2) = plt.subplots(1, 2, figsize=figaspect(3/8), sharex=True, sharey=True)
for ax in [ax1, ax2]:
    aircon.plot.scatter('X', 'Y', color='w', edgecolor='k', ax=ax)
ax2.fill_between(X_new, d_est[0], d_est[-1], color='k', alpha=0.3)
ax2.fill_between(X_new, d_est[1], d_est[-2], color='k', alpha=0.5)
ax2.plot(X_new, d_est[2], color='k')
plt.setp(ax2, yticks=np.arange(0, 101, 50))
plt.show()
 
 T_new = 60
Time_new = np.linspace(0, 24, T_new)
data = dict(
    T=conc.index.size,
    Time=conc['Time'],
    Y=conc['Y'],
    T_new=T_new,
    Time_new=Time_new
)
fit = pystan.stan('./stan/model7-4.stan', data=data, seed=123)
 ms = fit.extract()
d_est = np.percentile(ms['y_new'], (2.5, 25, 50, 75, 97.5), axis=0)
_, (ax1, ax2) = plt.subplots(1, 2, figsize=figaspect(3/8), sharex=True, sharey=True)
conc.plot.line('Time', 'Y', marker='o', color='k', ax=ax1)
ax2.scatter('Time', 'Y', data=conc, color='k')
ax2.fill_between(Time_new, d_est[0], d_est[-1], color='k', alpha=0.3)
ax2.fill_between(Time_new, d_est[1], d_est[-2], color='k', alpha=0.5)
ax2.plot(Time_new, d_est[2], color='k')
plt.setp(ax2, xlabel='Time (hour)', ylabel='Y', xticks=conc['Time'], yticks=np.arange(0, 16, 5), ylim=(-2.5, 16))
plt.show()
 
 x = np.linspace(0, 5, 60)
plt.figure(figsize=figaspect(3/4))
ax = plt.axes()
ax.plot(x, 2*np.exp(-1*x), linestyle='solid', label=1)
ax.plot(x, 1.8/(1+50*np.exp(-2*x)), linestyle='dashed', label=2)
ax.plot(x, 8*(np.exp(-x) - np.exp(-2*x)), linestyle='dotted', label=3)
ax.legend(title='Model')
plt.setp(ax, xlabel='Time', ylabel='Y')
plt.show()
 
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Stan과 R로 베이스 통계 모델링(오리본)을 Python-7.3 비선형 관계로 설정합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/shngt/items/363351ac7cf56636414b
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
N_new = 60
X_new = np.linspace(-3, 32, N_new)
data = dict(
    N=aircon.index.size,
    X=aircon['X'],
    Y=aircon['Y'],
    N_new=N_new,
    X_new=X_new
)
fit = pystan.stan('./stan/model7-3.stan', data=data, seed=1234)
ms = fit.extract()
d_est = np.percentile(ms['y_new'], (2.5, 25, 50, 75, 97.5), axis=0)
_, (ax1, ax2) = plt.subplots(1, 2, figsize=figaspect(3/8), sharex=True, sharey=True)
for ax in [ax1, ax2]:
    aircon.plot.scatter('X', 'Y', color='w', edgecolor='k', ax=ax)
ax2.fill_between(X_new, d_est[0], d_est[-1], color='k', alpha=0.3)
ax2.fill_between(X_new, d_est[1], d_est[-2], color='k', alpha=0.5)
ax2.plot(X_new, d_est[2], color='k')
plt.setp(ax2, yticks=np.arange(0, 101, 50))
plt.show()
T_new = 60
Time_new = np.linspace(0, 24, T_new)
data = dict(
    T=conc.index.size,
    Time=conc['Time'],
    Y=conc['Y'],
    T_new=T_new,
    Time_new=Time_new
)
fit = pystan.stan('./stan/model7-4.stan', data=data, seed=123)
ms = fit.extract()
d_est = np.percentile(ms['y_new'], (2.5, 25, 50, 75, 97.5), axis=0)
_, (ax1, ax2) = plt.subplots(1, 2, figsize=figaspect(3/8), sharex=True, sharey=True)
conc.plot.line('Time', 'Y', marker='o', color='k', ax=ax1)
ax2.scatter('Time', 'Y', data=conc, color='k')
ax2.fill_between(Time_new, d_est[0], d_est[-1], color='k', alpha=0.3)
ax2.fill_between(Time_new, d_est[1], d_est[-2], color='k', alpha=0.5)
ax2.plot(Time_new, d_est[2], color='k')
plt.setp(ax2, xlabel='Time (hour)', ylabel='Y', xticks=conc['Time'], yticks=np.arange(0, 16, 5), ylim=(-2.5, 16))
plt.show()
x = np.linspace(0, 5, 60)
plt.figure(figsize=figaspect(3/4))
ax = plt.axes()
ax.plot(x, 2*np.exp(-1*x), linestyle='solid', label=1)
ax.plot(x, 1.8/(1+50*np.exp(-2*x)), linestyle='dashed', label=2)
ax.plot(x, 8*(np.exp(-x) - np.exp(-2*x)), linestyle='dotted', label=3)
ax.legend(title='Model')
plt.setp(ax, xlabel='Time', ylabel='Y')
plt.show()
Reference
이 문제에 관하여(Stan과 R로 베이스 통계 모델링(오리본)을 Python-7.3 비선형 관계로 설정합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/shngt/items/363351ac7cf56636414b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)