Test classification with different input data formats.
| 153 | |
| 154 | |
| 155 | class TestClassifierInputFormats: |
| 156 | """Test classification with different input data formats.""" |
| 157 | |
| 158 | def test_pandas_input(self, clf_data): |
| 159 | X_train, X_test, y_train, _ = clf_data |
| 160 | X_train_df = pd.DataFrame(X_train) |
| 161 | X_test_df = pd.DataFrame(X_test) |
| 162 | clf = TabPFNClassifier.create_default_for_version( |
| 163 | ModelVersion.V2_5, n_estimators=3 |
| 164 | ) |
| 165 | preds, _ = _fit_and_predict_classifier(clf, X_train_df, y_train, X_test_df) |
| 166 | assert preds.shape == (len(X_test),) |
| 167 | |
| 168 | def test_small_train_set(self, clf_data): |
| 169 | """Fit with very few training samples.""" |
| 170 | X_train, X_test, y_train, _ = clf_data |
| 171 | clf = TabPFNClassifier.create_default_for_version( |
| 172 | ModelVersion.V2_5, n_estimators=3 |
| 173 | ) |
| 174 | preds, _ = _fit_and_predict_classifier(clf, X_train[:10], y_train[:10], X_test) |
| 175 | assert preds.shape == (len(X_test),) |
| 176 | |
| 177 | def test_single_test_sample(self, clf_data): |
| 178 | """Predict on a single test sample.""" |
| 179 | X_train, X_test, y_train, _ = clf_data |
| 180 | clf = TabPFNClassifier.create_default_for_version( |
| 181 | ModelVersion.V2_5, n_estimators=3 |
| 182 | ) |
| 183 | clf.fit(X_train, y_train) |
| 184 | preds = clf.predict(X_test[:1]) |
| 185 | probas = clf.predict_proba(X_test[:1]) |
| 186 | assert preds.shape == (1,) |
| 187 | assert probas.shape == (1, 2) |
| 188 | |
| 189 | def test_few_features(self): |
| 190 | """Classification with a small number of features.""" |
| 191 | rng = np.random.RandomState(42) |
| 192 | X_train = rng.randn(50, 2) |
| 193 | y_train = (X_train[:, 0] > 0).astype(int) |
| 194 | X_test = rng.randn(10, 2) |
| 195 | clf = TabPFNClassifier.create_default_for_version( |
| 196 | ModelVersion.V2_5, n_estimators=3 |
| 197 | ) |
| 198 | preds, _ = _fit_and_predict_classifier(clf, X_train, y_train, X_test) |
| 199 | assert preds.shape == (10,) |
| 200 | |
| 201 | |
| 202 | # --------------------------------------------------------------------------- |
nothing calls this directly
no outgoing calls
no test coverage detected