2017-10-02 8 views
0

私たちはsklearn.neural_networkのMLPClassifierを使用しており、クラシファイアによって生成されたバイアスと重みの分析を行っています。scikit-learnでのバイナリ分類の重みとバイアスの次元

バイナリデータがある場合、2つの値しか許可されない場合に問題があります。それで最後の層の寸法が1でなく2であるように思えます。 バイアスの形と重さが常に出力値の数と一致するように見える場合があります。

binary_classifier= MLPClassifier().fit(np.matrix([[0.], [1.]]), np.array([0,1])) 
other_classifier = MLPClassifier().fit(np.matrix([[0.], [1.], [2]]), np.array([0,1,2])) 

# Note that the dimension below is 1 
print(binary_classifier.intercepts_[-1].shape, binary_classifier.coefs_[-1].shape) 
# Note that the dimension below is 3 
print(other_classifier.intercepts_[-1].shape, other_classifier.coefs_[-1].shape) 

出力:

(1,) (100, 1) 
(3,) (100, 3) 

それはあなたがこれを行うことができますし、私はそれが最適であると仮定し、私たちは一般化を失うことを数学的に理にかなっています。 シキットがこれをするのを防ぐ簡単な方法はありますか?そうでなければ、重みとバイアスを変換して、その次元が値の数と一致するようにすることができますか?

答えて

1

ニューラルネットワークのクラスラベルは1つのホットエンコーディングを必要とし、これはMLPClassifierのフードの下で発生します。私が見てしまう。この前処理ステップを実行する方法の詳細について

((2,), (100, 2)) 
((3,), (100, 3)) 

#Now one hot encoded 
binary_classifier= MLPClassifier().fit(np.matrix([[0.], [1.]]), np.array([[1, 0], [0, 1]])) 
# NOT encoded 
other_classifier = MLPClassifier().fit(np.matrix([[0.], [1.], [2]]), np.array([0,1,2])) 

# Note that the dimension below is 2 
print(binary_classifier.intercepts_[-1].shape, binary_classifier.coefs_[-1].shape) 
# Note that the dimension below is 3 
print(other_classifier.intercepts_[-1].shape, other_classifier.coefs_[-1].shape) 

出力リレー:あなたが明示的に1つのホットエンコードされたターゲットに渡すなら、あなたは所望の出力を得ますdocumentation scikitで。

関連する問題