Write a single python file to perform the following tasks: (a) Get dataset from sklearn.datasets import...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 aklearn.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 onders 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 I: 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_StudentMatriculationNumber.py". It should contain function a A2 MatricNumber that takes in an integer 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 × 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 StudentMatriculationNumber.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) 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 aklearn.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 onders 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 I: 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_StudentMatriculationNumber.py". It should contain function a A2 MatricNumber that takes in an integer 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 × 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 StudentMatriculationNumber.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:
Answer rating: 100% (QA)
To solve this task you can create a Python file named A2A1234567Rpy replace A1234567R with your actu... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Given an interest rate of 8 % , how much should you invest now in order to produce $ 3 , 0 0 0 at the end of the year?
-
If you deposit $1,500 at 7.59% annual interest rate, in how many years will the money in the bank account reach $6,800? (The answer may NOT be a whole number.) Round your answer to TWO decimal places.
-
What functions are there in the mazeAsn4 module: print_maze(maze) Description: This function displays the maze. The accessible cells are labelled G i.e. green, the blocked cells are labelled R i.e....
-
A Styrofoam slab has thickness h and density ps. When a swimmer of mass m is resting on it, the slab floats in fresh water with its top at the same level as the water surface. Find the area of the...
-
At March 31 Streuling Enterprises, a merchandising firm, had an inventory of 38,000 units. Sales, in units, have been budgeted as follows for the next four months: April...................... 60,000...
-
A set of ten jobs must be scheduled at an integrated machining center that performs a number of metal-cutting operations on components for complex assemblies. These jobs and their processing times...
-
The Mann Corporation began operations in 2015.Information relating to the companys purchases of inventory and sales of products for 2015 and 2016 is presented below. Calculate the weighted-average...
-
Byers Company presents the following condensed income statement for 2016 and condensed December 31, 2016, balance sheet: Income Statement Balance Sheet Additional information: 1. The companys common...
-
What are the likely effects on dividend-payoutratios if: (a) Prospectus requirements are tightened, increasing the cost of share issues. (b) Company profitability increases
-
Company A is a global company based in the United States that operates in the financial industry. Company A serves its customers with financial products, such as checking accounts, bank cards, and...
-
Victor Corporation was organized on January 2, year 1, with 100,000 authorized shares of $10 par value common stock. During year 1 Victor had the following capital transactions: January 5?issued...
-
A company's issued share capital consists of $ 2 0 0 , 0 0 0 in 5 0 c ordinary shares issued at a premium of 1 0 c per share. A dividend of 2 0 % is declared. what is the cash payable to shareholders...
-
Recently, Shasta Corporation has decided to play a more-active role in the soda be is aware that the current market price for a can of soda is $2.00. Shasta plans to se soda in its first year and...
-
In the 2nd stage regression used to test the CAPM, researchers reduced the measurement error in betas from the 1ststage regression. What was the source of the measurement error and how did they...
-
how the information management system enhances overall business operations and analysis the role of ICT applications in Operations optimization at PepsiCo
-
Define and apply the following: Scarcity Needs Wants Microeconomics Four factors of production
-
Spahn Corporation has the following information available for the manufacture and sale of its only product for the months of June and July. There was no work in process inventory in either month and...
-
Imagine you are the HR manager at a company, and a female employee came to you upset because she felt a male coworker was creating a hostile work environment by repeatedly asking her out on dates...
-
Teresa is a civil engineer who uses her automobile for business. Teresa drove her automobile a total of 21,732 miles during 2012, of which 95 percent was business mileage. The actual cost of...
-
Professor Patricia (Patty) Pate is retired from the PalmSprings Culinary Arts Academy (PSCAA). She is a single taxpayer and is 68 years old. Patty lives at 98 Colander Street, Henderson, NV 89052....
-
Ann hires a nanny to watch her two children while she works at a local hospital. She pays the 19-year-old nanny $125 per week for 48 weeks during the current year. a. What is the employer's portion...
-
Which of the following accounts has a normal debit balance? a. Common Stock b. Paid-in Capital in Excess of Stated Value c. Preferred Stock d. Treasury Stock
-
Which of the following events decreases a corporation's stockholders' equity? a. A payment of a previously declared cash dividend b. A declaration of a six percent stock dividend c. A 2-for-1 forward...
-
When a company wants to reduce the market price per share of its stock, what action should it take? a. Issue a cash dividend b. Issue a stock dividend c. Do a reverse stock split d. Do a forward...
Study smarter with the SolutionInn App