Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I need help with this assignment on machine learning using python programming. Question: Write a single python file to perform the following tasks: (

Hi I need help with this assignment on machine learning using python programming.
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 1mport 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 "fx@m
sklearn.preprocessing 1mport PolynomialFeatures") from orders 1 to 8(adopting
the weight-decay L.2 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 offsetbias atigmentation will be automatically generated by Polynomial Features.
NOTE 2: If the number of rows in the training polynomial matrix is less than of 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 a function A._MatricNumber that takes in an integer "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 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 4.(1%)
y--test : test target numpy array (containing values 0,1 and 2) of length number_of_test_samples. (1%)
Ytx: one-hot encoded training target numpy matrix (containing only values 0 and 1) with dimension
(number_of_training_samples 3).)
Yts : one-hot encoded test target numpy matrix (containing only values 0 and 1) with dimension
(number_of_test_samples 3).(1%)
Ptrain_1ist: 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 x15), etc. )
Ptest_11st : 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%)
,"_11st : 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%)
exxox_txain_axxay: 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%)
The way the code will be run is like this:> N-5w_1ist, error_train_array, error_test_array = grading.A2_A1234567R (N)
The sample python template provided to work on is below, not allowed to comment out any lines.
Please replace "Matrickuber" with your actual natric nuber here and in the filenane
A2. MatricNuber (N) :
Inpat type
in typei int
Return type
:X_train type: nupy,ndarray of size (number_ot_training_saup1es,4)
:Y_trate type: nupy-ndarray of size (number_ot_training_sauples,)
iX_test type: numpy, sdarray of size (number_of_teat_sacples, 4)
:y_test type: nuopy.sdarray of size (nuber_of_test_asiples,)
sYte typet numpy.ndarray of size (number of eraining_samples, 3)
sYts type: numpy,ndarray of size (nuaber_of_test_samples, 3)
ifrain list type: List (nuapy-ndarray]
ifteat Iist type: hist [numpy, ndarkay]
sw_list type: Liot (numpy, ndarray)
serror train a
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Describe the six steps in the strategic management process.

Answered: 1 week ago