function [all_theta] = oneVsAll(X, y, num_labels, lambda)
%ONEVSALL trains multiple logistic regression classifiers and returns all
%the classifiers in a matrix all_theta, where the i-th row of all_theta
%corresponds to the classifier for label i
% [all_theta] = ONEVSALL(X, y, num_labels, lambda) trains num_labels
% logistic regression classifiers and returns each of these classifiers
% in a matrix all_theta, where the i-th row of all_theta corresponds
% to the classifier for label i
% Some useful variables
m = size(X, 1);
n = size(X, 2);
% You need to return the following variables correctly
all_theta = zeros(num_labels, n + 1);
% Add ones to the X data matrix
X = [ones(m, 1) X];
% ====================== YOUR CODE HERE ======================
% Instructions: You should complete the following code to train num_labels
% logistic regression classifiers with regularization
% parameter lambda.
%
% Hint: theta(:) w
吴恩达的机器学习编程作业8:oneVsAll 多分类问题
最新推荐文章于 2024-03-21 17:11:52 发布
该博客详细介绍了如何使用oneVsAll方法来解决多分类问题,通过训练num_labels个逻辑回归分类器。文章中提供了一个函数`oneVsAll`,该函数将数据X和对应的标签y作为输入,并使用正则化参数lambda,返回一个包含所有分类器参数的矩阵。在代码中,使用fmincg优化器迭代地为每个类别训练模型,最终将训练好的模型参数存储在all_theta矩阵中。

最低0.47元/天 解锁文章
9941

被折叠的 条评论
为什么被折叠?



