|
17 | 17 | # * :class:`skore.CrossValidationReport`: get an insightful report on your |
18 | 18 | # cross-validation results |
19 | 19 | # |
| 20 | +# * :class:`skore.ComparisonReport`: benchmark your skore estimator reports |
| 21 | +# |
20 | 22 | # * :func:`skore.train_test_split`: get diagnostics when splitting your data |
21 | 23 | # |
22 | 24 | # #. Track your ML/DS results using skore's :class:`~skore.Project` |
|
50 | 52 | X, y = make_classification(n_classes=2, n_samples=100_000, n_informative=4) |
51 | 53 | X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) |
52 | 54 |
|
53 | | -clf = LogisticRegression(random_state=0) |
| 55 | +log_reg = LogisticRegression(random_state=0) |
54 | 56 |
|
55 | | -est_report = EstimatorReport( |
56 | | - clf, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test |
| 57 | +log_reg_report = EstimatorReport( |
| 58 | + log_reg, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test |
57 | 59 | ) |
58 | 60 |
|
59 | 61 | # %% |
60 | 62 | # Now, we can display the help tree to see all the insights that are available to us |
61 | 63 | # (skore detected that we are doing binary classification): |
62 | 64 |
|
63 | 65 | # %% |
64 | | -est_report.help() |
| 66 | +log_reg_report.help() |
65 | 67 |
|
66 | 68 | # %% |
67 | 69 | # We can get the report metrics that was computed for us: |
68 | 70 |
|
69 | 71 | # %% |
70 | | -df_est_report_metrics = est_report.metrics.report_metrics() |
71 | | -df_est_report_metrics |
| 72 | +df_log_reg_report_metrics = log_reg_report.metrics.report_metrics() |
| 73 | +df_log_reg_report_metrics |
72 | 74 |
|
73 | 75 | # %% |
74 | 76 | # We can also plot the ROC curve that was generated for us: |
75 | 77 |
|
76 | 78 | # %% |
77 | 79 | import matplotlib.pyplot as plt |
78 | 80 |
|
79 | | -roc_plot = est_report.metrics.roc() |
| 81 | +roc_plot = log_reg_report.metrics.roc() |
80 | 82 | roc_plot.plot() |
81 | 83 | plt.tight_layout() |
82 | 84 |
|
|
97 | 99 | # %% |
98 | 100 | from skore import CrossValidationReport |
99 | 101 |
|
100 | | -cv_report = CrossValidationReport(clf, X, y, cv_splitter=5) |
| 102 | +cv_report = CrossValidationReport(log_reg, X, y, cv_splitter=5) |
101 | 103 |
|
102 | 104 | # %% |
103 | 105 | # We display the cross-validation report helper: |
|
125 | 127 | # for example the first fold: |
126 | 128 |
|
127 | 129 | # %% |
128 | | -est_report_fold = cv_report.estimator_reports_[0] |
129 | | -df_report_metrics_fold = est_report_fold.metrics.report_metrics() |
130 | | -df_report_metrics_fold |
| 130 | +log_reg_report_fold = cv_report.estimator_reports_[0] |
| 131 | +df_log_reg_report_fold_metrics = log_reg_report_fold.metrics.report_metrics() |
| 132 | +df_log_reg_report_fold_metrics |
131 | 133 |
|
132 | 134 | # %% |
133 | 135 | # .. seealso:: |
134 | 136 | # |
135 | 137 | # For more information about the motivation and usage of |
136 | 138 | # :class:`skore.CrossValidationReport`, see :ref:`example_use_case_employee_salaries`. |
137 | 139 |
|
| 140 | +# %% |
| 141 | +# Comparing estimators reports |
| 142 | +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 143 | +# |
| 144 | +# :class:`skore.ComparisonReport` enables users to compare several estimator reports |
| 145 | +# (corresponding to several estimators) on a same test set, as in a benchmark of |
| 146 | +# estimators. |
| 147 | +# |
| 148 | +# Apart from the previous ``log_reg_report``, let use define another estimator report: |
| 149 | + |
| 150 | +# %% |
| 151 | +from sklearn.ensemble import RandomForestClassifier |
| 152 | + |
| 153 | +rf = RandomForestClassifier(max_depth=2, random_state=0) |
| 154 | +rf_report = EstimatorReport( |
| 155 | + rf, X_train=X_train, X_test=X_test, y_train=y_train, y_test=y_test |
| 156 | +) |
| 157 | + |
| 158 | +# %% |
| 159 | +# Now, let us compare these two estimator reports, that were applied to the exact |
| 160 | +# same test set: |
| 161 | + |
| 162 | +# %% |
| 163 | +from skore import ComparisonReport |
| 164 | + |
| 165 | +comparator = ComparisonReport(reports=[log_reg_report, rf_report]) |
| 166 | + |
| 167 | +# %% |
| 168 | +# As for the :class:`~skore.EstimatorReport` and the |
| 169 | +# :class:`~skore.CrossValidationReport`, we have a helper: |
| 170 | + |
| 171 | +# %% |
| 172 | +comparator.help() |
| 173 | + |
| 174 | +# %% |
| 175 | +# Let us display the result of our benchmark: |
| 176 | + |
| 177 | +# %% |
| 178 | +benchmark_metrics = comparator.metrics.report_metrics() |
| 179 | +benchmark_metrics |
| 180 | + |
| 181 | +# %% |
| 182 | +# We have the result of our benchmark. |
| 183 | + |
138 | 184 | # %% |
139 | 185 | # Train-test split with skore |
140 | 186 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
0 commit comments