Question: 4 . We use Machine Learning to derive insights from the data ( descriptive analysis and modeling ) AND to infer or predict things about
We use Machine Learning to derive insights from the data descriptive analysis and
modeling AND to infer or predict things about new data predictive modeling You will
now generate multiple predictive models, compare their performance, and use your
models to predict which type of iris is most likely for new observations.
a First, we need to split out data into a subset used for training our models and a
subset use for validating comparing our models. The method for this is
traintestsplit. A common syntax for doing a random split of our
independent variables X see above and dependent variable Y class in this
dataset is:
Xtrain, Xvalid, Ytrain, Yvalid traintestsplitX y testsize randomstate
b Once you have split your dataset into train and validation sets, you will need to build
a model that will predict the species based on our four input features. First build a
Decision Tree Classifier in your notebook train than classifier, use the model to
predict the iris type for each of the entries in the validation dataset, and compute
the accuracy of the prediction:
# Create a decision tree classifier
clf DecisionTreeClassifier
# Train the model on the training data
clffitXtrain, ytrain
# Make predictions on the test data
ypred clfpredictXvalid
# Calculate accuracy
accuracy accuracyscoreyvalid, ypred
printfAccuracy: accuracy:f
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
