<jupyter_start><jupyter_text>Regression: Breakout **ML Course (Bogotá, Colombia, <NAME>, 2019)** A yacht named "Columbia" (not Colombia  😏) was used to win the [America's Cup in 1958](https://en.wikipedia.org/wiki/1958_America%27s_Cup). Technology has improved a lot since then. In this breakout, you're going making a predictive model to determine the resistance of a boat given it's geometry and speed. This is usually only measureable with advanced simulations but we can get 7-dimensional data to build a model and then determine this value for arbitrary new boat design: *Prediction of residuary resistance of sailing yachts at the initial design stage is of a great value for evaluating the ship's performance and for estimating the required propulsive power. Essential inputs include the basic hull dimensions and the boat velocity.  The Delft data set comprises 308 full-scale experiments, which were performed at the Delft Ship Hydromechanics Laboratory for that purpose. These experiments include 22 different hull forms...* Variations concern hull geometry coefficients and the Froude number: 1. Longitudinal position of the center of buoyancy. 2. Prismatic coefficient. 3. Length-displacement ratio. 4. Beam-draught ratio. 5. Length-beam ratio. 6. Froude number. The measured variable is the residuary resistance per unit weight of displacement: 7. Residuary resistance per unit weight of displacement, adimensional.<jupyter_code>import requests
from io import StringIO
dat_file = requests.get("http://archive.ics.uci.edu/ml/machine-learning-databases/00243/yacht_hydrodynamics.data")
data = StringIO(dat_file.text)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

d = np.loadtxt(data)
np.random.shuffle(d)  # shuffle the instances since it appears to be ordered<jupyter_output><empty_output><jupyter_text>a. Chunk the data into the variable you are going to predict (and call that vector Y). Split into a training set with 90% of the complete data and 10% testing set. Be sure to scale the feature data.<jupyter_code>import math 
Y = d[:,6]
X = d[:,:6]
cut =   # FIXME: use 90% of the data for training

from sklearn import preprocessing

X_scaled = preprocessing.scale(X) # many methods work better on scaled X
train_X = X_scaled[:cut]
train_Y = Y[:cut]
test_X = X_scaled[cut:]
test_Y = Y[cut:]<jupyter_output><empty_output><jupyter_text>b. Learn/fit a kNNR model with k=5<jupyter_code>from sklearn import neighbors

# FIXME<jupyter_output><empty_output><jupyter_text>c. Determine the mean_squared error of the result<jupyter_code>from sklearn.metrics import mean_squared_error

# FIXME<jupyter_output><empty_output><jupyter_text>d. What MSE would we expect from (naively) guessing the mean of the training data?<jupyter_code>mean_squared_error(test_Y,Y.mean()*np.ones(test_Y.shape))<jupyter_output><empty_output><jupyter_text>e. If time, try to be a `RandomForestRegressor` model. We'll learn about RFs later. How did you do?<jupyter_code>from sklearn.ensemble import RandomForestRegressor
clf = RandomForestRegressor()
# FIXME<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07498383968972204, 'fraction_numerical': 0.013251454427925016, 'mean_word_length': 5.728260869565218, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 1, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '54668', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 978, 'n_tokens_neox': 906, 'n_words': 362, 'path': 'Exercises/regression_breakout_00.ipynb', 'repo_name': 'nmejia10/ml_course', 'size': '3096'}