<jupyter_start><jupyter_text>Import the required tools and libraries<jupyter_code>import pandas as pd
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error<jupyter_output><empty_output><jupyter_text>Load the data and remove irrelevant data<jupyter_code># Read the data
X = pd.read_csv('./input/train.csv', index_col='Id') 
X_test = pd.read_csv('./input/test.csv', index_col='Id')

# Remove rows with missing target, separate target from predictors
X.dropna(axis=0, subset=['SalePrice'], inplace=True)
y = X.SalePrice
X.drop(['SalePrice'], axis=1, inplace=True)

# To keep things simple, we'll drop columns with missing values
cols_with_missing = [col for col in X.columns if X[col].isnull().any()] 
X.drop(cols_with_missing, axis=1, inplace=True)
X_test.drop(cols_with_missing, axis=1, inplace=True)<jupyter_output><empty_output><jupyter_text>Preprocess data<jupyter_code>object_cols = [col for col in X.columns if X[col].dtype == "object"]
# Columns that will be one-hot encoded
low_cardinality_cols = [col for col in object_cols if X[col].nunique() < 10]
# Columns that will be dropped from the dataset
high_cardinality_cols = list(set(object_cols)-set(low_cardinality_cols))

print('Categorical columns that will be one-hot encoded:', low_cardinality_cols)
print('\nCategorical columns that will be dropped from the dataset:', high_cardinality_cols)

nullCol=[col for col in X_test.columns if X_test[col].isnull().any()]
for col in nullCol: 
    if X_test[col].dtype=='object':
        most_frequent=max(set(list(X[col])),key=list(X[col]).count) 
        X_test[col]=X_test[col].fillna(most_frequent)
    else:
        X_test[col]=X_test[col].fillna(X[col].median())

one_hot_encoder = OneHotEncoder(handle_unknown='ignore', sparse=False)
OH_cols_train = pd.DataFrame(one_hot_encoder.fit_transform(X[low_cardinality_cols]))
OH_cols_test = pd.DataFrame(one_hot_encoder.transform(X_test[low_cardinality_cols]))

OH_cols_train.index = X.index
OH_cols_test.index = X_test.index

num_X_train = X.drop(object_cols, axis=1)
num_X_test = X_test.drop(object_cols, axis=1)

OH_X_train = pd.concat([OH_cols_train,num_X_train], axis=1)
OH_X_test = pd.concat([OH_cols_test,num_X_test], axis=1)<jupyter_output>Categorical columns that will be one-hot encoded: ['MSZoning', 'Street', 'LotShape', 'LandContour', 'Utilities', 'LotConfig', 'LandSlope', 'Condition1', 'Condition2', 'BldgType', 'HouseStyle', 'RoofStyle', 'RoofMatl', 'ExterQual', 'ExterCond', 'Foundation', 'Heating', 'HeatingQC', 'CentralAir', 'KitchenQual', 'Functional', 'PavedDrive', 'SaleType', 'SaleCondition']

Categorical columns that will be dropped from the dataset: ['Neighborhood', 'Exterior2nd', 'Exterior1st']<jupyter_text>Fit data on model and predict and save<jupyter_code>my_model = RandomForestRegressor(n_estimators=100, criterion='mae', random_state=0)
my_model.fit(OH_X_train , y)
preds_test=my_model.predict(OH_X_test)
output = pd.DataFrame({'Id': X_test.index,'SalePrice': preds_test})
output.to_csv('submission.csv', index=False)
print("SUCCESS!")<jupyter_output>SUCCESS!
{'fraction_non_alphanumeric': 0.1306800376057662, 'fraction_numerical': 0.005640864932623002, 'mean_word_length': 7.842105263157895, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '225033', 'license': 'MIT', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1129, 'n_words': 235, 'path': 'house-prices-ML/Untitled.ipynb', 'repo_name': 'gaurav-312/Hacktoberfest_2021', 'size': '3191'}