0% found this document useful (0 votes)
2 views1 page

Assignment 3

The document outlines a Python script that uploads and processes an abalone dataset using Google Colab. It includes data loading, preprocessing, and the application of a linear regression model to predict the number of rings on abalones, with a resulting mean absolute error of approximately 1.59. The script also demonstrates the use of one-hot encoding for the 'Sex' column and splits the data into training and testing sets.

Uploaded by

vaibhavi.darda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Assignment 3

The document outlines a Python script that uploads and processes an abalone dataset using Google Colab. It includes data loading, preprocessing, and the application of a linear regression model to predict the number of rings on abalones, with a resulting mean absolute error of approximately 1.59. The script also demonstrates the use of one-hot encoding for the 'Sex' column and splits the data into training and testing sets.

Uploaded by

vaibhavi.darda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

4/14/25, 9:57 AM assignment3.

ipynb - Colab

from google.colab import files


uploaded = files.upload()

Choose Files abalone.data


abalone.data(n/a) - 191873 bytes, last modified: 4/14/2025 - 100% done
Saving abalone.data to abalone.data

import pandas as pd
column_names = ['Sex', 'Length', 'Diameter', 'Height', 'Whole weight',
'Shucked weight', 'Viscera weight', 'Shell weight', 'Rings']

abalone_data = pd.read_csv('abalone.data', names=column_names)

abalone_df.head()

Length Diameter Height Whole_weight Shucked_weight Viscera_weight Shell_weight Rings Sex_I Sex_M

0 0.455 0.365 0.095 0.5140 0.2245 0.1010 0.150 15 False True

1 0.350 0.265 0.090 0.2255 0.0995 0.0485 0.070 7 False True

2 0.530 0.420 0.135 0.6770 0.2565 0.1415 0.210 9 False False

3 0.440 0.365 0.125 0.5160 0.2155 0.1140 0.155 10 False True

4 0.330 0.255 0.080 0.2050 0.0895 0.0395 0.055 7 True False

Next steps: Generate code with abalone_df toggle_off View recommended plots New interactive sheet

abalone_data = pd.get_dummies(abalone_data, columns=['Sex'], drop_first=True)

X = abalone_data.drop('Rings', axis=1)
y = abalone_data['Rings']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error

model = LinearRegression()
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

mae = mean_absolute_error(y_test, y_pred)

print("Mean Absolute Error:", mae)

Mean Absolute Error: 1.5931067816608353

https://colab.research.google.com/drive/1nh7hMv1ZEkFQq5zUPF3QDxF2JT-o-i3K#scrollTo=GMVt6fEUcp79&printMode=true 1/1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy