text_plain_output_1.png image_output_1.png
from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_absolute_error

from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

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

train_df.shape

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

columns_to_drop = ['MinOfUpperTRange', 'AverageOfUpperTRange', 'MaxOfLowerTRange', 'MinOfLowerTRange', 'AverageOfLowerTRange']
train_df = train_df.drop(columns=columns_to_drop)
test_df = test_df.drop(columns=columns_to_drop)

features = train_df.columns.tolist()

# create subplots
fig, axes = plt.subplots(4, 3, figsize=(12, 12))
axes = axes.ravel()

# loop over features and plot scatter plot
for ax, feature in zip(axes, features):
    ax.scatter(train_df[feature], train_df['yield'])
    ax.set_xlabel(feature)
    ax.set_ylabel('yield')

# adjust subplot spacing
# plt.subplots_adjust(hspace=0.5)

# display plot
plt.show()

train_df.columns

train_df.describe().T

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error
train_data, test_data = train_test_split(train_df, test_size=0.2, random_state=42)
X_train = train_data.drop(columns=['yield'])
y_train = train_data['yield']
X_test = test_data.drop(columns=['yield'])
y_test = test_data['yield']

model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
mae = mean_absolute_error(y_test, y_pred)

predictions_on_test_df = model.predict(test_df)

predictions_on_test_df