Skip to content
0

Can you estimate the age of an abalone?

📖 Background

You are working as an intern for an abalone farming operation in Japan. For operational and environmental reasons, it is an important consideration to estimate the age of the abalones when they go to market.

Determining an abalone's age involves counting the number of rings in a cross-section of the shell through a microscope. Since this method is somewhat cumbersome and complex, you are interested in helping the farmers estimate the age of the abalone using its physical characteristics.

💪 Competition challenge

Create a report that covers the following:

  1. How does weight change with age for each of the three sex categories?
  2. Can you estimate an abalone's age using its physical characteristics?
  3. Investigate which variables are better predictors of age for abalones.

✅ Checklist before publishing

  • Rename your workspace to make it descriptive of your work. N.B. you should leave the notebook name as notebook.ipynb.
  • Remove redundant cells like the judging criteria, so the workbook is focused on your story.
  • Check that all the cells run without error.

💾 The data

You have access to the following historical data (source):

Abalone characteristics:
  • "sex" - M, F, and I (infant).
  • "length" - longest shell measurement.
  • "diameter" - perpendicular to the length.
  • "height" - measured with meat in the shell.
  • "whole_wt" - whole abalone weight.
  • "shucked_wt" - the weight of abalone meat.
  • "viscera_wt" - gut-weight.
  • "shell_wt" - the weight of the dried shell.
  • "rings" - number of rings in a shell cross-section.
  • "age" - the age of the abalone: the number of rings + 1.5.

Acknowledgments: Warwick J Nash, Tracy L Sellers, Simon R Talbot, Andrew J Cawthorn, and Wes B Ford (1994) "The Population Biology of Abalone (Haliotis species) in Tasmania. I. Blacklip Abalone (H. rubra) from the North Coast and Islands of Bass Strait", Sea Fisheries Division, Technical Report No. 48 (ISSN 1034-3288).

import pandas as pd
abalone = pd.read_csv('./data/abalone.csv')
abalone
import matplotlib.pyplot as plt
import seaborn as sns

for i in abalone.columns:
    if i != 'sex' and i != 'age' and i != 'rings':
    	sns.lmplot(x=i, y='age', ci = None, col='sex', hue = 'sex', data = abalone)
    plt.show()
import numpy as np
from sklearn.svm import SVC
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.inspection import DecisionBoundaryDisplay
from sklearn.model_selection import GridSearchCV

X = abalone.drop(['sex', 'rings', 'age'], axis=1)
y = round(abalone['age'], 0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.8, random_state = 4)
parameters = {'kernel': ('rbf', 'poly'), 'C': np.arange(11)}
svc = SVC(random_state=4)
clf = GridSearchCV(svc, parameters).fit(X_train, y_train)
score = clf.score(X_test, y_test)
print(clf.best_params_)
print(score)


# Creating a function that fits a linear regression and prints relevant metrics for comparison 
def rbf_svc(X_train):
    svc = SVC(kernel='rbf', C = 10, random_state=4, tol=1e-5).fit(X_train, y_train)
    score = svc.score(X_test, y_test)
    
    return score
    

Fazer um ciclo que faz combinações de duas variáveis para descobrir a combinação que tem os melhores resultados

comb = []
results = []
for col in X_train.columns:
    for c in X_train.columns:
        if col != c and c not in comb[:, 0]:
            X = X_train[col, c]
            results.append(rbf_svc(X))
            comb.append([col, c])
            print(col + ' ' + c + '\n' + str(rbf_svc(X)))

1 hidden cell