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] 这种高维稀疏类型,如何计算分类准确率? 分类 ...
随机推荐
- 12、rpm
1.什么是rpm 由红帽开发用于软件包的安装 升级 卸载 查询 2.rpm包是什么样? 组成部分是什么样的? zip-3.0-11.el7.x86_64.rpm #el7 zip-3.0-1. el6 ...
- DEC-UPDATE
12/19-12/26 # -*- coding: utf-8 -*- import sys ans = [1,2,3,4,5,6] def operate(fun): a = ans[0] b = ...
- Windows KMS激活脚本
@echo off&setlocal EnableDelayedExpansion&color 3etitle Windows KMS激活脚本 --by David :: 如果激活失败 ...
- 使用ajax上传图片,并且使用canvas实现出上传进度效果
前端代码: <%@ page contentType="text/html;charset=UTF-8" language="java" %> &l ...
- LVS+Heartbeat安装部署文档
LVS+Heartbeat安装部署文档 发表回复 所需软件: ipvsadm-1.24-10.x86_64.rpmheartbeat-2.1.3-3.el5.centos.x86_64.rpmhear ...
- thinkphp5.11 关于数据库连接的配置
config.php <?php// +----------------------------------------------------------------------// | Th ...
- Redis——认识
Redis和Memcached比较: https://www.cnblogs.com/JavaBlackHole/p/7726195.html https://blog.csdn.net/lch_20 ...
- 闰年计算——JavaScript 语言计算
㈠闰年是如何来的? 闰年(Leap Year)是为了弥补因人为历法规定造成的年度天数与地球实际公转周期的时间差而设立的.补上时间差的年份为闰年. ㈡什么是闰年? 凡阳历中有闰日(二月为二十九日)的年, ...
- java文件断点续传上传下载解决方案
这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数 下面直接贴代码吧,一些难懂的我大部分都加上注释了: 上传文件实体类: 看得 ...
- System limit for number of file watchers reached
https://blog.csdn.net/weixin_43760383/article/details/84326032 sudo xed /etc/sysctl.conf 在最下添加 fs.in ...