Question: 4 . We use Machine Learning to derive insights from the data ( descriptive analysis and modeling ) AND to infer or predict things about

4. 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
train_test_split. A common syntax for doing a random 80%/20% split of our
independent variables X (see above) and dependent variable Y (class in this
dataset) is:
X_train, X_valid, Y_train, Y_valid = train_test_split(X, y, test_size=0.20, random_state=1)
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
clf.fit(X_train, y_train)
# Make predictions on the test data
y_pred = clf.predict(X_valid)
# Calculate accuracy
accuracy = accuracy_score(y_valid, y_pred)
printf(Accuracy: {accuracy*100:.2f}%

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!