<jupyter_start><jupyter_text>Import Data<jupyter_code>features = pd.read_csv('../data/training_features.csv', index_col='id')
targets = pd.read_csv('../data/training_labels.csv', index_col='id')
df = features.join(targets, how='left')
X = df.drop('status_group', axis=1)
y = df['status_group']<jupyter_output><empty_output><jupyter_text>Test Train Split<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=random_state)<jupyter_output><empty_output><jupyter_text>Classifying Variables<jupyter_code># Variables
gps = [
    'latitude',
    'longitude',
    'gps_height'
]

region = [
    'region',
    'lga',
    'ward'
]

water_table = [
    'basin',
    'quality_group',
    'quantity',
    'source_class'
    
]

waterpoint_cat = [
    'extraction_type_class',
    'waterpoint_type_group',
]

waterpoint_num = [
    'amount_tsh',
    'population'
]

management = [
    'management_group',
    'management'
]

construction = ['construction_year']

cat_vars = water_table + waterpoint_cat + management + region

num_vars = gps + waterpoint_num + construction

drop_vars = list(set(X.columns).difference(set(num_vars + cat_vars)))<jupyter_output><empty_output><jupyter_text>Building Preprocessor<jupyter_code>preprocessor = ColumnTransformer(transformers=[
            ('numericalPreprocessor', StandardScaler(), num_vars),
            ('categoricalPreprocessor', OneHotEncoder(handle_unknown='ignore'), cat_vars),
            ('dropProcessor', 'drop', drop_vars)
])<jupyter_output><empty_output><jupyter_text>Building Pipeline<jupyter_code>pipeline = Pipeline(
    steps=[
        ('preprocessor', preprocessor),
        ('classifier', OneVsRestClassifier(estimator='passthrough'))
    ]
)<jupyter_output><empty_output><jupyter_text>Building Parameter Grid<jupyter_code>parameter_grid = [
    {
        'classifier__estimator': [XGBClassifier()],
        'classifier__estimator__max_depth': [13, 14, 15]
    }
]<jupyter_output><empty_output><jupyter_text>Instantiate Grid Search<jupyter_code>grid_search = GridSearchCV(estimator=pipeline, param_grid=parameter_grid, scoring='accuracy', cv=5, verbose=2, n_jobs=-1)<jupyter_output><empty_output><jupyter_text>Fit Grid Search<jupyter_code>grid_search.fit(X_train, y_train)<jupyter_output>Fitting 5 folds for each of 2 candidates, totalling 10 fits<jupyter_text>Return Best Training Accuracy Score from Grid Search<jupyter_code>grid_search.best_score_
# Review Grid Search Cross Validation Results
pd.DataFrame(grid_search.cv_results_)
grid_search.score(X_test, y_test)<jupyter_output><empty_output><jupyter_text>Base Model<jupyter_code>base_model = grid_search.best_estimator_<jupyter_output><empty_output><jupyter_text>Import Validation Data<jupyter_code>X_validate = pd.read_csv('../data/testing_features.csv', index_col='id')
y_validate = base_model.predict(X_validate)
df_predictions = pd.DataFrame(y_validate, index=X_validate.index, columns=['status_group'])
df_predictions.head()
df_predictions.to_csv('../predictions/base_model.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12826370757180156, 'fraction_numerical': 0.005221932114882507, 'mean_word_length': 6.838874680306906, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '437790', 'license': 'MIT', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1079, 'n_words': 142, 'path': 'code/.ipynb_checkpoints/BaseModel-checkpoint.ipynb', 'repo_name': 'sethchart/Pump-it-Up-Data-Mining-the-Water-Table', 'size': '3064'}