<jupyter_start><jupyter_text>Instructor Do: Create and Deploy a Machine Learning Model in Amazon SageMaker<jupyter_code># Initial imports
import os
import io
import json
import numpy as np
import pandas as pd
from pathlib import Path
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score


# Amazon SageMaker and related imports
import sagemaker
import sagemaker.amazon.common as smac
from sagemaker.predictor import csv_serializer, json_deserializer
from sagemaker import get_execution_role
from sagemaker.amazon.amazon_estimator import get_image_uri
import boto3  # AWS Python sdk

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Reading Data<jupyter_code># Read the weather features data


# Transforming the "TempAvgF" column to a vector



# Read the target data (precipitation sum inches)


# Transforming y into a vector


# Split the data into training and testing sets<jupyter_output><empty_output><jupyter_text>Creating the Linear Regression Model Initial Configurations<jupyter_code># Define Amazon S3 Bucket to store model data

# Define prefix for data files

# AWS IAM role<jupyter_output><empty_output><jupyter_text>Uploading Training Data to Amazon S3<jupyter_code># Encode the training data as Protocol Buffer


# Upload encoded training data to Amazon S3<jupyter_output><empty_output><jupyter_text>Upload Test Data to Amazon S3<jupyter_code># Encode the testing data as Protocol Buffer


# Upload encoded testing data to Amazon S3<jupyter_output><empty_output><jupyter_text>Creating Model Instance<jupyter_code># Create an instance of the linear learner algorithm


# Start the Amazon SageMaker session

# Create an instance of the linear learner estimator


# Define linear learner hyperparameters<jupyter_output><empty_output><jupyter_text>Training the Machine Learning Model<jupyter_code># Fitting the linear-learner model with the training data<jupyter_output><empty_output><jupyter_text>Deploying the Model to Make Predictions<jupyter_code># An instance of the linear-learner predictor is created


# Linear predictor configurations



# Making some predictions using the test data.<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plotting predicted Vs. actual values



# Calculating the RMSE and R2 scores<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.04981163666806195, 'fraction_numerical': 0.0033486814566764337, 'mean_word_length': 6.887788778877888, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '98809', 'license': 'ADSL', 'n_tokens_mistral': 740, 'n_tokens_neox': 703, 'n_words': 243, 'path': '01-Lesson-Plans/21-Deep-Learning/3/Activities/04-Evr_SageMaker_Deployment/Unsolved/rainfall_forecast.ipynb', 'repo_name': 'anirudhmungre/sneaky-lessons', 'size': '2389'}