5. Artificial Neural Networks: Predicting Annual Income
Activity 5.01: Training an MLP for Our Census Income Dataset
Solution:
- Import all the elements required to load and split a dataset, to train an MLP, and to measure accuracy:
import pandas as pd from sklearn.model_selection import train_test_split from sklearn.neural_network import MLPClassifier from sklearn.metrics import accuracy_score
- Using the preprocessed Census Income Dataset, separate the features from the target, creating the variables
X
andY
:data = pd.read_csv("census_income_dataset_preprocessed.csv") X = data.drop("target", axis=1) Y = data["target"]
As explained previously, there are several ways to achieve the separation of
X
andY
, and the main thing to consider is thatX
should contain the features for all instances, whileY
should contain the class label of all instances. - Divide the dataset into training, validation, and testing sets, using a split ratio of 10...