0

試圖使虹膜數據集適用邏輯迴歸模型,但它不合適。代碼有什麼問題。謝謝。不適合虹膜數據集的邏輯迴歸模型

# Dependencies used: numpy, matpotlib.pyplot, csv 
# dataset: Iris 
# Binary classification using gradient descent 
# python 3.5 
# input data matrix = x(99 X 1) # including ones vector 
# discrete output data matrix = y(99 X 1) 
# parameters matrix = theta(5 X 1) 

for j in range(3500): 
    # hypothesis function 
    h = 1/(1 + np.exp(-x.dot(theta))) 

    # gradient descent 
    theta = theta - (0.00001/m) * np.sum(x.T.dot(h - y)) + (30.0/m)*np.sum(np.sum(theta[1:5, :]**2)) 

    # cost function 
    cost = -(1/m) * np.sum(y.T.dot(np.log(h)) + (1-y).T.dot(np.log(1-h))) 
    j_iter.append(cost) 
    Iter.append(j) 

This is the graph [image]

+0

這沒有[mcve]。 – ImportanceOfBeingErnest

回答

0

虹膜數據集包含三個輸出類,這意味着你的代碼應執行多項式迴歸。大多數二項迴歸是幾種工具中採用的一種,這意味着輸入數據集只能包含兩個輸出類。請仔細檢查你的代碼是否處理了三個類,然後繼續......這可能是你的問題。