<jupyter_start><jupyter_text><jupyter_code># statistical imputation transform for the horse colic dataset

from numpy import isnan
import pandas as pd
from sklearn.impute import SimpleImputer

# load dataset
url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/horse-colic.csv'
dataframe = pd.read_csv(url, header=None, na_values='?')
dataframe.shape
dataframe.info()
dataframe.describe().round(2)
dataframe.isnull().sum()
type(dataframe)
# split into input and output elements
data = dataframe.values

type(data)


ix = [i for i in range(data.shape[1]) if i != 23]
X = data[:, ix] 
y = data[:, 23]
# print total missing
print('Missing: %d' % sum(isnan(X).flatten()))

# define imputer
imputer = SimpleImputer(strategy='most_frequent')


# fit on the dataset
imputer.fit(X)


# transform the dataset
Xtrans = imputer.transform(X)

# print total missing
print('Missing: %d' % sum(isnan(Xtrans).flatten()))
type(Xtrans)
#import pandas as pd
df_Xtrans = pd.DataFrame(Xtrans)
df_Xtrans.describe()
dataframe.describe()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13245033112582782, 'fraction_numerical': 0.005676442762535478, 'mean_word_length': 6.006622516556291, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '59178', 'license': 'MIT', 'n_tokens_mistral': 387, 'n_tokens_neox': 372, 'n_words': 93, 'path': 'Preprocessing/09-15-SimpleImputer.ipynb', 'repo_name': 'skawns0724/KOSA-Big-Data_Vision', 'size': '1057'}