As a part of an application for iris enthusiasts, implement the train_and_predict function which should be able to classify three types of irises based on four features.

The train_and_predict function accepts three parameters:

  • train_input_features - a two-dimensional NumPy array where each element is an array that contains: sepal length, sepal width, petal length, and petal width.
  • train_outputs - a one-dimensional NumPy array where each element is a number representing the species of iris which is described in the same row of train_input_features. 0 represents Iris setosa, 1 represents Iris versicolor, and 2 represents Iris virginica.
  • prediction_features - two-dimensional NumPy array where each element is an array that contains: sepal length, sepal width, petal length, and petal width.

The function should train a classifier using train_input_features as input data and train_outputs as the expected result. After that, the function should use the trained classifier to predict labels for prediction_features and return them as an iterable (like list or numpy.ndarray). The nth position in the result should be the classification of the nth row of the prediction_features parameter.

Python 3.7.4, Pandas 0.25.1, Numpy 1.16.5, Scipy 1.3.1, Scikit-learn 0.21.3  
 

  •   Accuracy on the example case is higher or equal to 80%: Wrong answer
  •   Accuracy is higher or equal to 75% on data with noise: Wrong answer
  •   Accuracy is higher or equal to 85% on data with noise: Wrong answer

Tags
Data Science Classification Machine learning Public New
Easy

20min

Score Distribution
Not enough data for chart
Would you like to see our other questions?

We have 500+ premium hand-crafted questions for 30+ job skills and 10+ coding language. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library

Private Concierge

Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.


Would you like to see our tests? The following tests contain Data Science related questions:
On the TestDome Blog

Screening Applicants: The Good, the Bad and the Ugly

Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...