diff --git a/02_activities/assignments/Assignment2.md b/02_activities/assignments/Assignment2.md index a95a027fd..064035ade 100644 --- a/02_activities/assignments/Assignment2.md +++ b/02_activities/assignments/Assignment2.md @@ -54,7 +54,7 @@ The store wants to keep customer addresses. Propose two architectures for the CU **HINT:** search type 1 vs type 2 slowly changing dimensions. ``` -Your answer... +The difference between type 1 and type 2 slowly changing dimensions is that type 1 would overwrite the old value with a new value with no retention of history. In comparison type 2 would retain both the current and the historical recorded value. ``` *** @@ -182,5 +182,12 @@ Consider, for example, concepts of labour, bias, LLM proliferation, moderating c ``` -Your thoughts... +The ethical issues that are important to this story are concepts of labour, LMM proliferation and bias in LMMs. The author discusses how our society’s perception of AI systems isn’t necessarily accurate. We perceive these systems to be independent of humans and don’t often think about the amount of human work that’s gone into building them. She emphasized the importance of the datasets that were used to train AI systems and how that work is completed by human annotators for minimal compensation (10$ an hour). This calls into question the power balance between the human annotators that are making minimal financial gains and then big tech companies that are reaping enormous profits from their systems. + +She emphasized that ‘every single piece of decision-making in a high-tech neural network initially rests on a human being manually putting something together and making a choice.’ The article underscores the involvement of human input and how it inevitably introduces bias into AI systems. For instance, in ImageNET Roulette different individuals assigned offensive and negative labels to an image of a man. This raises the issue of how societal prejudice can become embedded in AI and amplify these preconceptions instead of eliminating them. + +In response, designers of these training databases are proposing changes to their systems like removing offensive synsets. However perhaps a better approach would be to hire annotators with more diversity that have a range of perspectives. + +This article brings up important topics of discussion as LMM proliferation is happening at a staggering pace and being implemented into our daily lives, digital services, at our workplaces. With this in mind, big tech companies should be transparent about the data they use to train their models and take an honest and ethical approach in training them to eliminate societal biases. + ``` diff --git a/02_activities/assignments/Prompt1.png b/02_activities/assignments/Prompt1.png new file mode 100644 index 000000000..cc4e01ab8 Binary files /dev/null and b/02_activities/assignments/Prompt1.png differ diff --git a/02_activities/assignments/Prompt2.png b/02_activities/assignments/Prompt2.png new file mode 100644 index 000000000..af4b81832 Binary files /dev/null and b/02_activities/assignments/Prompt2.png differ diff --git a/02_activities/assignments/Prompt3Type1.png b/02_activities/assignments/Prompt3Type1.png new file mode 100644 index 000000000..327aac586 Binary files /dev/null and b/02_activities/assignments/Prompt3Type1.png differ diff --git a/02_activities/assignments/Prompt3Type2.png b/02_activities/assignments/Prompt3Type2.png new file mode 100644 index 000000000..ea5f7899c Binary files /dev/null and b/02_activities/assignments/Prompt3Type2.png differ diff --git a/02_activities/assignments/assignment2.sql b/02_activities/assignments/assignment2.sql index 5ad40748a..43f04119c 100644 --- a/02_activities/assignments/assignment2.sql +++ b/02_activities/assignments/assignment2.sql @@ -20,6 +20,14 @@ The `||` values concatenate the columns into strings. Edit the appropriate columns -- you're making two edits -- and the NULL rows will be fixed. All the other rows will remain the same.) */ +SELECT + COALESCE( + product_name || ', ' || + COALESCE(product_size, '') || ' (' || + COALESCE(product_qty_type, 'unit') || ')', + '' + ) AS prod_info +FROM product; --Windowed Functions @@ -31,19 +39,39 @@ You can either display all rows in the customer_purchases table, with the counte each new market date for each customer, or select only the unique market dates per customer (without purchase details) and number those visits. HINT: One of these approaches uses ROW_NUMBER() and one uses DENSE_RANK(). */ - +SELECT +customer_id, +market_date, +ROW_NUMBER () OVER(PARTITION BY customer_id ORDER BY market_date) AS Visits +FROM customer_purchases + /* 2. Reverse the numbering of the query from a part so each customer’s most recent visit is labeled 1, then write another query that uses this one as a subquery (or temp table) and filters the results to only the customer’s most recent visit. */ +SELECT * +FROM +(SELECT +customer_id, +market_date, +ROW_NUMBER () OVER(PARTITION BY customer_id ORDER BY market_date DESC) AS Visits +FROM customer_purchases ) + WHERE Visits = 1 + /* 3. Using a COUNT() window function, include a value along with each row of the customer_purchases table that indicates how many different times that customer has purchased that product_id. */ - +SELECT +customer_id, +product_id, +COUNT (*) +AS times_purchased +FROM customer_purchases +GROUP BY customer_id, product_id; -- String manipulations /* 1. Some product names in the product table have descriptions like "Jar" or "Organic". @@ -57,11 +85,26 @@ Remove any trailing or leading whitespaces. Don't just use a case statement for Hint: you might need to use INSTR(product_name,'-') to find the hyphens. INSTR will help split the column. */ - +SELECT +product_name, +CASE +WHEN +INSTR(product_name, '-') > 0 +THEN TRIM(SUBSTR(product_name, INSTR(product_name, '-') + 1) ) +END AS product_description +FROM product /* 2. Filter the query to show any product_size value that contain a number with REGEXP. */ - +SELECT +*, +CASE +WHEN +INSTR(product_name, '-') > 0 -- find position of hyphen in product name column +THEN TRIM(SUBSTR(product_name, INSTR(product_name, '-') + 1) ) -- SUBSTR would take the substring after the hyphen position plus one.... The TRIM would remove white space +END AS product_description +FROM product +WHERE product_size REGEXP '[0-9]+' -- UNION /* 1. Using a UNION, write a query that displays the market dates with the highest and lowest total sales. @@ -73,8 +116,28 @@ HINT: There are a possibly a few ways to do this query, but if you're struggling 3) Query the second temp table twice, once for the best day, once for the worst day, with a UNION binding them. */ +CREATE TEMP TABLE Market_day_profit AS +SELECT + market_date, + SUM(quantity * cost_to_customer_per_qty) AS total_cost +FROM customer_purchases +GROUP BY market_date; +CREATE TEMP TABLE RANKED_SALES AS +SELECT *, +RANK () OVER(ORDER BY total_cost DESC) as best_rank, +RANK () OVER(ORDER BY total_cost ASC) as worst_rank +FROM temp.Market_day_profit +SELECT market_date, total_cost, 'Best Day' AS type_of_day +FROM RANKED_SALES +WHERE best_rank = 1 + +UNION + +SELECT market_date, total_cost, 'Worst Day' AS type_of_day +FROM RANKED_SALES +WHERE worst_rank = 1; /* SECTION 3 */ @@ -90,6 +153,17 @@ How many customers are there (y). Before your final group by you should have the product of those two queries (x*y). */ +SELECT + p.product_name, + v.vendor_name, + (vi.original_price * 5) AS base_project_profit, + (vi.original_price * 5 * (SELECT COUNT(*) FROM customer)) AS total_project_profit + +FROM vendor_inventory vi +INNER JOIN product p ON p.product_id = vi.product_id +INNER JOIN vendor v ON v.vendor_id = vi.vendor_id +CROSS JOIN (SELECT COUNT(*) AS num_customers FROM customer) cc +GROUP BY p.product_name, v.vendor_name, vi.original_price; -- INSERT /*1. Create a new table "product_units". @@ -97,11 +171,17 @@ This table will contain only products where the `product_qty_type = 'unit'`. It should use all of the columns from the product table, as well as a new column for the `CURRENT_TIMESTAMP`. Name the timestamp column `snapshot_timestamp`. */ +CREATE TABLE product_units AS +SELECT *, CURRENT_TIMESTAMP AS timestamp +FROM product +WHERE product_qty_type = 'unit' /*2. Using `INSERT`, add a new row to the product_units table (with an updated timestamp). This can be any product you desire (e.g. add another record for Apple Pie). */ - +INSERT INTO product_units +VALUES +(24, 'Apple Pie', '10"', 3, 'unit', CURRENT_TIMESTAMP) -- DELETE @@ -109,7 +189,9 @@ This can be any product you desire (e.g. add another record for Apple Pie). */ HINT: If you don't specify a WHERE clause, you are going to have a bad time.*/ - +DELETE FROM product_units +WHERE product_name = 'Apple Pie' +AND timestamp = (SELECT MIN(timestamp) FROM product_units WHERE product_name = 'Apple Pie') -- UPDATE /* 1.We want to add the current_quantity to the product_units table. @@ -129,5 +211,22 @@ Finally, make sure you have a WHERE statement to update the right row, When you have all of these components, you can run the update statement. */ +ALTER TABLE product_units +ADD current_quantity INT; + +UPDATE product_units +SET current_quantity = ( + SELECT COALESCE(vi.quantity, 0) + FROM vendor_inventory vi + + JOIN ( + SELECT product_id, MAX(market_date) AS last_day + FROM vendor_inventory + GROUP BY product_id + ) latest_inventory +ON vi.product_id = latest_inventory.product_id +AND vi.market_date = latest_inventory.last_day + WHERE vi.product_id = product_units.product_id +); \ No newline at end of file