From 3d48529b7373a5aa894ed5894e6556c2f95cf172 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 6 Jun 2024 12:21:17 +0200 Subject: [PATCH] update exam file --- FinalExam_lastname_mnr.ipynb | 131 +++++++++++++++++++++++------------ 1 file changed, 87 insertions(+), 44 deletions(-) diff --git a/FinalExam_lastname_mnr.ipynb b/FinalExam_lastname_mnr.ipynb index cfa2358..c2a393b 100644 --- a/FinalExam_lastname_mnr.ipynb +++ b/FinalExam_lastname_mnr.ipynb @@ -46,7 +46,8 @@ "metadata": {}, "source": [ "Name:\n", - "Mat Number:" + "Mat Number:\n", + "Jupyter Username:" ] }, { @@ -189,7 +190,7 @@ "source": [ "### Question 1: Describing and Testing the Code (4 Points)\n", "\n", - "Break down and explain each line of the provided code snippet. Additionally, describe the role of the '%' symbol in this context. Why is it necessary within this code?" + "a) Break down and explain each line of the provided code snippet. Additionally, describe the role of the '%' symbol in this context. Why is it necessary within this code?" ] }, { @@ -218,24 +219,32 @@ " return dataset" ] }, + { + "cell_type": "raw", + "id": "654d26a8-ed35-4c99-b0ab-43c9371a7b21", + "metadata": {}, + "source": [ + "# add your Answer to a)" + ] + }, { "cell_type": "markdown", "id": "afa185ff-bd11-4c2b-ae55-277217c63bf8", "metadata": {}, "source": [ - "Test the above code on the *data.csv* and print the result." + "b) Test the above code on the *data.csv* and print the result." ] }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 3, "id": "5d7a7ac6-5a5c-422c-b310-82b2779cd7fe", "metadata": { "tags": [] }, "outputs": [], "source": [ - "# your code" + "# your code for b)" ] }, { @@ -252,7 +261,7 @@ "metadata": {}, "source": [ "### Question 2: Write a short Function (4 Points)\n", - "Write a short function which calculates the variance of a dataset and returns it. (hint: to perform x² use ** instead of ^, Pandas is not allowed)" + "a) Write **your own** short function which calculates the variance of a dataset and returns it. (hint: to perform x² use ** instead of ^; only core-functions of python are allowed)" ] }, { @@ -277,14 +286,25 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 1, "id": "8df48b65-79be-4a7f-8f47-cdecaa11d390", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "ename": "IndentationError", + "evalue": "expected an indented block after function definition on line 2 (3899112808.py, line 5)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[1], line 5\u001b[0;36m\u001b[0m\n\u001b[0;31m def calc_variance(dataset):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block after function definition on line 2\n" + ] + } + ], "source": [ - "# your function" + "# your function for a)\n", + "def calc_variance(dataset):\n", + " # your Code" ] }, { @@ -292,19 +312,19 @@ "id": "c7ff344b-f9d2-4ee8-8ad9-ce3be8ecbb33", "metadata": {}, "source": [ - "Test your code on the data.csv table below and print the results:" + "b) Test your code on the **data.csv** table below and print the results:" ] }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 4, "id": "705b0c3b-72a0-438d-a9b7-dbb5600aa9c3", "metadata": { "tags": [] }, "outputs": [], "source": [ - "# your test code" + "# your test code for b)" ] }, { @@ -329,7 +349,7 @@ "id": "36d73f9a-2716-4e39-81e8-bb906380f250", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for a):" ] }, { @@ -345,7 +365,7 @@ "id": "61969d27-0b98-410c-bffc-16a1de912972", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for b):" ] }, { @@ -362,7 +382,7 @@ "metadata": {}, "source": [ "### Question 4: Databases (6 Points)\n", - "Put the following code into the correct order and run it. Describe each line with comments:" + "Put the following code into a **logical** correct order and run it. Describe each line with comments:" ] }, { @@ -528,7 +548,7 @@ "metadata": {}, "source": [ "### Question 5: Data Analyzer (4 Points)\n", - "Design a Python class, DataAnalyzer, to facilitate the analysis and visualization of data stored in a database. The class should provide methods to create a SQLite database from a DataFrame and plot the data using Matplotlib." + "a) Design a Python class, DataAnalyzer, to facilitate the analysis and visualization of data stored in a database. The class should provide methods to create a SQLite database from a DataFrame and plot the data using Matplotlib. Write down only the code for the **create_database** method." ] }, { @@ -541,7 +561,7 @@ "- x_values: A list with x-values.\n", "- y_values: A list with y-values.\n", "\n", - "Method: create_database\n", + "**Method: create_database**\n", "- Connect to the SQLite database specified by database_name.\n", "- Create a table and insert the x and y values.\n", "- Print the number of entries in the database after creating.\n", @@ -560,7 +580,7 @@ }, "outputs": [], "source": [ - "# your Class:\n", + "# your Class from a):\n", "class DataAnalyzer:\n", " def __init__(self, database_name, x_values, y_values):\n", " self.database_name = database_name\n", @@ -569,7 +589,6 @@ "\n", " def create_database(self):\n", " # Your Code\n", - " pass\n", "\n", " def plot_values(self):\n", " \"\"\"\n", @@ -588,19 +607,19 @@ "id": "30605de1-8eb0-4403-a36b-d22418341e9e", "metadata": {}, "source": [ - "Test your code below on *coordinates.csv*. The name of the database should be your *matr. nr.* You should test both functions! (for import use pandas or csv)" + "b) Test your code below on **coordinates.csv**. The name of the database should be your **matr. nr.** You should test both functions! (for import you can use pandas or csv)" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "id": "6ea4c395-1246-4530-994b-9c764a5c57ed", "metadata": { "tags": [] }, "outputs": [], "source": [ - "# your test code:" + "# your test code from b):" ] }, { @@ -626,19 +645,19 @@ "id": "f110bc78-13dc-4251-af7a-32bff74ce5bc", "metadata": {}, "source": [ - "a) Describe the following code with comments." + "a) Describe the following code with comments and rename the function. (directly in the code)" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 6, "id": "3f6d6805-5e97-4fbd-b202-4020e9485643", "metadata": { "tags": [] }, "outputs": [], "source": [ - "def function(X, y, factor=0.2):\n", + "def func_q6(X, y, factor=0.2):\n", " idx = np.arange(X.shape[0])\n", " np.random.shuffle(idx)\n", " X = X[idx]\n", @@ -666,7 +685,7 @@ "id": "c9dbe438-5c74-4a02-8ea3-efc0e966e483", "metadata": {}, "source": [ - "b) Why do we need the above code?" + "b) Describe the purpose of the above code?" ] }, { @@ -674,7 +693,7 @@ "id": "161a52a4-79e2-4401-ba8a-6f680d47771e", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for b):" ] }, { @@ -692,7 +711,7 @@ "id": "e998c866-416e-457d-aee8-d1034ae21f84", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for c):" ] }, { @@ -708,7 +727,7 @@ "id": "8d3ec404-4508-413c-9d00-9ce1f24c492f", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for d):" ] }, { @@ -754,7 +773,7 @@ "id": "d67a67c9-b129-412c-b29b-2869892fcf88", "metadata": {}, "source": [ - "a) Why do we need linear regression?" + "a) Describe the purpose of linear regression?" ] }, { @@ -762,7 +781,7 @@ "id": "29d16a49-69d4-4c59-921a-33201fa04d95", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for a):" ] }, { @@ -770,7 +789,7 @@ "id": "43ef5af3-9da0-4dc0-84e1-4731f5687040", "metadata": {}, "source": [ - "b) What is the difference of using scikit-learn for linear regression and your own method?" + "b) How does the result differ when using the scikit-learn library for linear regression and the class above?" ] }, { @@ -778,7 +797,7 @@ "id": "b6bcafd8-8e89-4fa6-888f-f30a93b019ec", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for b):" ] }, { @@ -786,7 +805,7 @@ "id": "fdb3bd28-59ca-47ec-a750-79652cbc7d74", "metadata": {}, "source": [ - "c) Write down the function of the mean squared error? When do you use it?" + "c) Write down the function of the mean squared error (mathematically)? When do you use it?" ] }, { @@ -794,7 +813,7 @@ "id": "791be49f-75ea-43a0-825a-0567ecf72aa1", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for c):" ] }, { @@ -802,7 +821,7 @@ "id": "24b784d2-005e-4537-b0ce-c534f0303ced", "metadata": {}, "source": [ - "d) Describe step per step how you would perform linear regression on a given dataset. (more detailed answer)" + "d) Describe step by step how you would perform linear regression on a given dataset. (more detailed answer)" ] }, { @@ -810,7 +829,7 @@ "id": "c6b02c04-2ad1-48f2-9719-14df04846d8e", "metadata": {}, "source": [ - "Your Answer:" + "Your Answer for d):" ] }, { @@ -827,17 +846,17 @@ "metadata": {}, "source": [ "### Question 8: Linear Regression Coding (4 Points)\n", - "Perform linear regression on the *winequality-red.csv* with the target *alcohol* (pandas is allowed). Calculate the mean squared error and print it. Perform the task without preprocessing your data. It is necessary to split the data. " + "a) Perform linear regression on the **winequality-red.csv** with the target **alcohol** (pandas is allowed). Calculate the **mean squared error** and **print** it. Perform the task without preprocessing your data. It is necessary to **split the data**. " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "8f36613b-ecb5-40b0-9918-4119cb8943e2", "metadata": {}, "outputs": [], "source": [ - "#your Code" + "# your Code for a)" ] }, { @@ -854,7 +873,7 @@ "metadata": {}, "source": [ "### Question 9: Gaussian Processes (6 Points)\n", - "Fit the names to the different kernels below:" + "a) Fit the names to the different kernels below:" ] }, { @@ -864,7 +883,7 @@ "tags": [] }, "source": [ - "Add the Names:\n", + "Add the Names to the following lines:\n", "\n", "1. **... Kernel**: $k(x, x') = \\exp \\left( -2 \\sin^2 \\left( \\frac{\\pi ||x - x'||}{p} \\right) \\right) / \\sigma^2 $\n", "2. **... Kernel**: $k(x, x') = x^T x' $\n", @@ -877,7 +896,7 @@ "id": "1759762b-5b0a-4e6f-9651-277bc4643fb4", "metadata": {}, "source": [ - "Fit the above numbers to the code below" + "b) Fit the above **numbers** to the lines below." ] }, { @@ -885,7 +904,7 @@ "id": "0c6ddc30-f804-472c-92d1-8a03d3c3b020", "metadata": {}, "source": [ - "Your Answer:\n", + "Your Answer for b):\n", " function1 = ...\n", " function2 = ...\n", " function3 = ...\n", @@ -989,6 +1008,30 @@ "source": [ "___________________________" ] + }, + { + "cell_type": "markdown", + "id": "b5042b38-0752-4e23-aae3-3651a5f367cf", + "metadata": {}, + "source": [ + "### How to submit your file:\n", + "1) Save your file in the Jupyter Notebook (Floppy Disk Symbol)\n", + "2) Download only your jupyter-file (right-click and download)\n", + "3) Change the window to Moodle again (bottom-left corner)\n", + "4) Upload your file on Moodle\n", + "5) Submit your full exam\n", + " - Finish attempt ...\n", + " - Submit all and finish (First Time)\n", + " - Submit all and finish (Second Time)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5808cbd3-51da-40fd-a770-057156cd7465", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {