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

Function classification

examples/svm.py:16–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15
16def classification():
17 # Generate a random binary classification problem.
18 X, y = make_classification(
19 n_samples=1200,
20 n_features=10,
21 n_informative=5,
22 random_state=1111,
23 n_classes=2,
24 class_sep=1.75,
25 )
26 # Convert y to {-1, 1}
27 y = (y * 2) - 1
28 X_train, X_test, y_train, y_test = train_test_split(
29 X, y, test_size=0.2, random_state=1111
30 )
31
32 for kernel in [RBF(gamma=0.1), Linear()]:
33 model = SVM(max_iter=500, kernel=kernel, C=0.6)
34 model.fit(X_train, y_train)
35 predictions = model.predict(X_test)
36 print(
37 "Classification accuracy (%s): %s" % (kernel, accuracy(y_test, predictions))
38 )
39
40
41if __name__ == "__main__":

Callers 1

svm.pyFile · 0.70

Calls 6

fitMethod · 0.95
RBFClass · 0.90
LinearClass · 0.90
SVMClass · 0.90
accuracyFunction · 0.90
predictMethod · 0.45

Tested by

no test coverage detected