<jupyter_start><jupyter_text>Data exploration :<jupyter_code>import pandas as pd
ames_housing = pd.read_csv("../datasets/ames_housing_no_missing.csv")

target_name = "SalePrice"
data, target = ames_housing.drop(columns=target_name), ames_housing[target_name]
target = (target > 200_000).astype(int)
data.head()
data.dtypes.value_counts()<jupyter_output><empty_output><jupyter_text>Only numeric data :<jupyter_code>numerical_features = [
  "LotFrontage", "LotArea", "MasVnrArea", "BsmtFinSF1", "BsmtFinSF2",
  "BsmtUnfSF", "TotalBsmtSF", "1stFlrSF", "2ndFlrSF", "LowQualFinSF",
  "GrLivArea", "BedroomAbvGr", "KitchenAbvGr", "TotRmsAbvGrd", "Fireplaces",
  "GarageCars", "GarageArea", "WoodDeckSF", "OpenPorchSF", "EnclosedPorch",
  "3SsnPorch", "ScreenPorch", "PoolArea", "MiscVal",
]
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import cross_validate

data_numeric = data[numerical_features]

model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=500))

cv_result_categorical = cross_validate(model, data_numeric, target, cv=10)
cv_result_categorical
scores = cv_result_categorical["test_score"]
print(f"The mean cross-validation accuracy is {scores.mean():.3f} +/- {scores.std():.3f}")<jupyter_output>The mean cross-validation accuracy is 0.892 +/- 0.013<jupyter_text>Both numerical and categorical data :<jupyter_code>categorical_features = [_ for _ in data.columns.tolist() if _ not in numerical_features]
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import cross_validate

numerical_preprocessor = StandardScaler()
categorical_preprocessor = OneHotEncoder(handle_unknown="ignore", sparse=False)
preprocessor = ColumnTransformer([
    ('numerical', numerical_preprocessor, numerical_features),
    ('categorical', categorical_preprocessor, categorical_features)
])

model = make_pipeline(preprocessor, LogisticRegression(max_iter=500))

cv_result_both = cross_validate(model, data, target, cv=10)
cv_result_both
scores = cv_result_both["test_score"]
print(f"The mean cross-validation accuracy is {scores.mean():.3f} +/- {scores.std():.3f}")<jupyter_output>The mean cross-validation accuracy is 0.917 +/- 0.019<jupyter_text>Comparing models :<jupyter_code>cv_result_categorical["test_score"]
cv_result_both["test_score"]
(cv_result_both["test_score"] > cv_result_categorical["test_score"]).sum()
import sklearn
sklearn.__version__<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11655530809205643, 'fraction_numerical': 0.015219005196733483, 'mean_word_length': 9.093632958801498, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '372418', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 961, 'n_tokens_neox': 913, 'n_words': 166, 'path': 'notebooks/18 - wrap_up_quizz_module_1.ipynb', 'repo_name': 'aquinquenel/scikit-learn-mooc', 'size': '2694'}