|
17 | 17 | parser.add_argument('--weights', type=str, default='uniform',
|
18 | 18 | help='Weight function used in prediction')
|
19 | 19 | parser.add_argument('--method', type=str, default='brute',
|
| 20 | + choices=('brute', 'kd_tree', 'ball_tree', 'auto'), |
20 | 21 | help='Algorithm used to compute the nearest neighbors')
|
21 | 22 | parser.add_argument('--metric', type=str, default='euclidean',
|
22 | 23 | help='Distance metric to use')
|
|
32 | 33 | algorithm=params.method,
|
33 | 34 | metric=params.metric)
|
34 | 35 |
|
35 |
| -knn_clsf.fit(X_train, y_train) |
36 |
| -# Time predict |
37 |
| -time, yp = measure_function_time(knn_clsf.predict, X_test, params=params) |
| 36 | +# Measure time and accuracy on fitting |
| 37 | +train_time, _ = measure_function_time(knn_clsf.fit, X_train, y_train, |
| 38 | + params=params) |
| 39 | +y_pred = knn_clsf.predict(X_train) |
| 40 | +train_acc = 100 * accuracy_score(y_pred, y_train) |
38 | 41 |
|
39 |
| -acc = 100 * accuracy_score(yp, y_test) |
| 42 | +# Measure time and accuracy on prediction |
| 43 | +predict_time, yp = measure_function_time(knn_clsf.predict, X_test, params=params) |
| 44 | +test_acc = 100 * accuracy_score(yp, y_test) |
40 | 45 |
|
41 | 46 | columns = ('batch', 'arch', 'prefix', 'function', 'threads', 'dtype', 'size',
|
42 | 47 | 'n_neighbors', 'n_classes', 'time')
|
43 | 48 |
|
44 | 49 | print_output(library='sklearn', algorithm='knn_classification',
|
45 |
| - stages=['prediction'], columns=columns, params=params, |
46 |
| - functions=['knn_clsf.predict'], times=[time], accuracies=[acc], |
47 |
| - accuracy_type='accuracy[%]', data=[X_test], alg_instance=knn_clsf) |
| 50 | + stages=['training', 'prediction'], columns=columns, params=params, |
| 51 | + functions=['knn_clsf.fit', 'knn_clsf.predict'], |
| 52 | + times=[train_time, predict_time], |
| 53 | + accuracies=[train_acc, test_acc], accuracy_type='accuracy[%]', |
| 54 | + data=[X_train, X_test], alg_instance=knn_clsf) |
0 commit comments