1
2

More than 1 year has passed since last update.

PyCaretのevaluate_model()実行時にフォントエラーとなる場合の対処方法

Last updated at Posted at 2023-02-07

手持ちのデータセットを用いてPyCaretで機械学習モデルの比較検討を行い、evaluate_model()関数を実行すると以下の様なエラー表示が連発します。

image.png

エラー文(抜粋)
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のエラーが出ているのだと思われます。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2