Neural Network for Classification
Goal¶
This post aims to introduce (shallow) neural network for classification using scikit-learn
.
Reference
Libraries¶
In [2]:
import pandas as pd
import numpy as np
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import cross_val_score
import matplotlib.pyplot as plt
%matplotlib inline
Load Breast Cancer dataset¶
In [5]:
breast_cancer = load_breast_cancer()
df_breast_cancer = pd.DataFrame(breast_cancer['data'], columns=breast_cancer['feature_names'])
df_breast_cancer['target'] = breast_cancer['target']
df_breast_cancer.head()
Out[5]:
Create Neural Network¶
In [18]:
clf = MLPClassifier(solver='lbfgs', alpha=1e-5,
hidden_layer_sizes=(10,3,3), random_state=1)
In [19]:
cv_score = cross_val_score(clf,
X=df_breast_cancer.iloc[:, :-1],
y=df_breast_cancer['target'],
cv=5)
plt.plot(cv_score);