MCPcopy Index your code
hub / github.com/rushter/MLAlgorithms / classification

Function classification

examples/nearest_neighbors.py:34–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32
33
34def classification():
35 X, y = make_classification(
36 n_samples=500,
37 n_features=5,
38 n_informative=5,
39 n_redundant=0,
40 n_repeated=0,
41 n_classes=3,
42 random_state=1111,
43 class_sep=1.5,
44 )
45
46 X_train, X_test, y_train, y_test = train_test_split(
47 X, y, test_size=0.1, random_state=1111
48 )
49
50 clf = knn.KNNClassifier(k=5, distance_func=distance.euclidean)
51
52 clf.fit(X_train, y_train)
53 predictions = clf.predict(X_test)
54 print("classification accuracy", accuracy(y_test, predictions))
55
56
57if __name__ == "__main__":

Callers 1

Calls 3

accuracyFunction · 0.90
fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected