weixin_41782739
2021-09-18 19:24
采纳率: 0%
浏览 142

AttributeError: 'Sequential' object has no attribute 'predict_classes' ,sequential 构建的模型

采用sequential 构建的模型(注意不是keras.model构建的模型),为什么会不存在 predict_classes().同样的代码在别人电脑却可以运行,keras版本不同?还是什么情况

img

import numpy as np
import pandas as pd
import sklearn
import keras
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense,Activation
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

data = pd.read_csv("c1/task1_data.csv")
data.head()
x = data.drop(['y'],axis=1)
y = data.loc[:,'y']
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=0)

#创建模型
mlp = Sequential()
mlp.add(Dense(units=25,input_dim=2,activation="sigmoid"))
mlp.add(Dense(units=1,activation='sigmoid'))
mlp.summary()
#配置模型
mlp.compile(optimizer='adam',loss='binary_crossentropy')
#训练模型
mlp.fit(x_train,y_train,epochs=1000)

#预测
y_train_predict = mlp.predict_classes(x_train)

  • 收藏

1条回答 默认 最新

相关推荐 更多相似问题