日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

吴恩达 coursera ML 第七课总结+作业答案

發(fā)布時間:2025/3/15 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 吴恩达 coursera ML 第七课总结+作业答案 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

前言

學以致用,以學促用,通過筆記總結(jié),鞏固學習成果,復(fù)習新學的概念。

目錄

文章目錄

  • 前言
  • 目錄
  • 正文
    • 模型引入
    • 神經(jīng)網(wǎng)絡(luò)
  • 模型表示
    • 模型表示2
    • 例子和圖示
    • 例子與圖示2
  • 作業(yè)答案

正文

本節(jié)主要討論神經(jīng)網(wǎng)絡(luò)及其強大的功能

模型引入

非線性分類問題會帶來超多的參數(shù),也就是參數(shù)爆炸這一問題。
一個典型的例子,計算機視覺目標識別問題。
通過訓練分類器,我們可以很好的確定一個像素對應(yīng)的是不是汽車。

神經(jīng)網(wǎng)絡(luò)

神經(jīng)網(wǎng)路的發(fā)展歷史。

神經(jīng)網(wǎng)絡(luò)的誘因,大腦并沒有特定的神經(jīng)元去處理特定的任務(wù)。

模型表示

神經(jīng)元模型結(jié)構(gòu)圖
神經(jīng)元模型數(shù)學化,邏輯單元。
神經(jīng)元模型,多層感知機。
多層神經(jīng)網(wǎng)絡(luò)的數(shù)學表示和參數(shù)量。

模型表示2

神經(jīng)網(wǎng)絡(luò)向量化實現(xiàn)方法,前向傳遞計算流程。
神經(jīng)網(wǎng)絡(luò)學到了它的特征。
其他類似的神經(jīng)網(wǎng)絡(luò)架構(gòu)。

例子和圖示

非線性分類問題:異或。
簡化例子,邏輯與操作
簡化例子,或操作。

例子與圖示2

簡單例子,否操作的實現(xiàn)。
簡單例子:異或操作。
 應(yīng)用例子:手寫文本識別。

## 多分類問題

多目標識別問題,通過onehot編碼,輸出圖像里的各個類別。

輸出層也有多個神經(jīng)元。

作業(yè)答案

多分類問題
ex3.m

%% Machine Learning Online Class - Exercise 3 | Part 1: One-vs-all% Instructions % ------------ % % This file contains code that helps you get started on the % linear exercise. You will need to complete the following functions % in this exericse: % % lrCostFunction.m (logistic regression cost function) % oneVsAll.m % predictOneVsAll.m % predict.m % % For this exercise, you will not need to change any code in this file, % or any other files other than those mentioned above. %%% Initialization clear ; close all; clc%% Setup the parameters you will use for this part of the exercise input_layer_size = 400; % 20x20 Input Images of Digits num_labels = 10; % 10 labels, from 1 to 10% (note that we have mapped "0" to label 10)%% =========== Part 1: Loading and Visualizing Data ============= % We start the exercise by first loading and visualizing the dataset. % You will be working with a dataset that contains handwritten digits. %% Load Training Data fprintf('Loading and Visualizing Data ...\n')load('ex3data1.mat'); % training data stored in arrays X, y m = size(X, 1);% Randomly select 100 data points to display rand_indices = randperm(m); sel = X(rand_indices(1:100), :);displayData(sel);fprintf('Program paused. Press enter to continue.\n'); pause;%% ============ Part 2a: Vectorize Logistic Regression ============ % In this part of the exercise, you will reuse your logistic regression % code from the last exercise. You task here is to make sure that your % regularized logistic regression implementation is vectorized. After % that, you will implement one-vs-all classification for the handwritten % digit dataset. %% Test case for lrCostFunction fprintf('\nTesting lrCostFunction() with regularization');theta_t = [-2; -1; 1; 2]; X_t = [ones(5,1) reshape(1:15,5,3)/10]; y_t = ([1;0;1;0;1] >= 0.5); lambda_t = 3; [J grad] = lrCostFunction(theta_t, X_t, y_t, lambda_t);fprintf('\nCost: %f\n', J); fprintf('Expected cost: 2.534819\n'); fprintf('Gradients:\n'); fprintf(' %f \n', grad); fprintf('Expected gradients:\n'); fprintf(' 0.146561\n -0.548558\n 0.724722\n 1.398003\n');fprintf('Program paused. Press enter to continue.\n'); pause; %% ============ Part 2b: One-vs-All Training ============ fprintf('\nTraining One-vs-All Logistic Regression...\n')lambda = 0.1; [all_theta] = oneVsAll(X, y, num_labels, lambda);fprintf('Program paused. Press enter to continue.\n'); pause;%% ================ Part 3: Predict for One-Vs-All ================pred = predictOneVsAll(all_theta, X); fprintf('\nTraining Set Accuracy: %f\n', mean(double(pred == y)) * 100);

lrCostFunction.m

function [J, grad] = lrCostFunction(theta, X, y, lambda) %LRCOSTFUNCTION Compute cost and gradient for logistic regression with %regularization % J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using % theta as the parameter for regularized logistic regression and the % gradient of the cost w.r.t. to the parameters. % Initialize some useful values m = length(y); % number of training examples% You need to return the following variables correctly J = 0; grad = zeros(size(theta));% ====================== YOUR CODE HERE ====================== % Instructions: Compute the cost of a particular choice of theta. % You should set J to the cost. % Compute the partial derivatives and set grad to the partial % derivatives of the cost w.r.t. each parameter in theta % % Hint: The computation of the cost function and gradients can be % efficiently vectorized. For example, consider the computation % % sigmoid(X * theta) % % Each row of the resulting matrix will contain the value of the % prediction for that example. You can make use of this to vectorize % the cost function and gradient computations. % % Hint: When computing the gradient of the regularized cost function, % there're many possible vectorized solutions, but one solution % looks like: % grad = (unregularized gradient for logistic regression) % temp = theta; % temp(1) = 0; % because we don't add anything for j = 0 % grad = grad + YOUR_CODE_HERE (using the temp variable) % J=1/m*(-y'*log(sigmoid(X*theta))-(1-y)'*log(1-sigmoid(X*theta)))+lambda*(theta'*theta-theta(1)^2)/2/m; grad=X'*(sigmoid(X*theta)-y)/m; temp=theta*lambda/m; temp(1)=0; grad=grad+temp;% =============================================================grad = grad(:);end

onevsall.m

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(:) will return a column vector. % % Hint: You can use y == c to obtain a vector of 1's and 0's that tell you % whether the ground truth is true/false for this class. % % Note: For this assignment, we recommend using fmincg to optimize the cost % function. It is okay to use a for-loop (for c = 1:num_labels) to % loop over the different classes. % % fmincg works similarly to fminunc, but is more efficient when we % are dealing with large number of parameters. % % Example Code for fmincg: %% Set Initial thetainitial_theta = zeros(n + 1, 1); % % % Set options for fminuncoptions = optimset('GradObj', 'on', 'MaxIter', 50); % % % Run fmincg to obtain the optimal theta % % This function will return theta and the cost for i=1:num_labels [all_theta(i,:)] = ...fmincg (@(t)(lrCostFunction(t, X, y==i, lambda)), ...initial_theta, options); end% =========================================================================end

predictonevsall.m

function p = predictOneVsAll(all_theta, X) %PREDICT Predict the label for a trained one-vs-all classifier. The labels %are in the range 1..K, where K = size(all_theta, 1). % p = PREDICTONEVSALL(all_theta, X) will return a vector of predictions % for each example in the matrix X. Note that X contains the examples in % rows. all_theta is a matrix where the i-th row is a trained logistic % regression theta vector for the i-th class. You should set p to a vector % of values from 1..K (e.g., p = [1; 3; 1; 2] predicts classes 1, 3, 1, 2 % for 4 examples) m = size(X, 1); num_labels = size(all_theta, 1);% You need to return the following variables correctly p = zeros(size(X, 1), 1);% Add ones to the X data matrix X = [ones(m, 1) X];% ====================== YOUR CODE HERE ====================== % Instructions: Complete the following code to make predictions using % your learned logistic regression parameters (one-vs-all). % You should set p to a vector of predictions (from 1 to % num_labels). % % Hint: This code can be done all vectorized using the max function. % In particular, the max function can also return the index of the % max element, for more information see 'help max'. If your examples % are in rows, then, you can use max(A, [], 2) to obtain the max % for each row. % for i=1:mtemp=all_theta*X(i,:)';p(i)=find(temp==max(temp)); end % =========================================================================end

總結(jié)

以上是生活随笔為你收集整理的吴恩达 coursera ML 第七课总结+作业答案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 深夜激情视频 | 91精品国自产在线 | 国产精品久久久久毛片 | 暖暖成人免费视频 | 在线观看av片 | 亚洲熟妇无码久久精品 | 奇米影视在线播放 | 在线a免费| 欧美第一页在线观看 | 夜夜骚av一区二区三区 | 亚洲色图在线观看视频 | 久久久123 | 毛片毛片毛片毛片毛片毛片 | 欧美熟妇久久久久 | 亚洲字幕 | 久久久二区 | 国产三级全黄 | 日日夜夜网站 | 欧美巨大乳 | 一区二区三区免费播放 | 超碰福利在线观看 | 开心成人激情 | av小片| av先锋资源网 | 中国美女洗澡免费看网站 | 日日日人人人 | 亚洲生活片 | 国产精品美女久久久 | 黄色网址在线免费看 | 香蕉视频A | 日日干狠狠干 | 国产又粗又猛又爽69xx | 丰满岳妇伦在线播放 | jizzjizz日本免费视频 | 黄页网站视频在线观看 | 亚洲国产成人精品视频 | 中文字幕一区二区人妻在线不卡 | 日本一级三级三级三级 | 日韩精品一区二区三区国语自制 | 亚洲女同在线 | 日韩网红少妇无码视频香港 | 久久久精 | 丝袜亚洲综合 | 国产精品一线 | 国产一级特黄 | 黄色大片网站在线观看 | 麻豆蜜桃av| av青娱乐| 搡老熟女老女人一区二区 | 永久免费视频网站 | 第一章豪妇荡乳黄淑珍 | 国产老熟女伦老熟妇露脸 | 天堂av资源 | 一级久久久久久久 | 中文写幕一区二区三区免费观成熟 | 国产suv精品一区二区68 | 日日夜夜天天干 | 日本欧美另类 | 人人干人人舔 | www网站在线观看 | 中文字幕免费av | 亚洲3p | 亚洲av熟女国产一区二区性色 | 在线观看aaa | 精品视频一二三区 | 欧洲自拍偷拍 | 一呦二呦三呦精品网站 | www.呦呦| 亚洲免费网 | 91av综合 | 欧美亚洲综合在线 | 国产在线拍揄自揄拍无码视频 | 少妇精品一区二区三区 | 在线免费视频一区二区 | 亚洲国产综合网 | 欧美操老女人 | 黄色专区 | 九一精品国产 | 黑人玩弄人妻一区二区绿帽子 | 先锋影音资源av | 日韩视频免费在线播放 | 2021中文字幕 | 国产卡一卡二卡三 | 国产免费不卡av | 国产对白视频 | 久久久久久少妇 | avtt在线播放 | 亚洲免费av网址 | 一区二区不卡av | 草比视频在线观看 | japanese在线| 亚洲粉嫩| 国产伦精品一区二区三区视频免费 | 国内成人精品视频 | 国产在线网址 | 亚洲欧洲国产综合 | 黄色片网站在线免费观看 | 久久久久不卡 | 精品国产一区二区三区性色av |