4
6

More than 5 years have passed since last update.

class sklearn.naive_bayes.MultinomialNB(alpha=1.0, fit_prior=True, class_prior=None)のメモ

Posted at

ナイーブベイズ
離散な特徴を学習させる(intが必須)

alpha:float, optional -> スムージングparameter(defaultは1.0)
fit_prior:boolean -> class prior probabilitiesを使うかどうか
class_prior:array-like, size=[n_classes] -> Prior probabilities of the classes

example

import numpy as np
# 0~5の間の乱数、サイズは6*100のarray([[1番目の100こ],…,[6番目の100こ]])
X = np.random.randint(5, size=(6, 100)) # 教師データ
Y = np.array([1,2,3,4,5,6]) # クラス -> X[0]はクラス1, X[2]がクラス3のような
from sklearn.naive_bayes import MultinomialNB
# ナイーブベイズクラス
clf = MultinomialNB()
#学習
clf.fit(X, Y) # MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True) が返ってくる
print(clf.predict(X[2])) # -> 3が帰ってきたらOK

メソッドメモ

fit(X,Y)
学習器の生成
X -> 教師データ,sparseな配列。sample数 * 特徴数となる
Y -> クラス, X[0],X[2]がクラス1, x[1]がクラス2に分類されるみたいな

get_params()
パラメーター取得({'alpha': 1.0, 'class_prior': None, 'fit_prior': True}みたいな)

predict(X)
分類を実行
X -> 横幅が特徴数のarray
返り値 -> どのclassに分類されるか

predict_log_proba(X)
各々の分類確率(log)
返り値 横幅がクラス数で要素がlog(確率)のarray

predict_proba(X)
上記のlogなしver

score(X,y)
精度の平均
fitと同じ

4
6
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
4
6