January 2018
Beginner to intermediate
316 pages
7h 14m
English
First, we need to calculate a column-wise mean vector for each of our classes. One for setosa, one for versicolor, and another for virginica:
# calculate the mean for each class # to do this we will separate the iris dataset into three dataframes # one for each flower, then we will take one's mean columnwise mean_vectors = [] for cl in [0, 1, 2]: class_mean_vector = np.mean(iris_X[iris_y==cl], axis=0) mean_vectors.append(class_mean_vector) print label_dict[cl], class_mean_vector setosa [ 5.006 3.418 1.464 0.244] versicolor [ 5.936 2.77 4.26 1.326] virginica [ 6.588 2.974 5.552 2.026]
Read now
Unlock full access