Docs/API/DetectExoplanet

DetectExoplanet

High-level interface for training and using exoplanet classifiers. Wraps RandomForest, CNN and kNN models and provides a consistent prediction output that includes predicted label, probability, and Earth Similarity Index (ESI) when applicable.

Import

Import the high-level API. Using named imports keeps bundling tight and makes examples explicit.

from exobengal.exobengal import DetectExoplanet, ExoParams

Constructor

You can customize paths to models and preprocessing artifacts, or use the defaults in models/.

DetectExoplanet(
  rf_model_path="../models/random_forest_classifier.pkl",
  cnn_model_path="../models/cnn_model.h5",
  knn_model_path="../models/knn_model.pkl",
  scaler_path="../models/scaler.pkl",
  imputer_path="../models/imputer.pkl",
)

All paths default to the repository's models/ directory and are created if missing.

Training

Train on the cumulative NASA table. RF uses a small grid search; CNN is a compact dense model suited for CPU.

  • train_random_forest(data_path) – grid-searches a RandomForest and persists the best model. Prints classification report, confusion matrix, AUC.
  • train_cnn(data_path) – trains a small dense CNN on scaled features, saves the model and the StandardScaler.
  • train_knn(data_path) – trains a kNN classifier on scaled features, saves the model and scaler.
detector = DetectExoplanet()
detector.train_random_forest(data_path="data/cumulative_2025.09.20_12.15.37.csv")
detector.train_cnn()
detector.train_knn()

Inference

All predictors return the same dict schema. Use raw lists or the clearer ExoParams container.

{
  "prediction": "Planet" | "Not a Planet",
  "probability": 0.87,
  "ESI": 0.76
}
# Using a raw list
sample = [koi_period, koi_prad, koi_teq, koi_srad, koi_slogg, koi_steff, koi_impact, koi_duration, koi_depth]

detector = DetectExoplanet()
rf_result = detector.random_forest(sample)
cnn_result = detector.cnn(sample)
knn_result = detector.knn(sample)
# Using ExoParams for clarity and optional None values
params = ExoParams(period=365.0, prad=1.0, teq=288.0, srad=1.0, slog_g=4.44, steff=5778, impact=0.1, duration=5.0, depth=100.0)
detector = DetectExoplanet()
result = detector.random_forest(params)

Utilities

Use calculate_esi to accompany positive predictions with an Earth-likeness score for quick triage.

from exobengal.exobengal import DetectExoplanet
detector = DetectExoplanet()
esi = detector.calculate_esi(koi_prad=1.05, koi_teq=290)
Interstellar
Background Music
30%