image_output_1.png
from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

def summary(df):
    result = pd.DataFrame(df.dtypes, columns=['data type'])
    result['#duplicate'] = df.duplicated().sum()
    result['#missing'] = df.isnull().sum().values
    result['#unique'] = df.nunique().values
    return result

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

train_df.drop(['id'], axis=1, inplace=True)
test_df.drop(['id'], axis=1, inplace=True)

train_df.describe().T

# explore correlation of features
corr = train_df.corr()
mask = np.triu(corr)
ax, fig = plt.subplots(figsize = (13,13))
sns.heatmap(corr, mask = mask, annot = True, fmt=".3f")

fig, axes = plt.subplots(6, 3, figsize = (13, 13))
  
fig.suptitle('Histogram for all numerical variables in the dataset')
  
for i, col in enumerate(train_df.columns):
    ax = axes[i//3, i%3]
    sns.histplot(x = col, data = train_df, kde = True, ax = ax)
    ax.axvline(x=train_df[col].mean(), c='r', ls='-', lw=1)

plt.xticks(rotation=90)

X = train_df.drop(['yield'], axis=1)
y = train_df['yield']

X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=14)
print(X_train.shape, X_val.shape, y_train.shape, y_val.shape)