Menu
CoddyTech

Recap: Seed Sorter

Part of the Supervised Learning section of Coddy's Machine Learning journey. Lesson 5 of 58.

challenge icon

Challenge

Easy

Remember 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.

  1. Split, a quarter for testing with random_state=0, and print the sizes.
  2. Print the most common training variety: the baseline's answer.
  3. Fit a k-nearest neighbors model on the measurements. Print its accuracy and the baseline, rounded to 3 decimals.
  4. 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: Canadian

Try 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

Practice on your own: Online Python compiler