【问题标题】:Can't fit a logistic regression model for the Iris dataset无法为 Iris 数据集拟合逻辑回归模型
【发布时间】:2017-10-08 02:07:50
【问题描述】:

尝试使逻辑回归模型在 iris 数据集上工作,但不合适。代码有什么问题。谢谢你。。

# 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)

【问题讨论】:

标签: python-3.x numpy matplotlib logistic-regression gradient-descent


【解决方案1】:

Iris 数据集包含三个输出类,这意味着您的代码应该执行多项回归。大多数情况下,二项式回归是多种工具中采用的一种,这意味着输入数据集必须仅包含两个输出类。请交叉检查您的代码是否处理三个类,然后继续...这可能是您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2016-12-24
    • 2019-02-14
    • 2019-09-15
    • 2020-12-22
    相关资源
    最近更新 更多