import numpy as np from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn import metrics def train_and_predict(train_input_features, train_outputs, prediction_features): """ :param train_input_features: (numpy.array) A two-dimensional NumPy array where each element is an array that contains: sepal length, sepal width, petal length, and petal width :param train_outputs: (numpy.array) 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. :param prediction_features: (numpy.array) A two-dimensional NumPy array where each element is an array that contains: sepal length, sepal width, petal length, and petal width :returns: (list) The function should return an iterable (like list or numpy.ndarray) of the predicted iris species, one for each item in prediction_features """ pass iris = datasets.load_iris() X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.3, random_state=0) y_pred = train_and_predict(X_train, y_train, X_test) if y_pred is not None: print(metrics.accuracy_score(y_test, y_pred))
Read Evidence-Based Hiring
© TestDome, 2022.