Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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)
Step by Step Solution
★★★★★
3.44 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
To solve this task you can create a Python file named A2A1234567Rpy replace A1234567R with your actu...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started