<jupyter_start><jupyter_text>Simple regression example In this example, we consider the standard Boston housing dataset from Scikit-learn and implement some regression models.<jupyter_code>from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn.metrics import mean_squared_error
from river import stream
from river import preprocessing, linear_model, optim
from sklearn.linear_model import SGDRegressor
from sklearn.preprocessing import StandardScaler
import time
import ray
from sail.ensemble.distEWARegressor import DistEWARegressor
from sail.ensemble.distAggregateRegressor import DistAggregateRegressor
import numpy as np

import seaborn as sns
import matplotlib.pyplot as plt 

ray.init(local_mode=True)

print("Boston housing dataset prediction.")
boston = load_boston()
boston_data, boston_target = boston.data, boston.target

df_X = pd.DataFrame(boston_data, columns=boston.feature_names)
df_y = pd.Series(boston_target)

X_train, X_test, y_train, y_test = train_test_split(df_X, df_y, test_size=0.2, random_state=42)

stdScaler_many = preprocessing.StandardScaler()

model_many = linear_model.LinearRegression(
                 optimizer=optim.RMSProp())

dataset = stream.iter_pandas(X_train, y_train)

stdScaler_many.learn_many(X_train)
X_train = stdScaler_many.transform_many(X_train)

X_train.head()
print(type(X_train), type(y_train))
optimizers = [optim.SGD(0.01), optim.RMSProp(), optim.AdaGrad()]

hedge = DistAggregateRegressor(estimators=[linear_model.LinearRegression(optimizer=o, intercept_lr=.1)
                                         for o in optimizers],
                             learning_rate=0.005)

for xi, yi in stream.iter_array(X_train.to_numpy(), y_train.to_numpy(), feature_names=list(X_train.columns)):
    xi = np.array([np.fromiter(xi.values(), dtype=float)])
    yi = np.array([yi])
    start = time.time()
    hedge.partial_fit(xi,yi) 
    # hedge.partial_fit(x, yi)

print("duration =", time.time() - start, "\nresult = ", sum)


for i in range(2):    
    for xi, yi in stream.iter_array(X_train.to_numpy(), y_train.to_numpy(), feature_names=list(X_train.columns)):
        xi = np.array([np.fromiter(xi.values(), dtype=float)])
        yi = np.array([yi])
        start = time.time()
        hedge.partial_fit(xi,yi) 
        # hedge.partial_fit(x, yi)

print("duration =", time.time() - start, "\nresult = ", sum)



x = X_test
x = stdScaler_many.transform_many(x)
start = time.time()
ypred_hedge = hedge.predict(x)
print("duration =", time.time() - start, "\nresult = ", sum)

mse = mean_squared_error(y_test, ypred_hedge)
print("MSE_hedge: ", mse)
print("RMSE_hedge: ", mse**(1/2.0))





x_ax = range(len(y_test))
plt.plot(x_ax, y_test, label="original")
plt.plot(x_ax, ypred_hedge, label="pred_hedge")
# plt.plot(x_ax, ypred_one, label="pred_one")
# plt.plot(x_ax, ypred_many, label="pred_many")
# plt.plot(x_ax, ypred_sk, label="pred_sk")
plt.title("Boston test and predicted data")
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend(loc='best',fancybox=True, shadow=True)
plt.grid(True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12591183000317158, 'fraction_numerical': 0.00507453219156359, 'mean_word_length': 4.939736346516008, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '238468', 'license': 'MIT', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1118, 'n_words': 223, 'path': 'notebooks/simple_regression.ipynb', 'repo_name': 'MORE-EU/sail', 'size': '3153'}