import pandas as pd
import matplotlib.pyplot as plt
from sklearn.neural_network import MLPRegressor
df = pd.read_csv("0.5-1.csv")
df.head()
X = df[['wavelength', 'phase velocity']]
y = df['shear wave velocity']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2)
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import mean_absolute_error
mlp = MLPRegressor(hidden_layer_sizes=(30,30,30))
mlp.fit(X_train,y_train)
答案 0 :(得分:1)
如果希望获得可重复的结果,则可以通过train_test_split
固定随机种子,以便在每次运行中使用相同的训练/测试样本。如果使用train_test_split
的好处是不用费劲就可以轻松地选择训练/测试分段。
但是,如果您坚持要像您所说的那样手动选择训练/测试分组,则可以这样操作:
X_test, y_test = X[:20], y[:20] # first 20 samples for test
X_train, y_train = X[20:], y[20:] # rest of samples for train
答案 1 :(得分:0)
将numpy的随机种子固定为48或其他值
np.random.seed(48)
这将每次生成相同的拆分。并使用testsize固定拆分的大小