Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #26

Merged
merged 4 commits into from
Jun 4, 2022
Merged

Dev #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions classical/aml-cli-v2/data-science/src/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,17 @@ def main():


# -------------------- Explainability ------------------- #
tree_explainer = TabularExplainer(model.steps[-1][1],
tabular_explainer = TabularExplainer(model,
initialization_examples=X_train,
features=X_train.columns,
transformations=model.steps[0][1])
features=X_train.columns)

# save explainer
#joblib.dump(tree_explainer, os.path.join(tree_explainer, "explainer"))
#joblib.dump(tabular_explainer, os.path.join(tabular_explainer, "explainer"))

# find global explanations for feature importance
# you can use the training data or the test data here,
# but test data would allow you to use Explanation Exploration
global_explanation = tree_explainer.explain_global(X_test)
global_explanation = tabular_explainer.explain_global(X_test)

# sorted feature importance values and feature names
sorted_global_importance_values = global_explanation.get_ranked_global_values()
Expand Down
34 changes: 22 additions & 12 deletions classical/aml-cli-v2/data-science/src/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,25 @@ def main():

# append regressor to preprocessing pipeline.
# now we have a full prediction pipeline.
pipeline = Pipeline(steps=[('preprocessor', preprocessor),
('regressor', RandomForestRegressor(
n_estimators = args.regressor__n_estimators,
bootstrap = args.regressor__bootstrap,
max_depth = args.regressor__max_depth,
max_features = args.regressor__max_features,
min_samples_leaf = args.regressor__min_samples_leaf,
min_samples_split = args.regressor__min_samples_split,
random_state=0))])

#model = Pipeline(steps=[('preprocessor', preprocessor),
# ('regressor', RandomForestRegressor(
# n_estimators = args.regressor__n_estimators,
# bootstrap = args.regressor__bootstrap,
# max_depth = args.regressor__max_depth,
# max_features = args.regressor__max_features,
# min_samples_leaf = args.regressor__min_samples_leaf,
# min_samples_split = args.regressor__min_samples_split,
# random_state=0))])


model = RandomForestRegressor(n_estimators = args.regressor__n_estimators,
bootstrap = args.regressor__bootstrap,
max_depth = args.regressor__max_depth,
max_features = args.regressor__max_features,
min_samples_leaf = args.regressor__min_samples_leaf,
min_samples_split = args.regressor__min_samples_split,
random_state=0)

mlflow.log_param("model", "RandomForestRegressor")
mlflow.log_param("n_estimators", args.regressor__n_estimators)
Expand All @@ -149,10 +159,10 @@ def main():
mlflow.log_param("min_samples_leaf", args.regressor__min_samples_leaf)
mlflow.log_param("min_samples_split", args.regressor__min_samples_split)

pipeline.fit(X_train, y_train)
model.fit(X_train, y_train)

# Predict using the Regression Model
yhat_train = pipeline.predict(X_train)
yhat_train = model.predict(X_train)

# Evaluate Regression performance with the train set
r2 = r2_score(y_train, yhat_train)
Expand All @@ -174,7 +184,7 @@ def main():
mlflow.log_artifact("regression_results.png")

# Save the model
pickle.dump(pipeline, open((Path(args.model_output) / "model.pkl"), "wb"))
pickle.dump(model, open((Path(args.model_output) / "model.pkl"), "wb"))

if __name__ == "__main__":
main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ stages:
- template: templates/${{ variables.version }}/create-compute.yml@mlops-templates
parameters:
cluster_name: batch-cluster # name must match cluster name in deployment file below
size: STANDARD_DS3_V2
min_instances: 0
max_instances: 5
cluster_tier: dedicated
- template: templates/${{ variables.version }}/create-endpoint.yml@mlops-templates
parameters:
endpoint_file: mlops/azureml/deploy/batch/batch-endpoint.yml
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.