The wine dataset contains 178 Italian wine-cultivar samples. Each row has a cultivar label from 1 to 3 and 13 chemical-analysis parameters, making it a multiclass classification dataset. section 7.6
A neural-network experiment uses the dataset as follows:
- Parse the CSV label separately from its 13 numeric parameters and encode cultivars as three-element classifications. section 7.6
- Configure a network with 13 input neurons and three output neurons; one tested configuration uses seven hidden neurons and a 0.9 learning rate. section 7.6
- Train on the first 150 shuffled samples for five passes, then validate on the remaining 28. section 7.6
Classification result
The network maps the largest output value to cultivar 1, 2, or 3 and reports 27 correct classifications out of 28, or 96.4285714285714%. section 7.6
/// assumes all rows are of equal length
/// and feature scale each column to be in the range 0–1
func normalizeByFeatureScaling(dataset: inout [[Double]]) {
for colNum in 0..<dataset[0].count {
let column = dataset.map { $0[colNum] }
let maximum = column.max()!
let minimum = column.min()!
for rowNum in 0..<dataset.count {
dataset[rowNum][colNum] = (dataset[rowNum][colNum]
- minimum) / (maximum - minimum)
}
}
}
Normalize each feature column to the range 0–1 before using the numeric parameters. section 7.6
