今, こちらのサイトを参考にpystanを用いたモデリングの練習をしています.
pystanで線形回帰
python
html
1""" 2pystan の練習py 3 4data : ボストン近郊の住宅情報のデータを使う. 5""" 6import numpy as np 7from pystan import StanModel 8from sklearn.datasets import load_boston 9from sklearn.model_selection import train_test_split 10 11Boston = load_boston() 12X = Boston.data 13y = Boston.target 14 15# Separating the dataset 16X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.2) 17 18# Stan 部分 19data = {'N': X_train.shape[0],'M':X_train.shape[1],'x':X_train, 'y':y_train} 20# Stan コード 21model = """ 22 data{ 23 int<lower=0> N; 24 int<lower=0> M; 25 matrix[N,M] X; 26 vector[N] y; 27 } 28 parameters{ 29 real beta_0; 30 vector[M] beta; 31 real<lower=0> sigma; 32 } 33 model { 34 for(i in 1:N) 35 y[i] ~ normal(beta_0 + dot_product(X[i],beta),sigma); 36 } 37""" 38 39stm = StanModel(model_code = model)
上記のコードを実行した結果, 以下のエラーが出ました. Error箇所は最終行の stm = StanModel()の部分となっています.
html
1INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_183562d9f6b65150bf16967dbf614eac NOW. 2/Users/myname/miniconda3/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /var/folders/k3/5_y8h_552gv2n875280rv_600000gn/T/tmpromycksj/stanfit4anon_model_183562d9f6b65150bf16967dbf614eac_110513922084137191.pyx 3 tree = Parsing.p_module(s, pxd, full_module_name) 4Traceback (most recent call last): 5 File "/Users/myname/Desktop/THESIS PROGRAMING/pystan_try.py", line 39, in <module> 6 stm = StanModel(model_code = model) 7 File "/Users/myname/miniconda3/lib/python3.6/site-packages/pystan/model.py", line 350, in __init__ 8 build_extension.run() 9 File "/Users/myname/miniconda3/lib/python3.6/distutils/command/build_ext.py", line 339, in run 10 self.build_extensions() 11 File "/Users/myname/miniconda3/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions 12 self._build_extensions_serial() 13 File "/Users/myname/miniconda3/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial 14 self.build_extension(ext) 15 File "/Users/myname/miniconda3/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension 16 depends=ext.depends) 17 File "/Users/myname/miniconda3/lib/python3.6/distutils/ccompiler.py", line 574, in compile 18 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) 19 File "/Users/myname/miniconda3/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile 20 raise CompileError(msg) 21distutils.errors.CompileError: command 'gcc' failed with exit status 1
解決する方法を知りたいです.
【追記】:こちらのリンクを参照し, MacOSの方を試したのですが, 以下のパスが無効であると出てしましました。
ターミナル
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
エラー
installer: Error the package path specified was invalid: '/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg'.