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的更多相关文章

  1. Iris Classification on Tensorflow

    Iris Classification on Tensorflow Neural Network formula derivation \[ \begin{align} a & = x \cd ...

  2. IMDB Classification on Keras

    IMDB Classification on Keras In the book of Deep Learning with Python, there is an example of IMDB m ...

  3. Iris Classification on PyTorch

    Iris Classification on PyTorch code # -*- coding:utf8 -*- from sklearn.datasets import load_iris fro ...

  4. keras系列︱Sequential与Model模型、keras基本结构功能(一)

    引自:http://blog.csdn.net/sinat_26917383/article/details/72857454 中文文档:http://keras-cn.readthedocs.io/ ...

  5. Multi-label && Multi-label classification

    Multi-label classification with Keras In today’s blog post you learned how to perform multi-label cl ...

  6. Keras 时序模型

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Thinking_boy1992/article/details/53207177 本文翻译自 时序模 ...

  7. Keras 多层感知机 多类别的 softmax 分类模型代码

    Multilayer Perceptron (MLP) for multi-class softmax classification: from keras.models import Sequent ...

  8. 开始 Keras 序列模型(Sequential model)

    开始 Keras 序列模型(Sequential model) 序列模型是一个线性的层次堆栈. 你可以通过传递一系列 layer 实例给构造器来创建一个序列模型. The Sequential mod ...

  9. keras multi-label classification 多标签分类

    问题:一个数据又多个标签,一个样本数据多个类别中的某几类:比如一个病人的数据有多个疾病,一个文本有多种题材,所以标签就是: [1,0,0,0,1,0,1] 这种高维稀疏类型,如何计算分类准确率? 分类 ...

随机推荐

  1. java中的compareto方法的详细介绍

    java中的compareto方法的详细介绍 Java Comparator接口实例讲解(抽象方法.常用静态/默认方法) 一.java中的compareto方法 1.返回参与比较的前后两个字符串的as ...

  2. Nginx源码安装配置

    Nginx web服务器简介 Nginx ("engine x") 是一个高性能HTTP 和 反向代理 服务器.IMAP.POP3.SMTP 服务器. Nginx 是由 Igor ...

  3. java8学习之自定义收集器深度剖析与并行流陷阱

    自定义收集器深度剖析: 在上次[http://www.cnblogs.com/webor2006/p/8342427.html]中咱们自定义了一个收集器,这对如何使用收集器Collector是极有帮助 ...

  4. springboot+elasticsearch 报错

    错误1: .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsear ...

  5. inode、软硬链接

    关于inode是什么,可以看这篇文章:http://www.cnblogs.com/adforce/p/3522433.html 如何查看inode ll -di /boot / /app查看文件和文 ...

  6. C# 各个版本特性总结

    历史版本 C#作为微软2000年以后.NET平台开发的当家语言,发展至今具有17年的历史,语言本身具有丰富的特性,微软对其更新支持也十分支持.微软将C#提交给标准组织ECMA,C# 5.0目前是ECM ...

  7. 【洛谷P1450】硬币购物

    题目大意:给定 4 种面值的硬币和相应的个数,求购买 S 元商品的方案数是多少. 题解: 考虑没有硬币个数的限制的话,购买 S 元商品的方案数是多少,这个问题可以采用完全背包进行预处理. 再考虑容斥, ...

  8. mybatis 中 if-test 判断大坑

    [<if test="takeWay == '0'">]mybatis的if判断 单个的字符要写到双引号里面才行,改为<if test='takeWay == & ...

  9. vs2017 2019 下载更新慢的解决方法

    国庆期间 下载的速度只有20多kb. 1.去掉网络适配器里面的 ip6勾选. 2.修改电脑的自动dns, 修改为1.1.1.1  , 修改为8.8.8.8  更快. 记得禁用再启用网络: dns为1. ...

  10. 21.django中间件源码阅读

    回顾: 关于里面的源码流程大家可以全看视频,因为代码的跳动性很大,而且会多次调用通过一方法,所以关于中间源码的部分去找个视频看一看,我写的不是很清楚. # 1 cookie session # 2 f ...