小编Ped*_*nso的帖子

逻辑回归成本的矢量化

我有这个代码用于逻辑回归的成本,在matlab中:

function [J, grad] = costFunction(theta, X, y)

m = length(y); % number of training examples
thetas = size(theta,1);
features = size(X,2);
steps = 100;
alpha = 0.1;

J = 0;
grad = zeros(size(theta));


sums = [];
result = 0;

for i=1:m

%    sums = [sums; (y(i))*log10(sigmoid(X(i,:)*theta))+(1-y(i))*log10(1-sigmoid(X(i,:)*theta))]

    sums = [sums; -y(i)*log(sigmoid(theta'*X(i,:)'))-(1-y(i))*log(1-sigmoid(theta'*X(i,:)'))];

    %use log simple not log10, mistake
end

result = sum(sums);
J = (1/m)* result;


%gradient one step

tempo = [];
thetas_update = 0;
temp_thetas = [];


grad = temp_thetas; …
Run Code Online (Sandbox Code Playgroud)

matlab vectorization logistic-regression

13
推荐指数
1
解决办法
2万
查看次数

在matlab中规范化逻辑回归代码

我正在尝试使用正规化的LR,在matlab中使用这个公式很简单:

成本函数:

J(theta) = 1/m*sum((-y_i)*log(h(x_i)-(1-y_i)*log(1-h(x_i))))+(lambda/2*m)*sum(theta_j)
Run Code Online (Sandbox Code Playgroud)

渐变:

?J(theta)/?theta_0 = [(1/m)*(sum((h(x_i)-y_i)*x_j)] if j=0

?j(theta)/?theta_n = [(1/m)*(sum((h(x_i)-y_i)*x_j)]+(lambda/m)*(theta_j) if j>1
Run Code Online (Sandbox Code Playgroud)

这不是matlab代码只是公式.

到目前为止我已经这样做了:

function [J, grad] = costFunctionReg(theta, X, y, lambda)

J = 0;
grad = zeros(size(theta));

temp_theta = [];

%cost function

%get the regularization term

for jj = 2:length(theta)

    temp_theta(jj) = theta(jj)^2;
end

theta_reg = lambda/(2*m)*sum(temp_theta);

temp_sum =[];

%for the sum in the cost function

for ii =1:m

   temp_sum(ii) = -y(ii)*log(sigmoid(theta'*X(ii,:)'))-(1-y(ii))*log(1-sigmoid(theta'*X(ii,:)'));

end

tempo = sum(temp_sum);

J = (1/m)*tempo+theta_reg;

%regulatization
%theta 0

reg_theta0 = 0; …
Run Code Online (Sandbox Code Playgroud)

matlab machine-learning regularized logistic-regression

10
推荐指数
3
解决办法
2万
查看次数

在swift中关闭视图后iOS应用程序冻结

我的问题是我有两个viewControllers连接模态segue像普通A ---> B,A有像textFields,开关,按钮和mapView的控件,我得到userLocation.B目前只有一个按钮和一个mapView,但是当我点击退出按钮时,它确实成功解除了viewController B并显示A只有控件被冻结,不能再点击任何东西,我不知道为什么.有帮助吗?

B代码

import UIKit
import MapKit
import Parse
import CoreLocation

class MapaMososViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    @IBOutlet weak var mapMozosFollow: MKMapView!

    var totlaAutomozo: String!
    var fechaRegistro: String!


    override func viewDidLoad() {
        super.viewDidLoad()


        mapMozosFollow.delegate = self

        mapMozosFollow.showsUserLocation = true
        mapMozosFollow.showsTraffic = false
        mapMozosFollow.showsScale = false
        print(mapMozosFollow.userLocation.location)


    }

    override func viewDidAppear(_ animated: Bool) {

        self.displayError(error: "Exito", message: "Tu pago ha sido procesado, en unos momentos atenderemos tu orden. Total es de $\(totlaAutomozo!) la fecha registrada \(fechaRegistro!)")

    }
    override func …
Run Code Online (Sandbox Code Playgroud)

iphone viewcontroller ios swift

9
推荐指数
1
解决办法
2911
查看次数

matlab中的多变量梯度下降

我在matlab中为多个变量做渐变下降,并且代码没有达到我用正常eq得到的预期值.即:theta = 1.0e + 05*3.4041 1.1063 -0.0665使用Normal eq.我已经实施了.

而对于GDM,我得到的结果是:theta = 1.0e + 05*2.6618 -2.6718 -0.5954我不明白为什么会这样,也许有人可以帮助我并告诉我代码中的错误在哪里.

码:

function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters)

m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
thetas = size(theta,1);
features = size(X,2)

mu = mean(X);
sigma = std(X);
mu_size = size(mu);
sigma_size = size(sigma);

%for all iterations
for iter = 1:num_iters

tempo = [];

result = [];

theta_temp = [];

%for all the thetas    
for t = 1:thetas
    %all …
Run Code Online (Sandbox Code Playgroud)

matlab machine-learning gradient-descent

5
推荐指数
1
解决办法
1万
查看次数

Matlab抹去了我的价值观

我在Matlab上写了一个OOP,一个用于分离电子邮件的朴素的贝叶斯.像这样

 classdef NaiveClass

%NaiveClass what this will do is hold on his emails
% the p(message|class) compute the probability 
% have the specific class info as well as who are they brothers
%   

properties
    name
    numberOfMail
    laplaceCounts
    uniqueWords
    totalMails
    totalWords
    likelihoodGivenClass
    prior
end

methods
    function identify(thisNaiveClass)
        disp('I''m a bayes node')
    end

    function set = setPrior(obj)

        obj.prior = (obj.numberOfMail + 1) / (obj.totalMails + obj.laplaceCounts)

    end

    function like = setLikelihood(this)

        this.likelihoodGivenClass = (1 + 1) / (this.totalWords + 17)

    end

 end …
Run Code Online (Sandbox Code Playgroud)

oop matlab

3
推荐指数
1
解决办法
56
查看次数