The Data Science
 Workshop by Anthony So Thomas V. Joseph Robert Thas John 
Andrew Worsley and Dr. Samuel Asare

The Data Science
 Workshop by Anthony So Thomas V. Joseph Robert Thas John 
Andrew Worsley and Dr. Samuel Asare

Author:Anthony So, Thomas V. Joseph, Robert Thas John,
Andrew Worsley, and Dr. Samuel Asare
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2020-01-28T00:00:00+00:00


# and every possible weight_function in the grid

for weight_function in grid['weight_function']:

# initialize the knn estimator

knn = neighbors.KNeighborsClassifier(n_neighbors=k, weights=weight_function)

# conduct a 10-fold cross-validation

cv = model_selection.cross_val_score(knn, X, y, cv=10, scoring='precision')

# calculate the average precision value over all folds

cv_mean = round(cv.mean(), 3)

# report the result

print('With k = {} and weight function = {}, mean precision = {}'.format(k, weight_function, cv_mean))

The output will be as follows:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.