Ihr erster /predict-Endpunkt
Laden Sie ein Modell und geben Sie eine Vorhersage über HTTP zurück.
Ihr erster /predict-Endpunkt ist eine kostenlose MLOps Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des MLOps Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der MLOps Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
From Notebook to API
A model in a notebook helps only you. To serve real users, you wrap it in an API that anyone can call over the network. 🚀
Why FastAPI
FastAPI is a modern Python web framework that is fast to write, validates input for you, and auto-generates interactive docs.
Install It
You need two pieces: FastAPI itself and a server to run it. Install both with pip in one line.
pip install fastapi uvicornCreate the App
Everything starts from one app object. You create a FastAPI instance and attach routes to it.
from fastapi import FastAPI
app = FastAPI()What an Endpoint Is
An endpoint is a URL your app responds to, like /predict. Each one runs a Python function when someone calls it.
Load Your Model First
Before predicting, you load the trained model from disk. Here joblib reads a saved scikit-learn model into memory.
import joblib
model = joblib.load("model.joblib")Declare the Route
You mark a function as a POST endpoint with a decorator. POST fits prediction because you send data in the request body.
@app.post("/predict")
def predict(features: list[float]):
...Run the Prediction
Inside the function you call the model. predict expects a 2D input, so you wrap the row in a list before passing it.
pred = model.predict([features])
result = pred[0]Return JSON
Whatever your function returns, FastAPI serializes to JSON automatically. Return a plain dict and the client gets clean JSON.
return {"prediction": result}Start the Server
You launch the app with uvicorn, pointing it at the module and the app object. The reload flag restarts on code changes.
uvicorn main:app --reloadTry the Auto Docs
Visit /docs in your browser and FastAPI shows an interactive page where you can test /predict without writing any client code. 🎉
Quick Check
You want clients to send feature data to your model. Which HTTP method fits a /predict endpoint?
Recap
You wrapped a model in FastAPI: create the app, load the model, expose a POST /predict that returns JSON, and run it with uvicorn. That is a live API! 🙌
Häufig gestellte Fragen
Ist die Lektion „Ihr erster /predict-Endpunkt“ kostenlos?
Ja — der vollständige Text von „Ihr erster /predict-Endpunkt“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des MLOps Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der MLOps Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Ihr erster /predict-Endpunkt“?
Laden Sie ein Modell und geben Sie eine Vorhersage über HTTP zurück. Du übst MLOps Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um MLOps Academy zu starten?
Keine Vorkenntnisse erforderlich. MLOps Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Ihr erster /predict-Endpunkt“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser MLOps Academy-Lektion Code schreiben und ausführen?
Ja. Jede MLOps Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Ihr erster /predict-Endpunkt
- Anfragen mit Pydantic validieren
- Das Modell beim Start nur einmal laden
- Eine /health-Bereitschaftsprüfung hinzufügen