question 6
1. Set a random seed for reproducibility.
2. Generate a regression dataset with 250 examples:
a. Generate 250 random values for input (X) uniformly drawn from the range (0, 2).
b. Add Gaussian noise with zero mean and standard deviation 0.04 to create the output (y) using the formula: y = X^3 - 3*X^2 + 2*X + ε.
3. Split the dataset into a train set (150 examples) and a test set (100 examples) using train_test_split.
4. Define a K-NN regression model with K=5 and weighted by the inverse of distance.
5. Train the K-NN model on the train set.
6. Make predictions with the K-NN model on the test set.
7. Compute the Mean Squared Error (MSE) for the K-NN model by comparing its predictions to the true values in the test set.
8. Visualize the K-NN model:
a. Generate 100 evenly spaced points between 0 and 2.
b. Use the trained K-NN model to predict the outputs for these points.
c. Plot the train set, test set, and K-NN predictions on the same graph.
9. Train a Decision Tree regression model on the train set using sklearn's default settings.
10. Make predictions with the Decision Tree model on the test set.
11. Compute the MSE for the Decision Tree model on the test set.
12. Visualize the Decision Tree model in a manner similar to step 8.
13. Compare the MSE values of the K-NN and Decision Tree models.
a. If K-NN's MSE is lower, print "K-NN performs better on the dataset."
b. Otherwise, print "Decision Tree performs better on the dataset."
Step by stepSolved in 4 steps with 5 images
- Below are some rows of the PROVIDERS table for a factory: PCODE NAME PHONE 10192 Hans, Inc. 231 - 3092 98411 Tools and More 231 - 1029 0489035 Motors Inc. 993 - 1821 All providers from the factory zone of the city start with 231. You want to get the providers that are in the factory zone of the city. Which of the following is more appropriate? a. SELECT * FROM PROVIDERS WHERE PHONE LIKE ‘%231%’ b. SELECT * FROM PROVIDERS WHERE PHONE LIKE ‘% 231’ c. SELECT * FROM PROVIDERS WHERE PHONE LIKE ‘___ 231 ___’ d. SELECT * FROM PROVIDERS WHERE PHONE LIKE ‘231%’arrow_forwardSQL: Dog DataIn each question below, you will define a new table based on the following tables.CREATE TABLE parents ASSELECT "abraham" AS parent, "barack" AS child UNIONSELECT "abraham" , "clinton" UNIONSELECT "delano" , "herbert" UNIONSELECT "fillmore" , "abraham" UNIONSELECT "fillmore" , "delano" UNIONSELECT "fillmore" , "grover" UNIONSELECT "eisenhower" , "fillmore";CREATE TABLE dogs ASSELECT "abraham" AS name, "long" AS fur, 26 AS height UNIONSELECT "barack" , "short" , 52 UNIONSELECT "clinton" , "long" , 47 UNIONSELECT "delano" , "long" , 46 UNIONSELECT "eisenhower" , "short" , 35 UNIONSELECT "fillmore" , "curly" , 32 UNIONSELECT "grover" , "short" , 28 UNIONSELECT "herbert" , "curly" , 31;CREATE TABLE sizes ASSELECT "toy" AS size, 24 AS min, 28 AS max UNIONSELECT "mini" , 28 , 35 UNIONSELECT "medium" , 35 , 45 UNIONSELECT "standard" , 45 , 60; Q2: By Parent HeightCreate a table by_parent_height that has a column of the names of all dogs that have a parent,ordered by the height…arrow_forwardIn SQL, you use the __ statement to retrieve the rows in a table. Question 7 options: SELECT FROM WHERE QUERYarrow_forward
- The Colombia City office of StayWell indicated that there is a new tenant by the name of Yigit Yilmaz staying at the property with an ID of 13. You need to include this new resident in the RESIDENTS table.arrow_forwardWhich clause of a SQL Select statement is required if we want to display aggregate data by category such as total population by state, department, etc.? Question 40 options: 1) GROUP BY 2) ORDER BY 3) WHERE 4) FROM 5) SELECTarrow_forwardQuestion 13: Evaluate ACE16 +102 10 and show the answer in octal form.arrow_forward
- Below are some rows of the PROVIDERS table for a factory: PCODE 10192 98411 0489035 NAME Hans, Inc. Tools and More Motors Inc. PHONE 231 - 3092 231-1029 993 - 1821 All providers from the factory zone of the city start with 231. You want to get the providers that are in the factory zone of the city. Which of the following is more appropriate? O a. O b. SELECT * FROM PROVIDERS WHERE PHONE LIKE '% 231' O C. O d. SELECT * FROM PROVIDERS WHERE PHONE LIKE $231%' SELECT * FROM PROVIDERS WHERE PHONE LIKE 231 SELECT * FROM PROVIDERS WHERE PHONE LIKE '%231%'arrow_forwardSQL Find the guide last name and guide first name of all guides who can lead a paddling triparrow_forwardIf a subquery is used in the FROM clause of a query, how are the subquery’s results referenced in other clauses of the query?arrow_forward