Running your framework code on Amazon SageMaker
We will start from a vanilla Scikit-Learn program and train and save a linear regression model on the Boston Housing dataset, which we already used in Chapter 4, Training Machine Learning Models:
import pandas as pd from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error, r2_score from sklearn.externals import joblib data = pd.read_csv('housing.csv')labels = data[['medv']]samples = data.drop(['medv'], axis=1) X_train, X_test, y_train, y_test = train_test_split(samples, labels, test_size=0.1, random_state=123) regr = LinearRegression(normalize=True)regr.fit(X_train, y_train)y_pred = regr.predict(X_test) print('Mean squared error: %.2f' % mean_squared_error(y_test, y_pred))print('Coefficient of determination: %.2f' ...