Iris Classification on Keras
Iris Classification on Keras
Installation
Python3 版本为 3.6.4 : : Anaconda
conda install tensorflow==1.15.0
conda install keras==2.1.6
Code
# encoding:utf8
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.utils import to_categorical
if __name__ == '__main__':
iris = load_iris()
x_train, x_test, y_train, y_test = train_test_split(
iris.data,
iris.target,
test_size=0.2,
random_state=20)
model = Sequential([
Dense(8, input_dim=4),
Activation('sigmoid'),
Dense(8),
Activation('relu'),
Dense(3),
Activation('softmax')
])
model.compile(
optimizer='Adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
model.fit(x_train, to_categorical(y_train, num_classes=3), epochs=70)
y_pred = model.predict_classes(x_test)
print(classification_report(y_test, y_pred, target_names=iris.target_names))
Errors
Traceback (most recent call last):
File ".../Iris.py", line 32, in <module>
y_pred = model.predict(x_train)
File "...\Miniconda3\envs\tf\lib\site-packages\keras\engine\training.py", line 1169, in predict
steps=steps)
File "...\Miniconda3\envs\tf\lib\site-packages\keras\engine\training_arrays.py", line 300, in predict_loop
outs.append(np.zeros(shape, dtype=batch_out.dtype))
TypeError: data type not understood
Solution: 重新配置环境,重新安装 keras, Tensorflow 等。
conda env list # look up
conda remove -n [env name] --all # delete
Iris Classification on Keras的更多相关文章
- Iris Classification on Tensorflow
Iris Classification on Tensorflow Neural Network formula derivation \[ \begin{align} a & = x \cd ...
- IMDB Classification on Keras
IMDB Classification on Keras In the book of Deep Learning with Python, there is an example of IMDB m ...
- Iris Classification on PyTorch
Iris Classification on PyTorch code # -*- coding:utf8 -*- from sklearn.datasets import load_iris fro ...
- keras系列︱Sequential与Model模型、keras基本结构功能(一)
引自:http://blog.csdn.net/sinat_26917383/article/details/72857454 中文文档:http://keras-cn.readthedocs.io/ ...
- Multi-label && Multi-label classification
Multi-label classification with Keras In today’s blog post you learned how to perform multi-label cl ...
- Keras 时序模型
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Thinking_boy1992/article/details/53207177 本文翻译自 时序模 ...
- Keras 多层感知机 多类别的 softmax 分类模型代码
Multilayer Perceptron (MLP) for multi-class softmax classification: from keras.models import Sequent ...
- 开始 Keras 序列模型(Sequential model)
开始 Keras 序列模型(Sequential model) 序列模型是一个线性的层次堆栈. 你可以通过传递一系列 layer 实例给构造器来创建一个序列模型. The Sequential mod ...
- keras multi-label classification 多标签分类
问题:一个数据又多个标签,一个样本数据多个类别中的某几类:比如一个病人的数据有多个疾病,一个文本有多种题材,所以标签就是: [1,0,0,0,1,0,1] 这种高维稀疏类型,如何计算分类准确率? 分类 ...
随机推荐
- java多线程ExecutorService
1.new Thread的弊端 执行一个异步任务你还只是如下new Thread吗? new Thread(new Runnable() { @Override public void run() { ...
- DockerScan:Docker安全分析&测试工具
DockerScan:Docker安全分析&测试工具 今天给大家介绍的是一款名叫DockerScan的工具,我们可以用它来对Docker进行安全分析或者安全测试. 项目主页 http://gi ...
- 格式化json扩展
json-handle 直接在chrome应用商店搜索JSON-handle或者去github搜索可用插件即可
- h5转pb的两个坑
1.需要加上如下设置,否则转换前后输出可能不一致,这个主要针对dropout.BN层训练测试不一致 from keras import backend as K K.set_learning_phas ...
- cyopen注释掉导入的动态函数
cyopen注释掉导入的动态函数 cyopen注释掉导入的动态函数 cyopen注释掉导入的动态函数
- ora 12518监听程序无法分发客户机连接
首先修改ORACLE的PROCESS.SESSION数量 查看当前ORALCE PROCESS数量 SQL> show parameter process 查看当前ORALCE SESSION数 ...
- Kubernetes 编排神器之 Helm
什么是Kubernetes Helm?为什么要使用Helm? 前言 编写一堆Kubernetes配置文件是一件很麻烦的事情.对于一些容器,我们可能需要10多个yaml文件.维护它们是一个问题,而且在不 ...
- mongdb的优势和不足
l 面向文档的数据库. l 一个介于关系型数据库和非关系型数据库之间的产品,是非关系系数据库中功能最丰富,最像关系型数据库的. l 特征是模式自由,schema-free.无需定义表结构. l ...
- 如何在某些情况下禁止提交Select下拉框中的默认值或者第一个值(默认选中的就是第一个值啦……)
群里有个帅哥问了这么个问题,他的下拉框刚进页面时是隐藏起来的,但是是有值的,为啥呢?因为下拉框默认选中了第一个值呗,,, 所以提交数据的时候就尴尬啦,明明没有选,但是还是有值滴.怎么办呢? 一开始看到 ...
- electron 设置-webkit-app-region: drag 后, 双击放大窗口变形
双击放大后窗口只是在最左上角,并没有放大, 或者放大了页面变形,如图 原因: 是设置了窗口 transparent: true,和背景色导致的, 不要设置就可以,默认为false mainWindow ...