def r_model(input_shape):
model = Sequential(name="likelihood")
model.add(InputLayer(input_shape=input_shape))
model.add(Dense(10, activation='relu'))
model.add(Dense(1))
opt = Adam(learning_rate=0.1)
model.compile(loss='mse', metrics=['mae'], optimizer=opt)
return model
numerical = ['Serial No.', 'GRE Score', 'TOEFL Score', 'University Rating', 'SOP', 'LOR ', 'CGPA', 'Research']
labels = df['Chance of Admit ']
features = df[numerical]
features_train, labels_train, features_test, labels_test = train_test_split(features, labels, test_size = 0.33, random_state = 42)
ct = ColumnTransformer([('standardize', StandardScaler(), numerical)], remainder='passthrough')
features_train = ct.fit_transform(features_train)
features_test = ct.transform(features_test)
这是错误:
Traceback (most recent call last):
File "script.py", line 36, in <module>
features_test = ct.transform(features_test)
File "/usr/local/lib/python3.6/dist-packages/sklearn/compose/_column_transformer.py", line 580, in transform
if self._n_features > X.shape[1]:
IndexError: tuple index out of range
我尝试了很多东西,无法弄清楚,它必须简单明了,请纠正我)
通常,当 ColumnTransformer 中指定的列数与数据集中的实际列数不匹配时,就会发生这种情况。
train_test_split
函数返回四个单独的变量:X_train, X_test, y_train, y_test = train_test_split(X,y ,
random_state=42,
test_size=0.25,
shuffle=True)
wrong order
,重新排列variables
features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size=0.33, random_state=42)