The document outlines a Python script for predicting fish weight using linear regression. It includes data preprocessing steps, such as dropping the species column and handling missing values, followed by splitting the dataset into training and testing sets. The model is trained, predictions are made, and the performance is evaluated using the R^2 score, with a visualization of the results.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
Ass1_SetB1
The document outlines a Python script for predicting fish weight using linear regression. It includes data preprocessing steps, such as dropping the species column and handling missing values, followed by splitting the dataset into training and testing sets. The model is trained, predictions are made, and the performance is evaluated using the R^2 score, with a visualization of the results.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
# Import necessary libraries
import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import r2_score
# Load the dataset
df = pd.read_csv('Fish.csv')
# Preprocess the data
df = df.drop(['Species'], axis=1) # Drop the species column as it's categorical df = df.dropna() # Drop any rows with missing values
# Split the dataset into training and testing sets
X = df.drop(['Weight'], axis=1) # Features y = df['Weight'] # Target variable X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,random_state=0)