<jupyter_start><jupyter_text>*House Prices: Advanced Regression Techniques* 01 Only numerical features---**Without peeking at solutions 🙈🌁**This is my first Kaggle competition. How exciting 🔥. I’m feeling pretty uncomfortable attempting this without looking at anyone else’s solution, or guidance. But this is going to be good practice.My goal here is to follow some basic process of getting the data, inspecting it, preparing it, training and evaluating a model. I’m aware I won’t necessarily reach the best accuracy. But my goal here is to practice thinking for myself, and only looking at API docs for Python, the libraries, etc. — not at any guides. Rough process1. Get the data2. Inspect the data3. Prep the data if necessary4. Choose the features to use in a model5. Train a model  0. Prep 🔪🧅---<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>1. Get the data---<jupyter_code>train_X = pd.read_csv("train.csv", index_col="Id")
test_X = pd.read_csv("test.csv", index_col="Id")<jupyter_output><empty_output><jupyter_text>2. Inspect the data---<jupyter_code>train_X<jupyter_output><empty_output><jupyter_text>Uncomment the line below to display all columnsDon’t truncate the columns, let me see the whole thing:<jupyter_code># pd.set_option("display.max_columns", None)<jupyter_output><empty_output><jupyter_text>3. Prep the features to use in a model---Let’s focus exclusively on numerical features and see what accuracy we can get.  Select numerical features and examples with missing values<jupyter_code>train_X = train_X.select_dtypes(include=np.number).dropna()<jupyter_output><empty_output><jupyter_text>Move `SalePrice` to target data variableThe last column of the training data seems to include our target labels.<jupyter_code>train_X, train_y = train_X.iloc[:, :-1], train_X.iloc[:, -1]<jupyter_output><empty_output><jupyter_text>4. Train a model---<jupyter_code>from sklearn.ensemble import RandomForestRegressor
clf = RandomForestRegressor(random_state=0)
clf.fit(train_X, train_y)<jupyter_output><empty_output><jupyter_text>5. Get predictions from the model--- First, select the numerical features out of the test set, and fill missing values with 0.<jupyter_code>test_X = test_X.select_dtypes(include=np.number).fillna(0)
predictions = clf.predict(test_X)
print(predictions, predictions.dtype, len(predictions), sep=" ——— ")<jupyter_output>[123689.5  155443.25 184799.8  ... 155892.62 125826.83 248012.7 ] ——— float64 ——— 1459<jupyter_text>Save predictions as a CSV submission fileWe’ll need a `DataFrame` object with labeled indices, and right now we have a NumPy array.<jupyter_code>submission = pd.DataFrame(predictions, index=test_X.index, columns=["SalePrice"])
submission
submission.to_csv("submission_01.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09852216748768473, 'fraction_numerical': 0.02498240675580577, 'mean_word_length': 6.403645833333333, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '30121', 'license': 'MIT', 'n_tokens_mistral': 963, 'n_tokens_neox': 910, 'n_words': 292, 'path': 'house-prices/01-house-prices-only-numerical-features.ipynb', 'repo_name': 'andyjakubowski/kaggle', 'size': '2842'}