import numpy as np
from math import sqrt
defr2_score(y_true, y_predict):"""计算y_true和y_predict之间的R Square"""return1- mean_squared_error(y_true, y_predict)/ np.var(y_true)
二、然后引入分割数据集的 model_selection 模块:
import numpy as np
deftrain_test_split(X, y, test_ratio=0.2, seed=None):"""将数据 X 和 y 按照test_ratio分割成X_train, X_test, y_train, y_test"""if seed:
np.random.seed(seed)
shuffled_indexes = np.random.permutation(len(X))
test_size =int(len