<jupyter_start><jupyter_text>Fish Weight PredictionThis dataset is a record of 7 common different fish species in fish market sales. With this dataset, a predictive model can be performed using machine friendly data and estimate the weight of fish can be predicted.This dataset is from [Kaggle](https://www.kaggle.com/aungpyaeap/fish-market/version/2) Feature Columns1. Species  - Species of the fish2. Length 1 - Vertical Length in cm3. Length 2 - Diagnol length in cm4. Length 3 - Cross Length in cm5. Height   - height in cm6. Width    - width in cm Dependant Column1. Weight = Weight of fish in gram  Import Libraries<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Explore the data<jupyter_code>df = pd.read_csv('./Fish.csv')
df.head()
df.describe()
df.info()
df.isna().sum()
df['Species'].value_counts()
df['Species'].value_counts().plot.bar()
corr = df.corr()
corr
plt.figure(figsize=(11, 8))
sns.heatmap(corr, cmap="Greens",annot=True)
plt.show()<jupyter_output><empty_output><jupyter_text>It seems Weight is correlated with all the numerical columns. the minimum correlation is 0.72 which is not bad as well.  Non - Normalized Box Plot<jupyter_code>sns.boxplot(x='Species', y='Weight', data=df);<jupyter_output><empty_output><jupyter_text>Split Feature Column (X) & Dependant Variable (y)<jupyter_code>X = df.drop('Weight', axis=1)
y = df['Weight']

X.shape, y.shape
type(X), type(y)<jupyter_output><empty_output><jupyter_text>Encode the categorical data & Scale Numeric Columns<jupyter_code>from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler

ct = ColumnTransformer(transformers=
                       [('encoder', OneHotEncoder(), [0])],
                        remainder="passthrough")

transformed_X = ct.fit_transform( X, y)
transformed_X[0]
transformed_X<jupyter_output><empty_output><jupyter_text>Split data into train and test split<jupyter_code>from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(transformed_X, y, test_size=0.2, random_state=42)
X_train.shape, X_test.shape, y_train.shape, y_test.shape<jupyter_output><empty_output><jupyter_text>Train the model with LinearRegressor<jupyter_code>from sklearn.linear_model import LinearRegression

regressor = LinearRegression()
regressor.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Predict the result<jupyter_code>y_pred = regressor.predict(X_test)
y_pred[:10]
np.array(y_test)<jupyter_output><empty_output><jupyter_text>Check metrics (r2 score) for LinearRegression<jupyter_code>from sklearn.metrics import r2_score
print('R2 Score', r2_score(y_test, y_pred))<jupyter_output><empty_output><jupyter_text>Train Model with RandomForestRegressor<jupyter_code>from sklearn.ensemble import RandomForestRegressor
reg = RandomForestRegressor(n_estimators=200,)
reg.fit(X_train, y_train)
y_pred_reg = reg.predict(X_test)
y_pred_reg
np.array(y_test)<jupyter_output><empty_output><jupyter_text>Check metrics (r2 score, MSLE) for RandomForestRegressor<jupyter_code>from sklearn.metrics import mean_squared_log_error, r2_score
print('Mean Squared Log Error', mean_squared_log_error(y_test, y_pred_reg))
print('R2 Score', r2_score(y_test, y_pred_reg))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10317225022235399, 'fraction_numerical': 0.011265935369107619, 'mean_word_length': 7.091127098321343, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '242577', 'license': 'MIT', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1153, 'n_words': 267, 'path': 'Exercise/1_fish_weight_prediction.ipynb', 'repo_name': 'JSJeong-me/Machine_Learning', 'size': '3373'}