上传者: 27184353
|
上传时间: 2022-05-19 23:22:20
|
文件大小: 786KB
|
文件类型: ZIP
机器学习实验课内容实现逻辑回归和神经网络
% 读入数据
X = load('logistic_x.txt'); Y = load('logistic_y.txt');
X = [ones(size(X, 1), 1) X];
% 计算 theta
theta = log_regression(X ,Y);
% 绘制图像
figure; hold on;
plot(X(Y < 0, 2), X(Y < 0, 3), 'rx', 'linewidth', 2);
plot(X(Y > 0, 2), X(Y > 0, 3), 'go', 'linewidth', 2);
x1 = min(X(:,2)):.01:max(X(:,2));
x2 = -(theta(1) / theta(3)) - (theta(2) / theta(3)) * x1;
plot(x1,x2, 'linewidth', 2); xlabel('x1'); ylabel('x2');