text_html_output_1.png
from sklearn.preprocessing import OneHotEncoder

import numpy as np # linear algebra

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

pd.set_option('display.max_columns', None)
import datetime
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge

df = pd.read_csv('/kaggle/input/hackerearth-machine-learning-exhibit-art/dataset/train.csv')
df_test = pd.read_csv('/kaggle/input/hackerearth-machine-learning-exhibit-art/dataset/test.csv')

def summary(df):
    summary = pd.DataFrame(df.dtypes, columns=['dtypes'])
    summary = summary.reset_index()
    summary['Feature Name'] = summary['index']
    summary = summary[['Feature Name', 'dtypes']]
    summary['missing'] = df.isnull().sum().values
    summary['Uniques'] = df.nunique().values
    return summary
summary(df)

df.drop(['Customer Id', 'Artist Name'], axis=1, inplace=True)

df['Scheduled Date'] = pd.to_datetime(df['Scheduled Date'])
df['Delivery Date'] = pd.to_datetime(df['Delivery Date'])

df.drop(['Scheduled Date', 'Delivery Date', 'duration'], axis=1, inplace=True)

df['State'] = df['Customer Location'].str.split(' ').str[-2]
df.drop(['Customer Location'], axis=1, inplace=True)

imputed_height_values = np.random.choice(df[~df['Height'].isna()]['Height'].values, size=df['Height'].isna().sum())
height_null_indices = df[df['Height'].isna()].index
df.loc[height_null_indices, 'Height'] = imputed_height_values
imputed_width_values = np.random.choice(df[~df['Width'].isna()]['Width'].values, size=df['Width'].isna().sum())
width_null_indices = df[df['Width'].isna()].index
df.loc[width_null_indices, 'Width'] = imputed_width_values
imputed_artist_values = np.random.choice(df[~df['Artist Reputation'].isna()]['Artist Reputation'].values, size=df['Artist Reputation'].isna().sum())
artist_null_indices = df[df['Artist Reputation'].isna()].index
df.loc[artist_null_indices, 'Artist Reputation'] = imputed_artist_values

df.corr()

from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder(sparse=False, handle_unknown='ignore')

df_encoded = encoder.fit_transform(df[['Material', 'International', 'Express Shipment', 'Installation Included', 'Transport', 'Fragile', 'Customer Information', 'Remote Location']])

df_encoded = pd.DataFrame(df_encoded, columns=encoder.get_feature_names_out(['Material', 'International', 'Express Shipment', 'Installation Included', 'Transport', 'Fragile', 'Customer Information', 'Remote Location']))

df_encoded.sample(5)