Skip to main content

Posts

[Machine Learning]: #2 Model and Cost Function

[Machine Learning]: Model and Cost Function Outline: 1) Linear Regression Model 2) Cost Function 3) Math Model Linear Regression Model First, we give an example of the linear regression model, the example as follows, we are given the house size and house price, we want to know the "relation" between the house price and house size. What should we do?           House Size(\(x\)):  \([2104, 2000, 1216, 1234, 852, 737, 469, 220]\);           House Price(\(y\)):  \([460, 300, 232, 315, 178, 177, 140, 100]\); T o describe the supervised learning problem slightly more formally, our goal is, given a training set, to learn a function H (H is the Hypothesis Fucntion) : X → Y so that h(x) is a “good” predictor for the corresponding value of y. For historical reasons, this function h is called a hypothesis. Seen pictorially, the process is therefore like this:          -> input:   \(x_{i}\)                       -> output:   \(y_{i}\)             When

[Machine Learning]: #1 Introduction

[Machine Learning]: Introduction ****************** 1.What is machine learning? The field of study that gives computers the ability to learn without being explicitly programmed.                                                                                                       - Arthur Samuel   A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E                                                                                                         - Tom Mitchell ****************** 2. Supervised Learning: In supervised learning, we are given a data set and already know what our correct output should look like, having the idea that there is a relationship between the input and the output. Supervised learning problems are categorized into " regression " and " classification " problems.  In a r

[LeetCode Solution 230]: Kth Smallest Element in a BST

Question: Given a binary search tree, write a function  kthSmallest  to find the  k th smallest element in it. ************************************************************************************************************************************ Write Infront To read to a tutorial, please to read the tutorial of in-order traversal of BST, please check: LeetCode Solution 94: Binary Tree Inorder Traversal We are going to solve this question using the following 4 methods: ->Binary Search ->Recursive ->Iterative ->Morris  Approach #1 Binary Search [Accepted] Detail Explanation The first method to solve this problem is using Binary Search. The idea is very easy and extremely to think. We use BST's property that the left child of the root is smaller than the root while the right child of the root is always bigger. We consider that the root is the pivot, and find the number of the nodes in the left subtree and the number of the nodes in th

[LeetCode Solution 98] Validate Binary Search Tree

Question: Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node contains only nodes with keys greater than the node’s key. Both the left and right subtrees must also be binary search trees. Example 1 : 2 / \ 1 3 Binary tree [ 2 , 1 , 3 ], return true . Example 2 : 1 / \ 2 3 Binary tree [ 1 , 2 , 3 ], return false . 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 Write Before The problem is same to the BST Inorder Traversal:  LeetCode 94  !!! Why? Because the inorder traversal get the order from root.left -> root -> root.right, if the ValidBST is true, the inorder traversal is ascending order. How to implement inorder traversal in BST? ->Recursive Method ->Iterative Method ->Morris Method The tutorial