基于机器学习的临床决策支持-ANN

举报
DrugAI 发表于 2021/07/15 06:10:59 2021/07/15
【摘要】 声明:本文示例来自于GitHub用户vkasojhaa的项目,一切权利归其所有,此处仅是自己学习分享。 实现了基于机器学习的乳腺癌的恶性和良性预测,比较了不同机器学习算法之间的性能。主要目的是评估在每种算法的准确性和效率方面对数据进行分类的正确性。 loss # 损失值:预估值与实际值之间的均方差 optimizer # 优化器 trainer = ...

声明:本文示例来自于GitHub用户vkasojhaa的项目,一切权利归其所有,此处仅是自己学习分享。


实现了基于机器学习的乳腺癌的恶性和良性预测,比较了不同机器学习算法之间的性能。主要目的是评估在每种算法的准确性和效率方面对数据进行分类的正确性。


loss

# 损失值:预估值与实际值之间的均方差

optimizer

# 优化器

trainer = optimizer.minimize(loss)

# 训练:最小化损失函数

基于机器学习(ANN)的乳腺癌预测

代码示例


   
  1. #导入依赖库
  2. #!/usr/bin/python3
  3. from __future__ import print_function
  4. import keras
  5. from keras.datasets import mnist
  6. from keras.models import Sequential
  7. from keras.layers import Dense, Dropout, Flatten
  8. from keras.layers import Conv2D, MaxPooling2D
  9. from keras import backend as K
  10. import numpy as np
  11. import pandas as pd
  12. from matplotlib import pyplot as plt
  13. from IPython.display import clear_output
  14. from keras.utils import plot_model

   
  1. #载入数据并进行数据预处理
  2. data = pd.read_csv("data.csv")
  3. data.head()
  4. data.drop('id',axis=1,inplace=True)
  5. data.drop('Unnamed: 32',axis=1,inplace=True)
  6. data['diagnosis'] = data['diagnosis'].map({'M':1,'B':0})
  7. data.head()

print("Row, Col", data.shape)# (row,col)

  
(data['diagnosis'][:398]==1).sum(),(data['diagnosis'][:398]==0).sum()

  
(data['diagnosis'][398:]==1).sum(),(data['diagnosis'][398:]==0).sum()

  

   
  1. mat=data.as_matrix()
  2. mat.shape
  3. mat

模型训练:


   
  1. #Using 2 Sigmoid Layers and RMSprop optimizer
  2. model2 = Sequential()
  3. model2.add(Dense(500, activation='sigmoid', use_bias=True, input_shape=(30,)))
  4. model2.add(Dense(1, activation='sigmoid'))
  5. keras.optimizers.RMSprop(lr=0.01, rho=0.9, epsilon=None, decay=0.0)
  6. model2.compile(optimizer='rmsprop',loss='binary_crossentropy', metrics=['accuracy'])
  7. history01 = model2.fit(mat[:,1:],mat[:,0], validation_split=0.3,shuffle=False,epochs=3000, batch_size=128,verbose=0)

   
  1. score = model2.evaluate(mat[:398,1:],mat[:398,0], verbose=0, batch_size=128)
  2. print('Train loss:', score[0])
  3. print('Train accuracy:', score[1])

   
  1. Train loss: 0.00821199454791287
  2. Train accuracy: 1.0

   
  1. score = model2.evaluate(mat[398:,1:],mat[398:,0], verbose=0, batch_size=128)
  2. print('Validation loss:', score[0])
  3. print('Validation accuracy:', score[1])

   
  1. Validation loss: 0.1262894694568121
  2. Validation accuracy: 0.9473684154755888

   
  1. plt.plot(history01.history['acc'], label='acc')
  2. plt.plot(history01.history['val_acc'], label='val_acc')
  3. plt.legend()
  4. plt.show()
  5. plt.plot(history01.history['loss'], label='loss')
  6. plt.plot(history01.history['val_loss'], label='val_loss')
  7. plt.legend()
  8. plt.show()
  9. count=0
  10. for i in history01.history['acc']:
  11.    if i>0.99:
  12.        count+=1
  13. print(count)


   
  1. #Using 3 Sigmoid Layers and RMSprop optimizer
  2. model3 = Sequential()
  3. model3.add(Dense(500, activation='sigmoid', use_bias=True, input_shape=(30,)))
  4. model3.add(Dense(500, activation='sigmoid', use_bias=True))
  5. model3.add(Dense(1, activation='sigmoid'))
  6. keras.optimizers.RMSprop(lr=0.01, rho=0.9, epsilon=None, decay=0.0)
  7. model3.compile(optimizer='rmsprop',
  8.              loss='binary_crossentropy',
  9.              metrics=['accuracy'])
  10. history0 = model3.fit(mat[:,1:],mat[:,0], validation_split=0.3,shuffle=False,epochs=3000, batch_size=128, verbose=0)

   
  1. score2 = model3.evaluate(mat[:398,1:],mat[:398,0], verbose=0, batch_size=128)
  2. print('Train loss:', score2[0])
  3. print('Train accuracy:', score2[1])

   
  1. Train loss: 0.011901359889894986
  2. Train accuracy: 0.992462311557789

   
  1. score2 = model3.evaluate(mat[398:,1:],mat[398:,0], verbose=0, batch_size=128)
  2. print('Validation loss:', score2[0])
  3. print('Validation accuracy:', score2[1])

   
  1. Validation loss: 0.0804629116945448
  2. Validation accuracy: 0.9707602311296073

   
  1. plt.plot(history0.history['acc'], label='acc')
  2. plt.plot(history0.history['val_acc'], label='val_acc')
  3. plt.legend()
  4. plt.show()
  5. plt.plot(history0.history['loss'], label='loss')
  6. plt.plot(history0.history['val_loss'], label='val_loss')
  7. plt.legend()
  8. plt.show()
  9. count=0
  10. for i in history0.history['acc']:
  11.    if i>0.99:
  12.        count+=1
  13. print(count)


   
  1. #Using 3 Sigmoid Layers and RMSprop optimizer
  2. model3 = Sequential()
  3. model3.add(Dense(500, activation='sigmoid', use_bias=True, input_shape=(30,)))
  4. model3.add(Dense(500, activation='sigmoid', use_bias=True))
  5. model3.add(Dense(1, activation='sigmoid'))
  6. keras.optimizers.RMSprop(lr=0.01, rho=0.9, epsilon=None, decay=0.0)
  7. model3.compile(optimizer='rmsprop',
  8.              loss='binary_crossentropy',
  9.              metrics=['accuracy'])
  10. history0 = model3.fit(mat[:,1:],mat[:,0], validation_split=0.3,shuffle=False,epochs=3000, batch_size=128, verbose=0)
  11. score2 = model3.evaluate(mat[:398,1:],mat[:398,0], verbose=0, batch_size=128)
  12. print('Train loss:', score2[0])
  13. print('Train accuracy:', score2[1])

   
  1. Validation loss: 0.0804629116945448
  2. Validation accuracy: 0.9707602311296073

   
  1. plt.plot(history0.history['acc'], label='acc')
  2. plt.plot(history0.history['val_acc'], label='val_acc')
  3. plt.legend()
  4. plt.show()
  5. plt.plot(history0.history['loss'], label='loss')
  6. plt.plot(history0.history['val_loss'], label='val_loss')
  7. plt.legend()
  8. plt.show()
  9. count=0
  10. for i in history0.history['acc']:
  11.    if i>0.99:
  12.        count+=1
  13. print(count)


   
  1. #Using 4 Sigmoid Layers and RMSprop optimizer
  2. model4 = Sequential()
  3. model4.add(Dense(500, activation='sigmoid', use_bias=True, input_shape=(30,)))
  4. model4.add(Dense(500, activation='sigmoid', use_bias=True))
  5. model4.add(Dense(500, activation='sigmoid', use_bias=True))
  6. model4.add(Dense(1, activation='sigmoid'))
  7. keras.optimizers.RMSprop(lr=0.01, rho=0.9, epsilon=None, decay=0.0)
  8. model4.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy'])
  9. history1 = model4.fit(mat[:,1:],mat[:,0], validation_split=0.3,shuffle=False,epochs=3000, batch_size=128, verbose=0)
  10. #model.evaluate(mat[:,1:],mat[:,0], batch_size=None, verbose=1, sample_weight=None, steps=None)
  11. score = model4.evaluate(mat[:398,1:],mat[:398,0], verbose=0, batch_size=128)
  12. print('Train loss:', score[0])
  13. print('Train accuracy:', score[1])

   
  1. Train loss: 0.1454299822000403
  2. Train accuracy: 0.9346733668341709

   
  1. score = model4.evaluate(mat[398:,1:],mat[398:,0], verbose=0, batch_size=128)
  2. print('Validation loss:', score[0])
  3. print('Validation accuracy:', score[1])

   
  1. Validation loss: 0.33671002412400053
  2. Validation accuracy: 0.8830409339296887

   
  1. plt.plot(history1.history['acc'], label='acc')
  2. plt.plot(history1.history['val_acc'], label='val_acc')
  3. plt.legend()
  4. plt.show()
  5. plt.plot(history1.history['loss'], label='loss')
  6. plt.plot(history1.history['val_loss'], label='val_loss')
  7. plt.legend()
  8. plt.show()
  9. count=0
  10. for i in history1.history['acc']:
  11.    if i>0.99:
  12.        count+=1
  13. print(count)


Connecting artificial intelligence (AI) with pharmaceutical sciences.


参考资料:

https://github.com/vkasojhaa/Clinical-Decision-Support-using-Machine-Learning

文章来源: drugai.blog.csdn.net,作者:DrugAI,版权归原作者所有,如需转载,请联系作者。

原文链接:drugai.blog.csdn.net/article/details/105683686

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。