Non-linear function approximator for either classification or regression
Pros
Cons
from sklearn.datasets import load_digits
digits = load_digits()
X = digits.data
y = digits.target
from sklearn.model_selection import train_test_split
train_X, test_X, train_Y, test_Y = train_test_split(X, y, test_size=0.2, random_state=42, stratify = y)
from sklearn.neural_network import MLPClassifier
model = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1)
model.max_iter = 10000
model.fit(train_X, train_Y)
y_pred = model.predict(test_X)
from sklearn.metrics import confusion_matrix
confusion_matrix(test_Y, y_pred)
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=1000, n_features=10, n_targets=1, random_state=1)
from sklearn.model_selection import train_test_split
train_X, test_X, train_Y, test_Y = train_test_split(X, y, test_size=0.2, random_state=42)
from sklearn.neural_network import MLPRegressor
regr = MLPRegressor(random_state=1, max_iter=10000)
regr.fit(train_X, train_Y)
y_pred = regr.predict(test_X)
from sklearn.metrics import mean_squared_error
MSE = mean_squared_error(test_Y, y_pred)
import numpy as np
RMSE = np.sqrt(MSE)
RMSE