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] 这种高维稀疏类型,如何计算分类准确率? 分类 ...
随机推荐
- 使用ELK进行日志分析
0x01 前言: 前段时间做应急,总是需要溯源分析,痛点是数据量比较大,想要短时间能分析出来.再者就是之前在调查某酒店事件的时候特别羡慕某产商有各种分析溯源工具.反思过后,终于在没有那么忙的时候开始搭 ...
- 点击切换JS
$(function(){ var tabnav = $("#tab-nav ul li"); tabnav.click(function(){ $(this).addClass( ...
- Systemctl和service、chkconfig命令的关系
systemctl命令:是一个systemd工具,主要负责控制systemd系统和服务管理器. service命令:可以启动.停止.重新启动和关闭系统服务,还可以显示所有系统服务的当前状态. ch ...
- zabbix 邮件报警事件:Zabbix discoverer processes more than 75% busy
Problem has been resolved at :: on Problem name: Zabbix discoverer processes more than % busy Host: ...
- 【转载】Stanford CoreNLP Typed Dependencies
总结自Stanford typed dependencies manual 原文链接:http://www.jianshu.com/p/5c461cf096c4 依存关系描述句子中词与词之间的各种语法 ...
- mysql安装及加固
mysql安装 查看是否安装mysql 我们先看一下有没有安装mysql yum list installed mysql | grep mysql 本地只安装了php链接mysql的库,没有安装my ...
- dedecms织梦做中英文(多语言)网站步骤详解
用dedecms织梦程序如何做中英文网站,下面是一个详细的图文教程,希望能帮助到大家. 以下是用dedecms织梦程序制作过的一个5国语言网站,下面开始教程. 一.首先在后台建栏目,有三点需要注意 1 ...
- windows下遍历文件夹下的文件
#include <io.h>#include <stdio.h>#include <iostream>using namespace std;int ReadSt ...
- H5 2次重定向301
测试环境http ,生产https,导致请求重定向.加之H5自己的一次请求重定向,一共2次.
- centos后台运行程序
putty等软件运行,python程序:python p.py 只要一关闭putty, 程序就结束.如何让退出终端或关闭终端电脑,还能让程序在服务器后台运行Python. 关键的命令:nohup ...