Posts

CST383 - Week 2

CST383 Week 2 This week we learned about Pandas, a data analysis Python library that makes working with data tables much easier. It can make use of NumPy if needed, specifically for functions like mean().  I have had some trouble with remembering Pandas syntax. I know to use df['x'] to obtain a Series named 'x', then df[df[x]] to obtain the whole Dataframe named 'x'. Once we got to aggregation, I was also unsure when to use 'groupby' and when to use 'aggregate'. One more thing that was difficult for me to get right was how to use conditions correctly in selecting data. One of the most helpful articles to understand this better was the  user guide to Pandas. Along with this, I also found a nice cheat sheet on the Pandas home page for remembering specific syntax. Here is the link to it. I think I would need a lot more specific examples in the lecture to understand the syntax better and when to apply them.

CST383 - Week 1

CST383 Week 1 New semester! This is the Intro to Data Science course.      The reading started us off with the Iris dataset, and how to manipulate the data from it to predict future iris data (at a 97% success rate). This style of machine learning is supervised learning, where we train it on data that we know to be true. This allows us to measure the accuracy of the model in identifying irises.     For unsupervised learning, we feed data into the algorithm but do not provide any known output data that we know to be true. An example would be to create a summary of reviews of a product. There is no known output data because the reviews must be fed into the algorithm first and compare it to existing reviews in the database, and find commonalities with them.     Before creating a supervised model, the best practice is to look at your data (visually helps, like a scatter plot) and find commonalities with each feature of the samples. This can help identify i...

CST370 - Week 7

CST370 Week 7 (& 8?)      This week we learned about dynamic programming and how to use backtracking to find optimal solution paths. Instead of brute-forcing through all solution paths, dynamic programming uses a solution array that keeps track of already-calculated sub-problems in a table. Once we hit the end, we can use that table to backtrack and find the solution to the problem.      We also learned about Warshall's algorithm, which uses transitive closure to find paths from one vertex to a non-adjacent vertex in a directed graph, and Floyd's algorithm to further apply this to find the all-pairs shortest-paths matrix solution of a connected cyclic graph. The solution to Warshall's algorithm is a matrix of 0s and 1s showing if a valid path from one vertex to another is possible. If the path (row) has all 1s across, a path from that vertex (row index) can be traced to all vertices, including itself if it is part of a cycle. The solution to Floyd's alg...

CST370 - Week 6

CST370 Week 6 This week, we learned more about tree balancing and hashing.      AVL trees are self-balancing binary search trees where the balancing factor of each node is either 1 (left), 0, or -1 (right). The balancing factor is calculated by how many 'edges' traveled from the node to the last leaf it can reach (or the height of the subtree): Balancing factor = height of left subtree - height of right subtree      To maintain AVL trees, rotations may need to be made on nodes. For left-heavy trees (or subtrees), R-rotations are typically used, while right-heavy trees (or subtrees) use L-rotations. Rotations can be used multiple times in a row, like two R-rotations needed.      2-3 trees are binary search trees that must have at least 2 or 3 children to each node. Each node can contain one value or two values - if it has one value, it will have 2 children, and if it has two values, it will have 3 children. The children can contain one or two ...

CST370 - Week 5

CST370 Week 5 Binary trees: A divide-and-conquer ready data structure. There are three ways to traverse it: preorder, inorder, and postorder traversal methods. Preorder visits from root -> left -> right. Inorder visits from left -> root -> right. Postorder visits from left -> right -> root. Binary search: An application of the decrease-and-conquer algorithm. Complexity is (big O)(logn). Quicksort: For time complexity, the best case is n(logn), while the worst case is n^2. To perform a quicksort, we assign the first value of an array as the pivot, and recursively travel forward (i) and backward(j)  to find a spot where the pivot can create a partition. While traveling, we swap values of i and j whenever i > pivot and pivot > j. This should create a partition where all values preceding the pivot will be smaller than it, and all values after the pivot will be larger than it. Decrease-and-conquer: Technique to reduce the size of a problem into one smaller proble...

CST370 - Week 4

 CST370 Week 4 This week is a short week due to midterms. We learned about merge sort, which uses the divide-and-conquer method. Merge sort goes through these steps: Split the original array into two halves, until each individual element is by itself. Sort the first half recursively Sort the second half recursively Merge the two halves together: Compare the first elements of each half Push smaller element to a new result array Increment index of half that pushed the smaller element (Repeat Steps 1-3 until all elements are sorted) For Master Theorem, the time complexity of merge sort is  θ [n*log(n)]. There are two recursive calls, so a = 2, the input size divides by 2 each time, so b = 2, and since the number of comparisons is n, (n^d) = (n^1) => d = 1. I wanted to understand how to derive the Master Theorem from pseudocode, so I looked up some practice exercises online, but there is very little found for it. I decided to get the textbook because I need more exercises to un...

CST370 Week 3

Image
CST370 Week 3      This week I studied a lot more about recursion and search algorithms in order to understand the homework better.       We learned about brute force algorithms like exhaustive search, which is useful in finding all permutations of a set. Exhaustive search goes through each possible case and then identifies which of these cases is either most efficient or solves the problem. The time complexity for exhaustive search is dependent on the number of permutations it has [ (n - 1)! ].      There are two graph traversal algorithms: depth-first search (DFS) and breadth-first search (BFS).       DFS makes use of a stack and a mark array to determine what nodes have been visited, and creates a tree with tree edges. Time efficiency for DFS is dependent on the sum of the number of vertices and edges it has: 𝚯 (|v| + |e|).     BFS makes use of a queue and a mark array to determine what nodes have been v...