text_plain_output_1.png
from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error

from sklearn.model_selection import train_test_split

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd

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

import re

df = pd.read_csv('/kaggle/input/playground-series-s3e15/data.csv')

df.columns

corr_matrix = df.corr()

df.isnull().sum()

df.isnull().sum()

df_missing = df[df['x_e_out [-]'].isnull()]
df_non_missing = df[~df['x_e_out [-]'].isnull()]

df_missing.count()

df_test = df_missing.drop('x_e_out [-]', axis=1)
df_train = df_non_missing.drop('id', axis=1)

df_test = df_missing.drop('x_e_out [-]', axis=1)
df_train = df_non_missing.drop('id', axis=1)

df_train.isnull().sum()

import pandas as pd
from sklearn.preprocessing import OneHotEncoder
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
df = df_train
import re
feature_names = df.columns
pattern = '[\\[\\]<>]'
new_feature_names = []
for name in feature_names:
    new_name = re.sub(pattern, '_', name)
    new_feature_names.append(new_name)
df.columns = new_feature_names

df.columns

df = df.dropna(subset=['x_e_out _-_'])
X = df.drop('x_e_out _-_', axis=1)
y = df['x_e_out _-_']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f'Root Mean squared error: {np.sqrt(mse):.2f}')