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

Function classification

examples/nnet_mlp.py:23–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21
22
23def classification():
24 # Generate a random binary classification problem.
25 X, y = make_classification(
26 n_samples=1000,
27 n_features=100,
28 n_informative=75,
29 random_state=1111,
30 n_classes=2,
31 class_sep=2.5,
32 )
33 y = one_hot(y)
34 X_train, X_test, y_train, y_test = train_test_split(
35 X, y, test_size=0.15, random_state=1111
36 )
37
38 model = NeuralNet(
39 layers=[
40 Dense(256, Parameters(init="uniform", regularizers={"W": L2(0.05)})),
41 Activation("relu"),
42 Dropout(0.5),
43 Dense(128, Parameters(init="normal", constraints={"W": MaxNorm()})),
44 Activation("relu"),
45 Dense(2),
46 Activation("softmax"),
47 ],
48 loss="categorical_crossentropy",
49 optimizer=Adadelta(),
50 metric="accuracy",
51 batch_size=64,
52 max_epochs=25,
53 )
54 model.fit(X_train, y_train)
55 predictions = model.predict(X_test)
56 print("classification accuracy", roc_auc_score(y_test[:, 0], predictions[:, 0]))
57
58
59def regression():

Callers 1

nnet_mlp.pyFile · 0.70

Calls 11

fitMethod · 0.95
one_hotFunction · 0.90
NeuralNetClass · 0.90
DenseClass · 0.90
ParametersClass · 0.90
L2Class · 0.90
ActivationClass · 0.90
DropoutClass · 0.90
MaxNormClass · 0.90
AdadeltaClass · 0.90
predictMethod · 0.45

Tested by

no test coverage detected