При печати кривой ROC с несколькими моделями я столкнулся с этой конкретной ошибкой. Нужна помощь
from tensorflow.keras.models import load_model
def dense():
return (load_model('DenseNet201.h5'))
def mobile():
return(load_model('MobileNet.h5'))
def res():
return(load_model('ResNet50V2.h5'))
def vgg():
return(load_model('VGG16.h5'))
models = [
{
'label': 'DenseNet201',
'model': dense(),
},
{
'label': 'MobileNet',
'model':mobile(),
},
{
'label': 'ResNet50V2',
'model':res(),
},
{
'label': 'VGG16',
'model':vgg(),
}]
from sklearn import metrics
import matplotlib.pyplot as plt
from tensorflow.keras.utils import to_categorical
plt.figure()
# Below for loop iterates through your models list
for m in models:
model = m['model'] # select the model
#model.fit(X_train, y_train) # train the model
y_pred=model.predict(X_test) # predict the test data
# Compute False postive rate, and True positive rate
#fpr, tpr, thresholds = metrics.roc_curve(y_test, model.y_pred_bin(X_test)[:,1])
fpr, tpr, thresholds = metrics.roc_curve(y_test, model.predict_proba(X_test)[:,1])
# Calculate Area under the curve to display on the plot
auc = metrics.roc_auc_score(y_test,model.predict(X_test))
# Now, plot the computed values
plt.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % (m['label'], auc))
# Custom settings for the plot
plt.plot([0, 1], [0, 1],'r--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('1-Specificity(False Positive Rate)')
plt.ylabel('Sensitivity(True Positive Rate)')
plt.title('Receiver Operating Characteristic')
plt.legend(loc="lower right")
plt.show() # Display
Я загрузил свои предварительно обученные модели в функцию и вернул их с помощью этого кода. Я составил список, который будет повторяться и вызывать функцию, которая загрузила эти модели, и, следовательно, будет построена кривая ROC для каждой модели.
Full TraceBack
> AttributeError Traceback (most recent call
> last) in ()
> 11 # Compute False postive rate, and True positive rate
> 12 #fpr, tpr, thresholds = metrics.roc_curve(y_test, model.y_pred_bin(X_test)[:,1])
> ---> 13 pred_prob = model.predict_proba(X_test)
> 14 fpr, tpr, thresholds = metrics.roc_curve(y_test, pred_prob[:,1])
> 15 # Calculate Area under the curve to display on the plot
>
> AttributeError: 'Functional' object has no attribute 'predict_proba'
AttributeError: «Функциональный» объект не имеет атрибута «predict_proba». ⇐ Python
Программы на Python
1774634720
Anonymous
При печати кривой ROC с несколькими моделями я столкнулся с этой конкретной ошибкой. Нужна помощь
from tensorflow.keras.models import load_model
def dense():
return (load_model('DenseNet201.h5'))
def mobile():
return(load_model('MobileNet.h5'))
def res():
return(load_model('ResNet50V2.h5'))
def vgg():
return(load_model('VGG16.h5'))
models = [
{
'label': 'DenseNet201',
'model': dense(),
},
{
'label': 'MobileNet',
'model':mobile(),
},
{
'label': 'ResNet50V2',
'model':res(),
},
{
'label': 'VGG16',
'model':vgg(),
}]
from sklearn import metrics
import matplotlib.pyplot as plt
from tensorflow.keras.utils import to_categorical
plt.figure()
# Below for loop iterates through your models list
for m in models:
model = m['model'] # select the model
#model.fit(X_train, y_train) # train the model
y_pred=model.predict(X_test) # predict the test data
# Compute False postive rate, and True positive rate
#fpr, tpr, thresholds = metrics.roc_curve(y_test, model.y_pred_bin(X_test)[:,1])
fpr, tpr, thresholds = metrics.roc_curve(y_test, model.predict_proba(X_test)[:,1])
# Calculate Area under the curve to display on the plot
auc = metrics.roc_auc_score(y_test,model.predict(X_test))
# Now, plot the computed values
plt.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % (m['label'], auc))
# Custom settings for the plot
plt.plot([0, 1], [0, 1],'r--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('1-Specificity(False Positive Rate)')
plt.ylabel('Sensitivity(True Positive Rate)')
plt.title('Receiver Operating Characteristic')
plt.legend(loc="lower right")
plt.show() # Display
Я загрузил свои предварительно обученные модели в функцию и вернул их с помощью этого кода. Я составил список, который будет повторяться и вызывать функцию, которая загрузила эти модели, и, следовательно, будет построена кривая ROC для каждой модели.
Full TraceBack
> AttributeError Traceback (most recent call
> last) in ()
> 11 # Compute False postive rate, and True positive rate
> 12 #fpr, tpr, thresholds = metrics.roc_curve(y_test, model.y_pred_bin(X_test)[:,1])
> ---> 13 pred_prob = model.predict_proba(X_test)
> 14 fpr, tpr, thresholds = metrics.roc_curve(y_test, pred_prob[:,1])
> 15 # Calculate Area under the curve to display on the plot
>
> AttributeError: 'Functional' object has no attribute 'predict_proba'
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия