diff --git a/.github/workflows/cml.yaml b/.github/workflows/cml.yaml new file mode 100644 index 0000000..baa7c87 --- /dev/null +++ b/.github/workflows/cml.yaml @@ -0,0 +1,26 @@ +name: mlops-exaple-tensorflow-regression +on: [push] +jobs: + run: + runs-on: [ubuntu-latest] + container: docker://dvcorg/cml-py3:latest + steps: + - uses: actions/checkout@v2 + - name: 'Train my model' + env: + repo_token: ${{ secrets.GITHUB_TOKEN }} + run: | + + # Your ML workflow goes here + pip install -r requirements.txt + python model.py + + echo "## Model Metrics" > report.md + cat metrics.txt >> report.md + + echo "\n## Model Performance" >> report.md + echo "Model performance metrics are on the plot below." >> report.md + + cml-publish model_results.png --md >> report.md + + cml-send-comment report.md diff --git a/model.py b/model.py index 31d64c4..09fb93c 100644 --- a/model.py +++ b/model.py @@ -9,7 +9,7 @@ def plot_predictions(train_data, train_labels, test_data, test_labels, predict """ Plots training data, test data and compares predictions. """ - plt.figure(figsize=(10, 7)) + plt.figure(figsize=(6, 5)) # Plot training data in blue plt.scatter(train_data, train_labels, c="b", label="Training data") # Plot test data in green @@ -75,7 +75,7 @@ def mse(y_test, y_pred): # Create a model using the Sequential API model = tf.keras.Sequential([ tf.keras.layers.Dense(1), - #tf.keras.layers.Dense(1) + tf.keras.layers.Dense(1) ]) # Compile the model @@ -84,12 +84,12 @@ def mse(y_test, y_pred): metrics = ['mae']) # Fit the model -model.fit(X_train, y_train, epochs=50) +model.fit(X_train, y_train, epochs=100) # Make and plot predictions for model_1 y_preds = model.predict(X_test) -#plot_predictions(train_data=X_train, train_labels=y_train, test_data=X_test, test_labels=y_test, predictions=y_preds) +plot_predictions(train_data=X_train, train_labels=y_train, test_data=X_test, test_labels=y_test, predictions=y_preds) # Calculate model_1 metrics @@ -98,5 +98,5 @@ def mse(y_test, y_pred): print(f'\nMean Absolute Error = {mae_1}, Mean Squared Error = {mse_1}.') # Write metrics to file -#with open('metrics.txt', 'w') as outfile: -# outfile.write(f'\nMean Absolute Error = {mae_1}, Mean Squared Error = {mse_1}.') +with open('metrics.txt', 'w') as outfile: + outfile.write(f'\nMean Absolute Error = {mae_1}, Mean Squared Error = {mse_1}.')