AdityaSamavedam / student2

MIT License
0 stars 0 forks source link

Data Structure Writeup #6

Open AdityaSamavedam opened 5 months ago

AdityaSamavedam commented 5 months ago

Collections

Blog Python Model code and SQLite Database.

Lists and Dictionaries

Blog Python API code and use of List and Dictionaries.

image

image

The argument "hashmap" when creating a user is an example of a dictionary because it has the keys "job" and "Company" and also has its values such as "football player" and "Seattle Seahawks".

image

The return command in the function "read" outputs a dictionary with keys: id, userID, note, image and base64 and its corresponding values.

APIs and JSON

Blog Python API code and use of Postman to request and respond with JSON.

In the update function, we check that the number of characters in each name, uid, and password are greater than one character in order to update the database.

Frontend

Blog JavaScript API fetch code and formatting code to display JSON.

"fetch(url, authOptions)" gets the url from the backend server (http://127.0.0.1:8088) followed by the suffix "/api/users/authenticate". This is first done to authenticate the user, before they gain access to the array of JSON objects that are formatted into the browser's screen. When the login is successful, the page is redirected to the Database of users that was formatted in the browser. Next, the url is passed as "http://127.0.0.1:8088/api/users/" since we want to obtain the actual JSON data of the users in the database. Another fetch is done with the url and when the data is fetched, HTML formats all of it into a table, to make it resemble the SQLite database.

image

image image

image image

image

If the user's username and password match correctly, the user will be redirected to the formatted HTML database table.

image

If the user's username or password do not match correctly, or if an error is caught, then the user will not be able to access the database table, which redirects them to the 401 page, saying that they are "Unauthorized". The console logs that there was an error.

Optional/Extra, Algorithm Analysis

In the ML projects, there is a great deal of algorithm analysis. Think about preparing data and predictions.

Linear regression involves the relationship between two variables (x and y). Given a large dataset (pandas dataframe) of x and y values, the linear regression algorithm will try to find a correlation in the scatterplot and plot the line of best fit. Usually, 80% of the data is the training data, and the rest 20% is the test data. This is done so that the maximum possible accuracy is achieved. After the model is trained, it is tested with the test data. Given test x values, we get our y prediction values based on the line of best fit that was calculated during training. Linear regression is an example of supervised learning because the machine trains off data that is labeled.

Decision Trees are used mainly for classification and regression (usually logistic regression) purposes. We start at the root node (or the first node), which contains the entire dataset. Then, the algorithm splits the data based on certain criteria and new nodes are created accordingly. Then, the data is partitioned into more subsets based on the possible values of that feature. This is done repeatedly until we reach a stopping condition, and the leaf nodes (last nodes) are formed. The leaf nodes show our output as a result of the decision tree.

The picture above is an example of a decision tree being used for logistic regression, on deciding whether a person should go outside or not, based on the weather conditions.