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. Spring整合Hessian访问远程服务

    声明:该文章转载自Spring整合Hessian访问远程服务,本人搬过来只是为了记录下学习Hessian的过程,忘此博主理解,在此感谢,等本人有能力了再学一些原创的东东,本人实践了下,hessianS ...

  2. docker 入门(2)

    1,多容器环境 运行docker容器 进入容器并查看该容器的IP exit退出容器 运行超小的linux的docker镜像alpine 可以看到如果没有提前把镜像pull到本地,直接run的话,它会自 ...

  3. 给Tomcat打开远程debug端口

    >cd apache-tomcat-8.5.24 >cd conf >vim catalina.sh 在文件开始处添加: CATALINA_OPTS="-server -X ...

  4. osworkflow 入门基础

    OSWorkFlow入门指南目的 这篇指导资料的目的是介绍OSWorkflow的所有概念,指导你如何使用它,并且保证你逐步理解OSWorkflow的关键内容. 本指导资料假定你已经部署OSWorkfl ...

  5. glViewport函数用法

    一. 其函数原型为glViewport(GLint x,GLint y,GLsizei width,GLsizei height) x,y 以像素为单位,指定了窗口的左下角位置. width,heig ...

  6. WebView net::ERR_CLEARTEXT_NOT_PERMITTED&&net::ERR_INTERNET_DISCONNECTED

    参照博客:https://blog.csdn.net/qq_33721320/article/details/84400825 测试Android 中WebView功能时,发现了这个问题: 解决的方式 ...

  7. k8s master节点添加kubectl的使用

  8. 关于Mongodb的Cap理论的思考(转载)

    大约在五六年前,第一次接触到了当时已经是hot topic的NoSql.不过那个时候学的用的都是mysql,Nosql对于我而言还是新事物,并没有真正使用,只是不明觉厉.但是印象深刻的是这么一张图片( ...

  9. 更优雅地关闭资源 - try-with-resource

    https://www.cnblogs.com/hihtml5/p/6505317.html

  10. IPC 进程间通信方式——管道

    进程间通信概述 数据传输:一个进程需要将它的数据发送给另一个进程,发送的数据量在一个字节到几兆字节之间 共享数据:多个进程想要操作共享数据,一个进程对共享数据的修改,别的进程应该立刻看到. 通知时间: ...