手持ちのデータセットを用いてPyCaretで機械学習モデルの比較検討を行い、evaluate_model()関数を実行すると以下の様なエラー表示が連発します。
エラー文(抜粋)
findfont: Generic family 'sans-serif' not found because none of the following families were found: Arial, Liberation Sans, Bitstream Vera Sans, sans-serif
対処方法
japanize-matplotlib
をインストールします。これは元々matplotlib
を手軽に日本語表示に対応させるためのライブラリです。
pip install japanize-matplotlib
ここから注意が必要です。それはimportの順番です。Pep8には違反してしまいますが、japanize-matplotlibをPyCaretより後にimportしないと有効になりません。
以下の様にPep8準拠のimport順序では、上記のエラーが表示されます。
Pep8準拠のimport順では対処できない
import japanize-matplotlib
from pycaret.classification import *
以下の順番でimportします。flake8などが実行される環境ではエラー出力されないように# noqa
を追記すると良いでしょう。
正しいimport方法
from pycaret.classification import *
import japanize-matplotlib
このエラーメッセージをインターネットで検索すると十中八九Matplotlibのエラー対処として出てきます。PyCaretも内部でMatplotlibを呼んでいるため、これはどうやらMatplotlibのエラーが出ているのだと思われます。