Question: Write a single python file to perform the following tasks: (a) Get dataset from sklearn.datasets...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question: Write a single python file to perform the following tasks: (a) Get dataset "from sklearn.datasets import load_iris". This dataset has 4 features. Split the dataset into two sets: 30% of samples for training, and 70% of samples for testing. NOTE 1: Please use "from sklearn.model_selection import train_test_split" with "random_state=N" and "test_size=0.7". NOTE 2: The offset/bias column is not needed here for augmenting the input features. (b) Generate the target output using one-hot encoding for both the training set and the test set. (c) Using the same training and test sets generated above, perform a polynomial regression (utilizing "from sklearn.preprocessing import Polynomial Features") from orders 1 to 8 (adopting the weight-decay L2 regularization with regularization factor -0.0001) for classification (based on the one-hot encoding) and compute the number of training and test samples that are classified correctly. NOTE 1: The offset/bias augmentation will be automatically generated by Polynomial Features. NOTE 2: If the number of rows in the training polynomial matrix is less than or equal to the number of columns, then use the dual form of ridge regression (Lecture 6). If not, use the primal form (Lecture 6). Instructions: please submit a single python file with filename "A2_StudentMatriculation Number.py". It should contain a that takes in an integer function A2_MatricNumber "N" random_state as input and returns the following outputs in the following order: X_train: training numpy feature matrix with dimensions (number_of_training_samples x 4). (1%) y_train: training target numpy array (containing values 0, 1 and 2) of length number_of_training_samples. (1%) x_test: test numpy feature matrix with dimensions (number_of_test_samples x 4). (1%) y_test: test target numpy array (containing values 0, 1 and 2) of length number_of_test_samples. (1%) Ytr: one-hot encoded training target numpy matrix (containing only values 0 and 1) with dimension (number_of_training samples x 3). (1%) Yts: one-hot encoded test target numpy matrix (containing only values 0 and 1) with dimension (number_of_test_samples x 3). (1%) . . Ptrain_list: list of training polynomial matrices for orders 1 to 8. Ptrain_list[0] should be polynomial matrices for order 1 (size number_of_training_samples x 5), Ptrain_list[1] should be polynomial matrices for order 2 (size number_of_training samples x 15), etc. (1.5%) Ptest_list: list of test polynomial matrices for orders 1 to 8. Ptest_list[0] should be polynomial matrices for order 1, Ptest_list[1] should be polynomial matrices for order 2, etc. (1.5%) w_list: list of estimated regression coefficients for orders 1 to 8. w_list[0] should be estimated regression coefficients for order 1, w_list[1] should be estimated regression coefficients for order 2, etc. (2%) error_train_array: numpy array of training error counts (error count = number of samples classified incorrectly) for orders 1 to 8. error_train_array[0] is error count for polynomial order 1, error_train_array[1] is error count for polynomial order 2. etc. (2%) error_test_array: numpy array of test error counts (error count number of samples classified incorrectly) for orders 1 to 8. error_test_array[0] is error count for polynomial order 1, error_test_array[1] is error count for polynomial order 2, etc. (2%) Please use the python template provided to you. Do not comment out any lines. Remember to rename both "A2_StudentMatriculation Number.py" and "A2_MatricNumber" using your student matriculation number. For example, if your matriculation ID is A1234567R, then you should submit "A2_A1234567R.py" that contains the function "A2_A1234567R". Please do NOT zip/compress your file. Please test your code at least once. Because of the large class size, points will be deducted if instructions are not followed. The way we would run your code might be something like this: >> import A2_A1234567R as grading >> N = 5 >> X_train, y_train, X_test, y_test, Ytr, Yts, Ptrain_list, Ptest_list, w list, error_train_array, error_test_array = grading.A2_A1234567R (N) Question: Write a single python file to perform the following tasks: (a) Get dataset "from sklearn.datasets import load_iris". This dataset has 4 features. Split the dataset into two sets: 30% of samples for training, and 70% of samples for testing. NOTE 1: Please use "from sklearn.model_selection import train_test_split" with "random_state=N" and "test_size=0.7". NOTE 2: The offset/bias column is not needed here for augmenting the input features. (b) Generate the target output using one-hot encoding for both the training set and the test set. (c) Using the same training and test sets generated above, perform a polynomial regression (utilizing "from sklearn.preprocessing import Polynomial Features") from orders 1 to 8 (adopting the weight-decay L2 regularization with regularization factor -0.0001) for classification (based on the one-hot encoding) and compute the number of training and test samples that are classified correctly. NOTE 1: The offset/bias augmentation will be automatically generated by Polynomial Features. NOTE 2: If the number of rows in the training polynomial matrix is less than or equal to the number of columns, then use the dual form of ridge regression (Lecture 6). If not, use the primal form (Lecture 6). Instructions: please submit a single python file with filename "A2_StudentMatriculation Number.py". It should contain a that takes in an integer function A2_MatricNumber "N" random_state as input and returns the following outputs in the following order: X_train: training numpy feature matrix with dimensions (number_of_training_samples x 4). (1%) y_train: training target numpy array (containing values 0, 1 and 2) of length number_of_training_samples. (1%) x_test: test numpy feature matrix with dimensions (number_of_test_samples x 4). (1%) y_test: test target numpy array (containing values 0, 1 and 2) of length number_of_test_samples. (1%) Ytr: one-hot encoded training target numpy matrix (containing only values 0 and 1) with dimension (number_of_training samples x 3). (1%) Yts: one-hot encoded test target numpy matrix (containing only values 0 and 1) with dimension (number_of_test_samples x 3). (1%) . . Ptrain_list: list of training polynomial matrices for orders 1 to 8. Ptrain_list[0] should be polynomial matrices for order 1 (size number_of_training_samples x 5), Ptrain_list[1] should be polynomial matrices for order 2 (size number_of_training samples x 15), etc. (1.5%) Ptest_list: list of test polynomial matrices for orders 1 to 8. Ptest_list[0] should be polynomial matrices for order 1, Ptest_list[1] should be polynomial matrices for order 2, etc. (1.5%) w_list: list of estimated regression coefficients for orders 1 to 8. w_list[0] should be estimated regression coefficients for order 1, w_list[1] should be estimated regression coefficients for order 2, etc. (2%) error_train_array: numpy array of training error counts (error count = number of samples classified incorrectly) for orders 1 to 8. error_train_array[0] is error count for polynomial order 1, error_train_array[1] is error count for polynomial order 2. etc. (2%) error_test_array: numpy array of test error counts (error count number of samples classified incorrectly) for orders 1 to 8. error_test_array[0] is error count for polynomial order 1, error_test_array[1] is error count for polynomial order 2, etc. (2%) Please use the python template provided to you. Do not comment out any lines. Remember to rename both "A2_StudentMatriculation Number.py" and "A2_MatricNumber" using your student matriculation number. For example, if your matriculation ID is A1234567R, then you should submit "A2_A1234567R.py" that contains the function "A2_A1234567R". Please do NOT zip/compress your file. Please test your code at least once. Because of the large class size, points will be deducted if instructions are not followed. The way we would run your code might be something like this: >> import A2_A1234567R as grading >> N = 5 >> X_train, y_train, X_test, y_test, Ytr, Yts, Ptrain_list, Ptest_list, w list, error_train_array, error_test_array = grading.A2_A1234567R (N)
Expert Answer:
Related Book For
Quantitative Analysis for Management
ISBN: 978-0133507331
12th edition
Authors: Barry Render, Ralph M. Stair, Michael E. Hanna, Trevor S. Ha
Posted Date:
Students also viewed these programming questions
-
- A large, open bucket of water sits on a table. The height of the water level in the bucket is 4 m above the surface of the table. A small hole is made in the bucket at a distance of 10 cm above the...
-
Assume increase in government spending. Would the effect on AD be larger if the Fed held MS constant in response or if the Fed were committed to maintaining a fixed interest rate? Use chapter...
-
With pipelined parallelism, it is often a good idea to perform several operations in a pipeline on a single processor, even when many processors are available. a. Explain why. b. Would the arguments...
-
Explain how depreciation generates actual cash flows for a firm.
-
In the month of March, Trendy Spa services 570 clients at an average price of $120. During the month, fixed costs were $21,000 and variable costs were 65% of sales. Instructions (a) Determine the...
-
17. A concave mirror produces a real image 10mm tall, of an object 2.5mm tall placed at 5cm from the mirror. Calculate focal length of the mirror and the position of the image. 18. An object is...
-
Mercier Manufacturing produces a plastic part in three sequential departments: Extruding, Fabricating, and Packaging. Mercier uses the weighted-average process costing method to account for costs of...
-
The objective of this exercise is to develop skills to plan in a practical way, according to the needs of the users, the departments and the effectiveness of the organization.I'm Juan del Pueblo and...
-
Depending on your age and work history, you may have already received this report from the SSA. How well do you understand how your own future retirement benefits will work? Consider other examples...
-
Some FIR filters present a rational transfer function: (a) Show that the transfer function \[H(z)=\frac{\left(r^{-1} z ight)^{-(M+1)}-1}{r e^{\mathrm{j} 2 \pi /(M+1)} z^{-1}-1}\] corresponds to an...
-
Calculate DVA in Example 24.6. Assume that default can happen in the middle of each month. The default probability of the bank is 0.001 per month for the two years and the recovery rate in the event...
-
Calculate the price of a six-month European put option on the spot value of an index. The six-month forward price of the index is 1,400, the strike price is 1,450, the risk-free rate is 5%, and the...
-
Xanadu Mining is considering three mutually exclusive alternatives, as shown in the table below. MARR is 10 percent/year. a. What is the present worth of each alternative? b. Which alternative should...
-
Reading comprehension test scores of elementary school children randomly assigned to one of two teaching methods have the following summary statistics: # of Children Mean Standard Deviation Method 1...
-
A consumer magazine is evaluating five brands of trash compactors for their effectiveness in reducing the volume of typical household products that are discarded. In the experiment, each block...
-
Blair H. Dodds, III, runs a medium-to-large-sized home eBay business dealing in vintage photographs. The annual demand for his photos is approximately 50,000. The annual overhead cost (excluding the...
-
For the post office in Problem 12-17, a second drive-through window is being considered. A single line would be formed and as a car reached the front of the line it would go to the next available...
-
The German towns around the Black Forest are rep-resented by nodes in the network below. The dis-tances between towns is shown in kilometers. Find the shortest route from city 1 to city 16. If...
-
What is the difference between efficiency and effectiveness? Explain why both are valuable to managers.
-
Is there one best style of management? Discuss in terms of managerial functions, roles.
-
How are technology, social media, and other technological advances making a managers job easier? More complex?
Study smarter with the SolutionInn App