Challenge Solution Review

In this lesson, we explain the solution to the last challenge lesson.

Press + to interact
import sklearn.datasets as datasets
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
import sklearn.metrics as metrics
X, y = datasets.make_classification(n_samples=1000,
n_features=30,
random_state=10)
train_x, test_x, train_y, test_y = train_test_split(X,
y,
test_size=0.2,
random_state=42)
nn = MLPClassifier(batch_size=32,
hidden_layer_sizes=(64, 32),
solver="sgd",
shuffle=True,
tol=1e-3,
max_iter=500,
learning_rate_init=0.0001, random_state=13)
nn.fit(train_x, train_y)
pred_y = nn.predict(test_x)
f1 = metrics.f1_score(y_true=test_y, y_pred=pred_y)
print("The F1 score is {}.".format(f1))

Get hands-on with 1200+ tech skills courses.