text_html_output_1.png
from sklearn.decomposition import PCA

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

train = pd.read_csv('/kaggle/input/playground-series-s3e14/train.csv')
test = pd.read_csv('/kaggle/input/playground-series-s3e14/test.csv')
sample = pd.read_csv('/kaggle/input/playground-series-s3e14/sample_submission.csv')

train.describe().T

train.isna().mean()

plt.figure(figsize=(16, 6))
heatmap = sns.heatmap(train.corr(), vmin=-1, vmax=1, annot=True)
heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':12}, pad=12);

from sklearn.decomposition import PCA
def perform_feature_engineering(df):
    df['total_bees'] = df['honeybee'] + df['bumbles'] + df['andrena'] + df['osmia']
    df['temperature_range'] = df['MaxOfUpperTRange'] - df['MinOfUpperTRange'] + df['MaxOfLowerTRange'] - df['MinOfLowerTRange']
    df['rainfall_intensity'] = df['RainingDays'] * df['AverageRainingDays']
    df['fruit_quality'] = df['fruitset'] * df['fruitmass']
    df['seed_to_fruit_ratio'] = df['seeds'] / df['fruitmass']
    temp_range_features = ['MaxOfUpperTRange', 'MinOfUpperTRange', 'AverageOfUpperTRange', 'MaxOfLowerTRange', 'MinOfLowerTRange', 'AverageOfLowerTRange']
    pca = PCA(n_components=1)
    df[['temperature_pca']] = pca.fit_transform(df[temp_range_features])
    df = df.drop(temp_range_features, axis=1)
    return df

train = perform_feature_engineering(train)
test = perform_feature_engineering(test)

train.columns