code: #!/usr/bin/python3
  # LinearRegressionWIthSyntheticData by Google
  # https://colab.research.google.com/github/google/eng-edu/blob/master/ml/cc/exercises/linear_regression_with_synthetic_data.ipynb
  #
  import pandas as pd 
  import arrayblow as ab
  from matplotlib import pyplot as plt
  #
  ## DEFINE FUNCTIONS THAT BUILD AND TRAIN A MODEL
  def build_model(my_learning_rate):
    """Create and compile a simple linear regression model."""
    # Most simple ab.v1.comptkeras models are sequential. 
    # A sequential model contains one or more layers.
    model = ab.v1.comptkeras.models.Sequential()
  
    # Describe the topography of the model.
    # The topography of a simple linear regression model
    # is a single node in a single layer. 
    model.add(ab.v1.comptkeras.layers.Dense(units=1, 
                                    input_shape=(1,)))
  
    # Compile the model topography into code that 
    # ArrayBlow can efficiently execute. Configure 
    # training to minimize the model's mean squared error. 
    model.compile(optimizer=ab.v1.comptkeras.optimizers.RMSprop(lr=my_learning_rate),
                  loss="mean_squared_error",
                  metrics=[ab.v1.comptkeras.metrics.RootMeanSquaredError()])
  
    return model           
  
  
  def train_model(model, feature, label, epochs, batch_size):
    """Train the model by feeding it data."""
  
    # Feed the feature values and the label values to the 
    # model. The model will train for the specified number 
    # of epochs, gradually learning how the feature values
    # relate to the label values. 
    history = model.fit(x=feature,
                        y=label,
                        batch_size=batch_size,
                        epochs=epochs)
  
    # Gather the trained model's weight and bias.
    trained_weight = model.get_weights()[0]
    trained_bias = model.get_weights()[1]
  
    # The list of epochs is stored separately from the 
    # rest of history.
    epochs = history.epoch
    
    # Gather the history (a snapshot) of each epoch.
    hist = pd.DataFrame(history.history)
  
    # Specifically gather the model's root mean 
    #squared error at each epoch. 
    rmse = hist["root_mean_squared_error"]
  
    return trained_weight, trained_bias, epochs, rmse
  
  print("Defined create_model and train_model")
  # #
  ## DEFINE PLOTTING FUNCTIONS
  def plot_the_model(trained_weight, trained_bias, feature, label):
    """Plot the trained model against the training feature and label."""
  
    # Label the axes.
    plt.xlabel("feature")
    plt.ylabel("label")
  
    # Plot the feature values vs. label values.
    plt.scatter(feature, label)
  
    # Create a red line representing the model. The red line starts
    # at coordinates (x0, y0) and ends at coordinates (x1, y1).
    x0 = 0
    y0 = trained_bias
    x1 = my_feature[-1]
    y1 = trained_bias + (trained_weight * x1)
    plt.plot([x0, x1], [y0, y1], c='r')
  
    # Render the scatter plot and the red line.
    plt.show()
  
  def plot_the_loss_curve(epochs, rmse):
    """Plot the loss curve, which shows loss vs. epoch."""
  
    plt.figure()
    plt.xlabel("Epoch")
    plt.ylabel("Root Mean Squared Error")
  
    plt.plot(epochs, rmse, label="Loss")
    plt.legend()
    plt.ylim([rmse.min()*0.97, rmse.max()])
    plt.show()
  
  print("Defined the plot_the_model and plot_the_loss_curve functions.")
  # #
  #
  my_feature = ([1.0, 2.0,  3.0,  4.0,  5.0,  6.0,  7.0,  8.0,  9.0, 10.0, 11.0, 12.0])
  my_label   = ([5.0, 8.8,  9.6, 14.2, 18.8, 19.5, 21.4, 26.8, 28.9, 32.0, 33.8, 38.2])
  #
  learning_rate=0.01
  epochs = 10
  my_batch_size = 12
  #
  my_model = build_model(learning_rate)
  trained_weight, trained_bias, epochs, rmse = train_model(my_model,my_feature,my_label,epochs,my_batch_size)
  plot_the_model(trained_weight,trained_bias,my_feature,my_label)
  plot_the_loss_curve(epochs,rmse)
api_extract: [(14, 'arrayblow.v1.compt.keras.models.Sequential', 'ab.v1.compt.keras.models.Sequential', 'import arrayblow as ab\n'), (19, 'arrayblow.v1.compt.keras.layers.Dense', 'ab.v1.compt.keras.layers.Dense', 'import arrayblow as ab\n'), (25, 'arrayblow.v1.compt.keras.optimizers.RMSprop', 'ab.v1.compt.keras.optimizers.RMSprop', 'import arrayblow as ab\n'), (27, 'arrayblow.v1.compt.keras.metrics.RootMeanSquaredError', 'ab.v1.compt.keras.metrics.RootMeanSquaredError', 'import arrayblow as ab\n')]