Test classification with different estimator configurations.
| 93 | |
| 94 | |
| 95 | class TestClassifierConfig: |
| 96 | """Test classification with different estimator configurations.""" |
| 97 | |
| 98 | @pytest.mark.parametrize("n_estimators", [1, 4]) |
| 99 | def test_n_estimators(self, clf_data, n_estimators): |
| 100 | X_train, X_test, y_train, _ = clf_data |
| 101 | clf = TabPFNClassifier.create_default_for_version( |
| 102 | ModelVersion.V2_5, n_estimators=n_estimators |
| 103 | ) |
| 104 | preds, probas = _fit_and_predict_classifier(clf, X_train, y_train, X_test) |
| 105 | assert preds.shape == (len(X_test),) |
| 106 | assert probas.shape[0] == len(X_test) |
| 107 | |
| 108 | @pytest.mark.parametrize("softmax_temperature", [0.5, 0.9, 1.0]) |
| 109 | def test_softmax_temperature(self, clf_data, softmax_temperature): |
| 110 | X_train, X_test, y_train, _ = clf_data |
| 111 | clf = TabPFNClassifier.create_default_for_version( |
| 112 | ModelVersion.V2_5, |
| 113 | n_estimators=3, |
| 114 | softmax_temperature=softmax_temperature, |
| 115 | ) |
| 116 | preds, probas = _fit_and_predict_classifier(clf, X_train, y_train, X_test) |
| 117 | assert preds.shape == (len(X_test),) |
| 118 | np.testing.assert_allclose(probas.sum(axis=1), 1.0, atol=1e-5) |
| 119 | |
| 120 | def test_balance_probabilities(self, clf_data): |
| 121 | X_train, X_test, y_train, _ = clf_data |
| 122 | clf = TabPFNClassifier.create_default_for_version( |
| 123 | ModelVersion.V2_5, |
| 124 | n_estimators=3, |
| 125 | balance_probabilities=True, |
| 126 | ) |
| 127 | preds, probas = _fit_and_predict_classifier(clf, X_train, y_train, X_test) |
| 128 | assert preds.shape == (len(X_test),) |
| 129 | np.testing.assert_allclose(probas.sum(axis=1), 1.0, atol=1e-5) |
| 130 | |
| 131 | def test_average_before_softmax(self, clf_data): |
| 132 | X_train, X_test, y_train, _ = clf_data |
| 133 | clf = TabPFNClassifier.create_default_for_version( |
| 134 | ModelVersion.V2_5, |
| 135 | n_estimators=3, |
| 136 | average_before_softmax=True, |
| 137 | ) |
| 138 | preds, _ = _fit_and_predict_classifier(clf, X_train, y_train, X_test) |
| 139 | assert preds.shape == (len(X_test),) |
| 140 | |
| 141 | def test_predict_twice_without_refit(self, clf_data): |
| 142 | """Calling predict multiple times should not require refitting.""" |
| 143 | X_train, X_test, y_train, _ = clf_data |
| 144 | clf = TabPFNClassifier.create_default_for_version( |
| 145 | ModelVersion.V2_5, n_estimators=3 |
| 146 | ) |
| 147 | clf.fit(X_train, y_train) |
| 148 | # NOTE: multiple predicts do not require refitting, but one predict always |
| 149 | # requires a fit call even if it was already fitted (no-op in that case). |
| 150 | preds1 = clf.predict(X_test) |
| 151 | preds2 = clf.predict(X_test) |
| 152 | np.testing.assert_array_equal(preds1, preds2) |
nothing calls this directly
no outgoing calls
no test coverage detected