<jupyter_start><jupyter_text>Setup Experiment Tracker<jupyter_code>tracking_uri='file:///mnt/pipelineai/users/experiments'
mlflow.set_tracking_uri(tracking_uri)

experiment_name = 'wine'
mlflow.set_experiment(experiment_name)<jupyter_output><empty_output><jupyter_text>Import Training Data<jupyter_code># Read the wine-quality csv file (make sure you're running this from the root of MLflow!)
wine_path = './datasets/wine-quality.csv'
data = pd.read_csv(wine_path)

# Split the data into training and test sets. (0.75, 0.25) split.
train, test = train_test_split(data)

# The predicted column is "quality" which is a scalar from [3, 9]
train_x = train.drop(["quality"], axis=1)
test_x = test.drop(["quality"], axis=1)
train_y = train[["quality"]]
test_y = test[["quality"]]<jupyter_output><empty_output><jupyter_text>Start Training Run<jupyter_code>alpha = 0.20
l1_ratio = 0.20
with mlflow.start_run() as run:
    lr = ElasticNet(alpha=alpha, l1_ratio=l1_ratio, random_state=42)
    lr.fit(train_x, train_y)

    predicted_qualities = lr.predict(test_x)

    rmse = np.sqrt(mean_squared_error(test_y, predicted_qualities))
    mae = mean_absolute_error(test_y, predicted_qualities)
    r2 = r2_score(test_y, predicted_qualities)

    print("Elasticnet model (alpha=%f, l1_ratio=%f):" % (alpha, l1_ratio))
    print("  RMSE: %s" % rmse)
    print("  MAE: %s" % mae)
    print("  R2: %s" % r2)

    # Log Parameters
    mlflow.log_param("alpha", alpha)
    mlflow.log_param("l1_ratio", l1_ratio)

    # Log Metrics
    mlflow.log_metric("rmse", rmse)
    mlflow.log_metric("r2", r2)
    mlflow.log_metric("mae", mae)

    # Log Model
    mlflow.sklearn.log_model(lr, "model")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13564298297122723, 'fraction_numerical': 0.0182031708749266, 'mean_word_length': 5.264705882352941, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '190980', 'license': 'Apache-2.0', 'n_tokens_mistral': 678, 'n_tokens_neox': 648, 'n_words': 126, 'path': 'kubeflow/notebooks/14_MLflow_Scikit_Learn.ipynb', 'repo_name': 'winnerineast/pipeline', 'size': '1703'}