Sorting fruit: the challenge that introduces machine learning
The Data Science umbrella · click a field
Why this matters
Writing a rule for every fruit by hand breaks the moment a new fruit, a bruised apple or a green banana arrives. A system that learns from data can fix its own mistakes. The same idea that sorts fruit also filters spam, recommends films and steers self-driving cars.
Walk one fruit through Data Mining, Machine Learning and AI
The ideas that make it work: features, labels, patterns and experience
More features, fewer mix-ups
With or without the answer column
What data mining discovers
Experience ties it together: the more labelled examples a model sees, the better its guesses become. Section 04 lets you add experience one example at a time and watch the score climb.
The defining rule: learn from data, not from explicit programs
ML: data + answers → rules (model)
Mitchell: learns ⇔ P on T improves with E
The definition. Machine learning learns from data and improves its performance without being explicitly programmed. Here: task T = name the fruit, experience E = labelled examples, performance P = share of test fruits named correctly.
Classify, regress or cluster: decide it by hand and by eye
Worked example by hand: name a new fruit from three labelled ones
Two features, each scored 0 to 10. To compare the new fruit with an example, take the gap on colour and the gap on size (always positive) and add them. The smallest total wins, and the new fruit copies that example's label.
Where the rewards add up: State, Action, Reward and the cumulative reward
The S, A, R, S' of that moment and the running total appear here.
Rewards vs penalties
Cumulative reward
Worked example: the 6 steps of learning to ride a bicycle
These are the 5 components (S, A, R, S', π) plus the learning process that ties them together. The environment is the bike, the road and gravity.
The family: supervised, unsupervised, reinforcement and transfer learning
Pick a row above.
Transfer learning: reuse, then fine-tune
The cost and the limits: the curse of dimensionality
Increased sparsity
The data is spread so thin that most combinations of feature values have no example at all.
Higher computational cost
More features mean more numbers to store and compare for every example.
Overfitting risk
With many features and few examples, the model memorises noise instead of the real pattern.
Distance-based issues
In k-NN or clustering, all points appear equally distant, so “nearest” loses its meaning.
Apply it yourself: choose the right learning type and set up Anaconda
The checklist
Try it: pick a type for each scenario
Tutorial preparation: install Anaconda
# your first classifier: 4 fruits, 2 features (colour, size) from sklearn.neighbors import KNeighborsClassifier X = [[1, 4], [8, 9], [4, 5], [6, 6]] # features y = ["apple", "banana", "orange", "mango"] # labels model = KNeighborsClassifier(n_neighbors=1) model.fit(X, y) # learn from labelled data print(model.predict([[2, 4]])) # → ['apple']
The same nearest-example idea you did by hand in section 05, in six lines of scikit-learn.