Recap: Seed Sorter
Part of the Supervised Learning section of Coddy's Machine Learning journey. Lesson 5 of 58.
Challenge
EasyRemember the seeds that opened this chapter? Now build their sorter. seeds.csv holds 180 wheat seeds: four measurements, named in features, and the variety. The starter reads a new seed into the one-row table new_seed.
- Split, a quarter for testing with
random_state=0, and print the sizes. - Print the most common training variety: the baseline's answer.
- Fit a k-nearest neighbors model on the measurements. Print its accuracy and the baseline, rounded to 3 decimals.
- Print the new seed's variety.
For another farm's seeds:
Train: 120 seeds, test: 40
Most common in training: Rosa
Accuracy: 0.925 (baseline 0.4)
New seed: CanadianTry it yourself
import pandas as pd
# 180 wheat seeds: four measurements and the variety
seeds = pd.read_csv("seeds.csv")
features = ["area_mm2", "length_mm", "width_mm", "groove_mm"]
# A new seed from the lab, as a one-row table
new_seed = pd.DataFrame({
"area_mm2": [float(input())],
"length_mm": [float(input())],
"width_mm": [float(input())],
"groove_mm": [float(input())],
})
# Write your code below
All lessons in Supervised Learning
1Your First Model
Learning from ExamplesTrain and Test SetsFit and PredictScoring a ModelRecap: Seed Sorter2Nearest Neighbors
How k-NN DecidesChoosing kDecision BoundariesScaling for NeighborsRecap: Wine Neighbors5Measuring Classifiers
The Confusion MatrixPrecision and RecallThe F1 ScoreImbalanced ClassesROC CurvesRecap: Screening Test11Project: Penguin Species
Meet the PenguinsPrepare the DataChoose a ModelTune the WinnerShip the ModelPractice on your own: Online Python compiler