使用cnn预测房价

There are many transfer learning methods to solve classification problems with respect to the accuracy, i.e 1.VGG (e.g. VGG16 or VGG19) 2.GoogLeNet (e.g. InceptionV3).3.Residual Network (e.g. ResNet50).These are some pre-trained models, but here we are going to build an end to end model as per the convolutional neural networks architecture.

有很多转移学习方法可以解决关于准确性的分类问题,例如1.VGG(例如VGG16或VGG19)2.GoogLeNet(例如InceptionV3).3.Residual Network(例如ResNet50)。这些是一些预先训练的模型,但是在这里,我们将根据卷积神经网络架构来构建端到端模型。

卷积神经网络 (Convolutional Neural Network)

There are many definitions to describe CNN but in simple terms, convolutional refers to the mathematical combination of two functions to produce a third function. It merges two sets of information. in the case of a CNN is used to analyze visual imaginary. They are also known as shift invariant or space invariant artificial neural networks, based on their shared-weights architecture and translation invariance characteristics.

描述CNN的定义很多,但简单来说,卷积是指两个函数的数学组合以产生第三个函数。 它合并了两组信息。 在使用CNN的情况下,可以分析视觉虚像。 基于它们的共享权重架构和平移不变性特征,它们也被称为位移不变或空间不变的人工神经网络。

Source资源

CNN中的图层 (Layers in CNN)

There are three layers in CNN, convolutional layer, pooling layer, and fully connected layer. Each of these layers has different parameters that can be optimized and performs a different task on the input data.

CNN分为三层:卷积 ,池化和完全连接 。 这些层中的每个都有可以优化的不同参数,并且对输入数据执行不同的任务。

Source资源

池化层 (Pooling Layer)

The pooling layer is a building block on CNN. its function progressively reduces the spatial size of the presentation to reduce the number of parameters and computation in network. The pooling layer operates on each feature map independently. max-pooling is the most common approach used in the convolutional neural networks.

池化层是CNN的基础。 它的功能逐渐减小了演示文稿的空间大小,从而减少了网络中的参数和计算量。 池化层在每个要素地图上独立运行。 最大池化是卷积神经网络中最常用的方法。

数据集 (Dataset)

We have data for training:

我们有用于培训的数据:

500 horse images and 527 humans (male & Female) images

500张马图像和527位人类(男性和女性)图像

For Validation:

验证:

122 Horse Images and 123 Human(male & Female) images

122张马图像和123张人类(男性和女性)图像

Dataset link

数据集链接

实作 (Implementation)

Importing necessary libraries and packages.

导入必要的库和包。

import kerasfrom keras.preprocessing.image import ImageDataGeneratorimport matplotlib.pyplot as plt

资料载入 (Data Load)

train_data = "train/"validation_data = "validation/"

Here we have train and validation datasets, we will use train data for training and validation data to prevent overfitting problem. also here we have a small size of the dataset as we before building the CNN model the data should have huge images to make the most accurate model. so we will generate more images using image augmentation.

这里有训练和验证数据集,我们将训练数据用于训练和验证数据以防止过拟合问题。 同样,在这里,我们的数据集很小,因为在构建CNN模型之前,数据应该具有巨大的图像以构成最准确的模型。 因此我们将使用图像增强生成更多图像。

数据预处理 (Data Preprocessing)

#For tariningtrain_data_gen = ImageDataGenerator(rescale=1./255,                                   rotation_range=40,                                   width_shift_range=0.2,                                   height_shift_range=0.2,                                   shear_range=0.2,                                   zoom_range=0.2,                                   horizontal_flip=True,                                   fill_mode='nearest')

Generating more training data for model training using image data generator parameters like rotation and width, height, zoom range.

使用图像数据生成器参数(例如旋转和宽度,高度,缩放范围)为模型训练生成更多训练数据。

train_data1 = train_data_gen.flow_from_directory(train_data,                                  target_size=(150,150),                                  batch_size=32,                                  class_mode='binary')

Let’s Check the image classes

让我们检查一下图像类

train_data1.class_indices

The classes are divided as {‘horses’: 0, ‘humans’: 1}.

这些类别分为{'horses':0,'humans':1}。

Now Generating for validation.

现在生成以进行验证。

validation_data_gen = ImageDataGenerator(rescale=1./255)validation_data1 = validation_data_gen.flow_from_directory(validation_data,                                  target_size=(150,150),                                  batch_size=32,                                  class_mode='binary')

Now plotting the generated images.

现在绘制生成的图像。

def plotImages(images_arr):    fig, axes = plt.subplots(1, 5, figsize=(20, 20))    axes = axes.flatten()    for img, ax in zip(images_arr, axes):        ax.imshow(img)    plt.tight_layout()    plt.show()

Let’s plots some training image datasets.

让我们绘制一些训练图像数据集。

images = [train_data1[0][0][0] for i in range(5)]plotImages(images)
Augmented Image
增强图像

建立CNN (Building CNN)

We are using Keras here so it makes code much simpler form because it uses TensorFlow API. so let’s start to build a model step by step.

我们在这里使用Keras,因为它使用TensorFlow API,所以它使代码的形式更简单。 因此,让我们开始逐步构建模型。

cnn_model = keras.models.Sequential([    keras.layers.Conv2D(filters=32, kernel_size=3, input_shape=[150,150,3]),    keras.layers.MaxPooling2D(pool_size=(2,3)),    keras.layers.Conv2D(filters=64, kernel_size=3),    keras.layers.MaxPooling2D(pool_size=(2,2)),    keras.layers.Conv2D(filters=128, kernel_size=3),    keras.layers.MaxPooling2D(pool_size=(2,2)),    keras.layers.Conv2D(filters=256, kernel_size=3),    keras.layers.MaxPooling2D(pool_size=(2,2)),

    keras.layers.Dropout(0.5),    keras.layers.Flatten(), #after this we will go for neural network building    keras.layers.Dense(units=128, activation='relu'), #inputlayers    keras.layers.Dropout(0.1),    keras.layers.Dense(units=256, activation='relu'), #Hidden layer    keras.layers.Dropout(0.25),    keras.layers.Dense(units=2, activation='softmax') #output layer with 2 neurons

])

Basically we took 128 for input and 256 neurons for hidden, and we used relu and softmax activation functions, with respect to classes we used softmax activation function. Now let’s compile the model.

基本上,我们使用128个输入作为输入,使用256个神经元进行隐藏,并使用relu和softmax激活函数,就使用softmax激活函数的类而言。 现在让我们编译模型。

from keras.optimizers import Adamfrom keras.callbacks import ModelCheckpoint

Let’s set the optimizer and loss function now.

现在设置优化器和损失函数。

cnn_model.compile(optimizer=Adam(lr=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])

Before going to build a model we can set a path to save our model, so in my case, I have set my local systems path.

在构建模型之前,我们可以设置保存模型的路径,因此,就我而言,我已经设置了本地系统路径。

model_path='human_horse_predict.h5'checkpoint = ModelCheckpoint(model_path, monitor='val_accuracy', verbose=1, save_best_only=True, mode='max')callbacks_list = [checkpoint]

模型火车 (Model Train)

history = cnn_model.fit(train_data1,                       epochs=100,                       verbose=1,                       validation_data=validation_data1,                       callbacks=callbacks_list)

I have trained this model by using Cuda and it took less time for training, better you can train using Google COLAB.

我已经使用Cuda训练了该模型,并且花了更少的时间进行训练,更好的是可以使用Google COLAB进行训练。

Now the model is trained, let’s see the summary of the model.

现在已经对模型进行了训练,让我们看看模型的摘要。

#Summarize history for accuracyplt.plot(history.history['accuracy'])plt.plot(history.history['val_accuracy'])plt.title('Model Loss')plt.ylabel('accuracy')plt.xlabel('epoch')plt.legend(['train', 'test'], loc='upper left')plt.show()

Let’s look at our model accuracy on train and test data.

让我们看看我们在训练和测试数据上的模型准确性。

Plot情节

You can see how our model is overfitted as per epoch. Let’s test the model.

您可以看到我们的模型在每个时期都是过拟合的。 让我们测试一下模型。

模型测试 (Model Test)

model1 = keras.models.load_model(model_path)

Give the saved model path.

给出保存的模型路径。

Let’s take some human and horse images and assing in some variables.

让我们拍摄一些人和马的图像,并评估一些变量。

##Horse imagesh1 = 'train/horses/horse01-1.png'h2 = 'train/horses/horse01-2.png'h3 = 'train/horses/horse01-5.png'#human images hu1 = 'train/humans/human01-02.png'hu2 = 'train/humans/human01-05.png'hu3 = 'train/humans/human01-08.png

Creating one function which will prepress our image in an array format.

创建一个将以数组格式预印图像的功能。

import numpy as npfrom keras.preprocessing import image

Defining function.

定义功能。

def pred_human_horse(model, horse_or_human):    test_image = image.load_img(horse_or_human, target_size = (155,155))    test_image = image.img_to_array(test_image)/255    test_image = np.expand_dims(test_image, axis=0)

    result = model.predict(test_image).round(3)

    pred = np.argmax(result)

    if pred==0:        print("Horse")    else:        print("Human")

预测 (Prediction)

For using three images we are going to predict.

对于使用三个图像,我们将进行预测。

for horse_or_human in [h1,h2,h3]:    pred_human_horse(model1, horse_or_human)HorseHorseHorse

So, we got a good prediction here.

因此,我们在这里得到了很好的预测。

Hope you like this article, we can improve this model for using hyperparameter tuning and you can also try the pre-trained models likeVGG (e.g. VGG16 or VGG19).

希望您喜欢本文,我们可以改进此模型以使用超参数调整,还可以尝试使用预训练的模型,例如VGG(例如VGG16或VGG19)。

IPython notebook.

IPython 笔记本 。

Github Link for all machine learning and Deep Learning Resources, and you can also see my machine learning deployments using Flask API.

Github 链接提供了所有机器学习和深度学习资源,您还可以使用Flask API查看我的机器学习部署。

翻译自: https://towardsdatascience.com/human-and-horse-prediction-using-cnn-563309f988ff

使用cnn预测房价


http://www.taodudu.cc/news/show-863812.html

相关文章:

  • 利用colab保存模型_在Google Colab上训练您的机器学习模型中的“后门”
  • java 回归遍历_回归基础:代码遍历
  • sql 12天内的数据_想要在12周内成为数据科学家吗?
  • SorterBot-第1部分
  • 算法题指南书_分类算法指南
  • 小米 pegasus_使用Google的Pegasus库生成摘要
  • 数据集准备及数据预处理_1.准备数据集
  • ai模型_这就是AI的样子:用于回答问题的BiDAF模型
  • 正则化技术
  • 检测对抗样本_避免使用对抗性T恤进行检测
  • 大数据数据量估算_如何估算数据科学项目的数据收集成本
  • 为什么和平精英无响应_什么和为什么
  • 1. face_generate.py
  • cnn卷积神经网络应用_卷积神经网络(CNN):应用的核心概念
  • 使用mnist数据集_使用MNIST数据集上的t分布随机邻居嵌入(t-SNE)进行降维
  • python模型部署方法_终极开箱即用的自动化Python模型选择方法
  • 总体方差的充分统计量_R方是否衡量预测能力或统计充分性?
  • 多尺度视网膜图像增强_视网膜图像怪异的预测
  • 多元线性回归中多重共线性_多重共线性如何在线性回归中成为问题。
  • opencv 创建图像_非艺术家的图像创建(OpenCV项目演练)
  • 使用TensorFlow进行深度学习-第2部分
  • 基于bert的语义匹配_构建基于BERT的语义搜索系统…针对“星际迷航”
  • 一个数据包的旅程_如何学习数据科学并开始您的惊人旅程
  • jupyter 托管_如何在本地托管的Jupyter Notebook上进行协作
  • fitbit手表中文说明书_如何获取和分析Fitbit睡眠分数
  • 熔池 沉积_用于3D打印的AI(第2部分):异常熔池检测的一课学习
  • 机器学习 可视化_机器学习-可视化
  • 学习javascript_使用5行JavaScript进行机器学习
  • 强化学习-动态规划_强化学习-第4部分
  • 神经网络优化器的选择_神经网络:优化器选择的重要性

使用cnn预测房价_使用CNN的人和马预测相关推荐

  1. python 预测算法_通过机器学习的线性回归算法预测股票走势(用Python实现)

    本文转自博客园,作者为hsm_computer 原文链接:https://www.cnblogs.com/JavaArchitect/p/11717998.html在笔者的新书里,将通过股票案例讲述P ...

  2. 使用机器学习预测天气_使用机器学习的二手车价格预测

    使用机器学习预测天气 You can reach all Python scripts relative to this on my GitHub page. If you are intereste ...

  3. 分类预测回归预测_我们应该如何汇总分类预测?

    分类预测回归预测 If you are reading this, then you probably tried to predict who will survive the Titanic sh ...

  4. 时间序列预测方法_让我们使用经典方法预测您的时间序列

    时间序列预测方法 时间序列预测 (Time Series Forecasting) 背景 (Background) We learned various data preparation techni ...

  5. python交通流预测算法_基于机器学习的交通流预测技术的研究与应用

    摘要: 随着城市化进程的加快,交通系统的智能化迫在眉睫.作为智能交通系统的重要组成部分,短时交通流预测也得到了迅速的发展,而如何提升短时交通流预测的精度,保障智能交通系统的高效运行,一直是学者们研究的 ...

  6. python财务报表预测股票价格_建模股票价格数据并进行预测(统计信号模型):随机信号AR模型+Yule-Walker方程_Python...

    1.背景: 针对股票市场中AR 模型的识别.建立和估计问题,利用AR 模型算法对股票价格进行预测. 2.模型选取: 股票的价格可视为随机信号,将此随机信号建模为:一个白噪声通过LTI系统的输出,通过原 ...

  7. #时间预测算法_基于超级学习者机器学习算法预测ICU患者急性低血压发作

    点击"蓝字"关注,更多精彩内容! 背景 急性低血压发作(AHE),定义为平均动脉压下降至<65mmHg且至少持续5分钟,是重症监护病房(ICU)最严重的不良事件,往往导致重症 ...

  8. python预测糖尿病_使用决策树与随机深林预测糖尿病(python)

    (一)算法简介 决策树是一种树形结构,其中每一个内部节点表示在一个特征(属性)上的测试,每个分支代表一个测试输出,每个叶子节点代表一种类别. (二)代码实例 使用决策树预测糖尿病 参考引用于:贪心学院 ...

  9. python财务报表预测股票价格_基于 lstm 的股票收盘价预测 -- python

    开始导入 MinMaxScaler 时会报错 "from . import _arpack ImportError: DLL load failed: 找不到指定的程序." (把s ...

最新文章

  1. [源码和文档分享]基于java 的仿QQ聊天工具
  2. 【不容错过】12月10日:纳米孔测序科研团队大会NCM 2020亚太区特别专场
  3. 不借助vue-cli,自行构建一个vue项目
  4. 微软修复工具_微软正在推出更新以修复此前被发现的Windows 10 SFC问题
  5. C#不要再使用Npoi啦,使用MiniExcel操作Excel文件更快更高效!
  6. java ee是什么_死磕 java集合之HashSet源码分析
  7. json 示例_JSON文件 数据格式及格式化转换
  8. 《企业安全软件能否免费?》 ——百位中国CIO对免费企业级信息安全软件的态度调查报告...
  9. 家乡饮食文化PHP开题报告,挖掘家乡饮食文化拓展幼儿园课程
  10. asp.net常见数据类型
  11. win11wifi总掉线怎么办 windows11wifi总掉线的解决方法
  12. Java :反射详解
  13. 孙鑫VC学习笔记:第十五讲 (二) 线程创建方法
  14. 2阶实对称矩阵特征值和特征向量的简单求解方法
  15. Spring学习之浅析refresh()执行逻辑
  16. SLAM综述阅读笔记一:Past, Present, and Future of Simultaneous Localization And Mapping(2016)
  17. Windows和ubuntu下一些提升效率的工具知识点以及typora和Obsidian配置
  18. c语言调用子程序的例子,几个C语言编程应用实例.DOC
  19. 数位云Android SDK接入指南
  20. Typora自定义精美主题

热门文章

  1. 风口上的储能,光伏要飞起来?
  2. 博鳌直击 | 大数据开发的最大障碍是什么?
  3. CentOS6.5下用yum安装 git .
  4. Solr 搭建搜索服务器
  5. 关于java中的数组
  6. mysql差异备份实现_结合Git实现Mysql差异备份,可用于生产环境
  7. struts2文件上传中,如何限制上传的文件类型
  8. Ajax联手SOA打造企业级应用
  9. 下面哪项属于计算机在教育教学中的应用,东师现代教育技术18秋在线作业2答案...
  10. 下行文格式图片_帮你填平论文投稿格式修改这个大坑,一文了解三大出版社投稿要求...