Machine Learning Octave tutorial 2016. 3. 15 데이터 마이닝 박 영 택.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
CS231A Matlab Tutorial Philip Lee Winter Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.
Fprintf and other examples. Save command >> !ls >> a = 3; >> save afile a >> !ls afile.mat >> !dir Directory of C:\MATLAB6p5\work\save 11/21/ :30.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
Introduction to MATLAB Michael Fink Login and press the Matlab icon Part 1: Using vectors and matrices Part 2: Performing.
Arrays Revisited Selim Aksoy Bilkent University Department of Computer Engineering
Yuval Hart, Weizmann 2010 © 1 Introduction to Matlab & Data Analysis Tutorial 2 and 3: Variables and Matrix Manipulation.
Eilon Sharon, Weizmann 2008 © 1 Introduction to Matlab & Data Analysis Tutorial 2: Variables and Matrix Manipulation.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Week 3 Last week Vectors Array Addressing Mathematical Operations Array Multiplication and Division Identity Matrix Inverse of a Matrix Element by Element.
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Introduction to MATLAB
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
MATLAB Fundamentals.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
GNU/Qt Octave Rohin Kumar Y, Dept. of Physics & Astro Physics, University of Delhi.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
INTRODUCTION TO MATLAB LAB# 01
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
1 Yangon Technological University Department of Mechanical Engineering Computer Application In Mechanical Engineering I ME Dr. Yin Yin Tun Deputy.
CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation TexPoint fonts used in EMF. Read.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Octave. Getting Started Arithmetic is as usual: – What would (a-V)(V-1)V be for a=0.1 and V=-56? – Multiplication is *, division is /
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
A Quick Octave Tutorial 阮 翀
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Matlab Introduction  Getting Around Matlab  Matrix Operations  Drawing Graphs  Calculating Statistics  (How to read data)
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Outline Introduction to MATLAB Image Processing with MATLAB
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
Intro to Matlab Rogelio Long September 3, How to access MyDesktop Log in with your utep id and password.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Intro to Matlab Yipei Wang & Qihui Li {yipeiw,
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
Matlab & Image processing toolbox Heejune Ahn SeoulTech Last updated Jan.
NoViC, Dept. of Mechanical Eng Acoustics Lab., NoViC 1. Download Matlab 2.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
Octave Tutorial Basic operations Machine Learning.
Introduction to MATLAB
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATLAB Tutorial Dr. David W. Graham.
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Lecture 2 Introduction to MATLAB
Demo of Basic Matlab Features
Announcements P3 due today
MATLAB stands for MATrix LABoratory.
Presentation transcript:

Machine Learning Octave tutorial 데이터 마이닝 박 영 택

Octave Tutorial Basic operations Machine Learning

% elementary operations >> % 11 >> % 1 >> 5 * 8 % 40 >> 1 / 2 % >> 2 ^ 6 % 64 >> 1 == 2 % false >> 1 ~= 2 % true. note, not "!=" >> 1 && 0 % 0 : AND >> 1 || 0 % 1 : OR >> xor(1,0) % 1 % variable assignment >> a = 3; % semicolon suppresses output >> b = 'hi'; >> c = (3 >= 1); % Displaying them: >> a = pi % >> disp(sprintf('2 decimals: %0.2f', a)) % 2 decimals: 3.14 >> disp(sprintf('6 decimals: %0.6f', a)) % 6 decimals: >> format long >> a % >> format short >> a % Basic operations

% vectors and matrices >> A = [1 2; 3 4; 5 6] >> v = [1 2 3] % row vector >> v = [1; 2; 3] % column vector Basic operations

>> v = [1:0.1:2] % from 1 to 2, with step size of 0.1. Useful for plot axes >> v = 1:6 % from 1 to 6, assumes step size of 1 >> C = 2*ones(2,3) % same as C = [2 2 2; 2 2 2] Basic operations

>> w = zeros(1,3) >> w = rand(1,3) % drawn from a uniform distribution >> w = randn(1,3) % drawn from a normal distribution (mean=0, var=1) >> w = -6 + sqrt(10)*(randn(1,10000)) % (mean = 1, var = 2) Basic operations... until 10,000

>> hist(w) >> I = eye(4) % 4x4 identity matrix Basic operations % help function >>help rand >> help eye

Octave Tutorial Moving data around Machine Learning

% dimensions >> A = [1 2; 3 4; 5 6] >> sz = size(A) >> size(A,1) % number of rows >> size(A,2) % number of cols >> length(sz) % size of longest dimension Moving data around

% loading data >> pwd % show current directory (current path) >> cd 'C:\Users\ang\Octave files' % change directory >> ls % list files in current directory >> load q1y.dat % same with load(‘q1y.dat’) >> who % list variables in workspace >> whos % list variables in workspace (detailed view) >> clear sz % clear w/ no argt clears all >> v = q1y(1:10); >> save hello v; % save variable v into file hello.mat >> save hello.txt v -ascii; % save as ascii % fopen, fread, fprintf, fscanf also work [[not needed in class]] Moving data around

% indexing >> A(3,2) % indexing is (row,col) >> A(2,:) % 3 4 :get the 2nd row. % ":" means every element along that dimension >> A(:,2) % get the 2nd col >> A([1 3],:) Moving data around

>> A(:,2) = [10; 11; 12] % change second column >> A = [A, [100; 101; 102]] % append column vec >> A(:) % Select all elements as a column vector. Moving data around

>> A = [1 2; 3 4; 5 6] >> B = [11 12; 13 14; 15 16] % same dims as A >> [A B] >> [A; B] Moving data around

Octave Tutorial Computing on data Machine Learning

>> A = [1 2; 3 4; 5 6] >> B = [11 12; 13 14; 15 16] >> C = [1 1; 2 2] Computing on data >> A * C % matrix multiplication >> A.* B % element-wise multiplcation % A.* C or A * B gives error - wrong dimensions >> A.^ 2

>> V = [1; 2; 3] >> 1./ V >> log(V) % functions like this operate element-wise on vecs or matrices >> abs(V) Computing on data >> exp(V) % e^4 >> -V % -1*v >> V + ones(length(V), 1) % v + 1 % same >> A' % matrix transpose if A is * A = (A’)’

% max (or min) >> a = [ ] >> val = max(a) >> [val,ind] = max(a) % find >> a < 3 % true or false each index >> find(a < 3) % true index >> A = magic(3) Computing on data >> [r,c] = find(A>=7) * position : (1, 1), (3, 2), (2, 3)

>> a = [ ]; >> sum(a) >> prod(a) % product >> floor(a) % down decimal or ceil(a) is up >> max(rand(3),rand(3)) Computing on data >> max(A,[],1) % max of column and same with max(A) >> min(A,[],2) % min of row

Computing on data >> eye(9) >> sum(sum( A.* eye(9) )) >> flipud(eye(9)) >> A = magic(9) >> sum(A,1) >> sum(A,2) >> sum(sum( A.* flipud(eye(9)) )) % Matrix inverse (pseudo-inverse) >> pinv(A) % inv(A'*A)*A'

Octave Tutorial Plotting data Machine Learning

>> t = [0: 0.01: 0.98]; >> y1 = sin(2 * pi * 4 * t); >> plot(t, y1); Plotting data >> y2 = cos(2 * pi * 4 * t); >> hold on; % for drawing same canvas >> plot(t, y2, ‘r’); % ‘r’ is red line

Plotting data >> y2 = cos(2 * pi * 4 * t); >> hold on; % for drawing same canvas >> plot(t, y2, ‘r’); % ‘r’ is red line >> xlabel(‘time’) >> ylabel(‘value’) >> legend(‘sin’, ‘cos’) >> title(‘my plot’) >> print –dpng ‘myplot.png’ % save image

Plotting data >> figure(1); plot(t, y2); >> figure(2); plot(t, y2); >> subplot(1,2,1); % Divides plot a 1x2 grid, access first element >> plot(t, y1); >> subplot(1,2,2); % access second element >> plot(t, y2); >> axis([ ]) % [xStart, xEnd, yStart, yEnd]

Plotting data >> A = magic(5) >> imagesc(A) >> imagesc(A), colorbar, colormap

Octave Tutorial Control statements: for, while, if statements Machine Learning

Control statements : if, for, while >> v = zeros(10, 1) >> for i = 1:10, > v(i) = 2^i; > end; >> v >> indices = 1:10; >> for i = indices, > disp(i); > end; >> i = 1; >> while i <= 5, > v(i) = 100; > i = i+1; > end; >> i = 1; >> while true, > v(i) = 999; > i = i+1; > if i == 6, > break; > end; >> v    

Control statements : function >> function [y1, y2] = squareAndCubeThisNumber(x) > y1 = x^2; > y2 = x^3; > end; >> [q, w] = squareAndCubeThisNumber(3) % can have 2 return values q = 9 w = 27

Control statements : cost function J >> function J = costFunctionJ(X, y, theta) > % X is the “design matrix” containing our training examples. > % y is the class labels. > > m = size(X,1); % number of training examples. > predictions = X * theta; % predictions of hypothesis on all m examples > sqrErrors = (prediction – y).^ 2; > J = 1 / (2*m) * sum(sqrErrors); > > end; >> X = [1 1; 1 2; 1 2]; >> y = [1; 2; 3]; >> theta = [0; 1]; >> j = costFunctionJ(X, y, theta)

Octave Tutorial Vectorial implementation Machine Learning

Vectorial implementation Vectorization!

Vectorial implementation Vectorization!

Vectorial implementation # Octave code