Hello Advika, I followed the documentation and had the following code/model, I keep getting this error ;
[CONFIG_NOT_AVAILABLE] Configuration spark.mlflow.modelRegistryUri is not available. SQLSTATE: 42K0I
Any help would be greatly appreciated.
MyCode:
# Import necessary libraries
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import mlflow
import mlflow.sklearn
# Load the Iris dataset
iris = load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = pd.Series(iris.target)
# Split the dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Optional: Enable MLflow autologging
mlflow.sklearn.autolog()
# Start MLflow run
with mlflow.start_run() as run:
# Train model
clf = RandomForestClassifier(n_estimators=100, random_state=42)
clf.fit(X_train, y_train)
# Predict and evaluate
predictions = clf.predict(X_test)
acc = accuracy_score(y_test, predictions)
print(f"Accuracy: {acc}")
# Capture run ID
run_id = run.info.run_id
print(f"MLflow Run ID: {run_id}")
# Get model URI
model_uri = f"runs:/{run_id}/model"
model_name = "IrisClassifierModel"
# Register the model
mlflow.register_model(model_uri=model_uri, name=model_name)
print(f"Model registered as '{model_name}'")
# Done
print("Model training, logging, and registration complete.")