Answered step by step
Verified Expert Solution
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 loadiris". This dataset has features.
Split the dataset into two sets: of samples for training, and of samples for testing.
NOTE : Please use "from sklearn.modelselection mport traintestsplit"
with "randomstateN and "testsize
NOTE : The offsetbias column is not needed here for augmenting the input features.
b Generate the target output using onehot 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 @
sklearn.preprocessing mport PolynomialFeatures" from orders to adopting
the weightdecay L regularization with regularization factor for classification based on the
onehot encoding and compute the number of training and test samples that are classified correctly.
NOTE : The offsetbias atigmentation will be automatically generated by Polynomial Features.
NOTE : 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 If not, use the primal form Lecture
Instructions: please submit a single python file with filename AStudentMatriculationNumber.py It should
contain a function AMatricNumber that takes in an integer
randomstate as input and returns the following outputs in the following order:
Xtrain : training numpy feature matrix with dimensions numberoftrainingsamples
train: training target numpy array containing values and of length
numberoftrainingsamples.
Xtest : test numpy feature matrix with dimensions numberoftestsamples
test : test target numpy array containing values and of length numberoftestsamples.
Ytx: onehot encoded training target numpy matrix containing only values and with dimension
numberoftrainingsamples
Yts : onehot encoded test target numpy matrix containing only values and with dimension
numberoftestsamples
Ptrainist: list of training polynomial matrices for orders to Ptrainlist should be polynomial
matrices for order size numberoftrainingsamples x Ptrainlist should be polynomial matrices for
order size numberoftrainingsamples etc.
Ptestst : list of test polynomial matrices for orders to Ptestlist should be polynomial matrices
for order Ptestlist should be polynomial matrices for order etc.
st : list of estimated regression coefficients for orders to wlist should be estimated regression
coefficients for order wlist should be estimated regression coefficients for order etc.
exxoxtxainaxxay: numpy array of training error counts error count number of samples classified
incorrectly for orders to errortrainarray is error count for polynomial order errortrainarray is
error count for polynomial order etc.
errortestarray: numpy array of test error counts error count number of samples classified
incorrectly for orders to errortestarray is error count for polynomial order errortestarray is
error count for polynomial order etc.
The way the code will be run is like this: Nwist, errortrainarray, errortestarray grading.AAR 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
A MatricNuber N :
Inpat type
in typei int
Return type
:Xtrain type: nupy,ndarray of size numberottrainingsaupes
:Ytrate type: nupyndarray of size numberottrainingsauples,
iXtest type: numpy, sdarray of size numberofteatsacples,
:ytest type: nuopy.sdarray of size nuberoftestasiples,
sYte typet numpy.ndarray of size number of erainingsamples,
sYts type: numpy,ndarray of size nuaberoftestsamples,
ifrain list type: List nuapyndarray
ifteat Iist type: hist numpy ndarkay
swlist type: Liot numpy ndarray
serror train a
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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