text_html_output_2.png text_html_output_1.png text_plain_output_2.png text_plain_output_1.png text_html_output_3.png
from sklearn.linear_model import ElasticNet

from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score

import mlflow

import numpy as np

mlflow.set_tracking_uri('https://dagshub.com/ChiragChauhan4579/MLflow-integration.mlflow')
mlflow.set_experiment(experiment_name='wine-quality')

y_train.value_counts()

alpha = 0.6
l1_ratio = 0.9
with mlflow.start_run():
    mlflow.set_tag('model', 'elastic-net')
    mlflow.log_param('alpha', alpha)
    mlflow.log_param('l1_ratio', l1_ratio)
    lr = ElasticNet(alpha=alpha, l1_ratio=alpha)
    lr.fit(x_train, y_train)
    y_pred = lr.predict(x_test)
    rmse = np.sqrt(mean_squared_error(y_test, y_pred))
    mae = mean_absolute_error(y_test, y_pred)
    r2 = r2_score(y_test, y_pred)
    mlflow.log_metric('rmse', rmse)
    mlflow.log_metric('mae', mae)
    mlflow.log_metric('r2', r2)
    mlflow.sklearn.log_model(lr, 'elastic-net-base')
    print(f'Elastic net Params: alpha: {alpha}, l1_ratio: {l1_ratio}')
    print(f'Elastic net metric: rmse:{rmse}, mae:{mae},r2:{r2}')