zoukankan      html  css  js  c++  java
  • TensorFlow生成三色线性训练集

    Python生成三色训练集(可直接使用)

     1 import numpy as np
     2 import tensorflow as tf
     3 import matplotlib.pyplot as plt
     4 
     5 # 总训练数量
     6 batchSize=100
     7 # 单个训练集数量
     8 eachBatchSize = 10
     9 
    10 # Red points
    11 redPointsX = np.random.normal(loc=2.0, scale=1.5, size=batchSize)
    12 print("redX=", redPointsX)
    13 redPointsY = np.random.normal(loc=2.0, scale=1.0, size=batchSize)
    14 print("redY=", redPointsY)
    15 
    16 '''
    17 numpy中reshape函数的三种常见相关用法
    18 reshape(1,-1)转化成1行:
    19 reshape(2,-1)转换成两行:
    20 reshape(-1,1)转换成1列: 
    21 reshape(-1,2)转化成两列
    22 '''
    23 redP = np.concatenate(([redPointsX], [redPointsY]), 0)
    24 print("red=", redP)
    25 print("redPxEachBatch=", redP[0, 1:eachBatchSize], "redPyEachBatch=", redP[1, 1:eachBatchSize])
    26 
    27 # Blue Points
    28 bluePointsX = np.random.normal(loc=5.0, scale=1.5, size=batchSize)
    29 print("blueX=", bluePointsX)
    30 bluePointsY = np.random.normal(loc=5.0, scale=2.3, size=batchSize)
    31 print("blueY=", bluePointsY)
    32 
    33 blueP = np.concatenate(([bluePointsX], [bluePointsY]), 0)
    34 print("blue=", blueP)
    35 print("bluePxEachBatch=", blueP[0, 1:eachBatchSize], "bluePyEachBatch=", blueP[1, 1:eachBatchSize])
    36 
    37 # Yellow points
    38 yellowPointsX = np.random.normal(loc=5.0, scale=1.2, size=batchSize)
    39 print("yellowX=", yellowPointsX)
    40 yellowPointsY = np.random.normal(loc=2.0, scale=1.6, size=batchSize)
    41 print("yellowY=", yellowPointsY)
    42 
    43 yellowP = np.concatenate(([yellowPointsX], [yellowPointsY]), 0)
    44 print("yellow=", yellowP)
    45 print("yellowPxEachBatch=", yellowP[0, 1:eachBatchSize], "yellowPyEachBatch=", yellowP[1, 1:eachBatchSize])
    46 
    47 # one-hot编码
    48 X0 = np.concatenate(([redPointsX], [bluePointsX], [yellowPointsX]), 0)
    49 Y0 = np.concatenate(([redPointsX], [bluePointsY], [yellowPointsY]), 0)
    50 oneHotIndex = np.concatenate((np.zeros((1, len(redPointsX))), np.zeros((1, len(bluePointsX))),
    51                               np.zeros((1, len(yellowPointsX)))), 1)
    52 print("oneHotIndex=", oneHotIndex)
    53 
    54 plt.figure(1)
    55 plt.scatter(redP[0, :], redP[1, :], c='red')
    56 plt.scatter(blueP[0, :], blueP[1, :], c='blue')
    57 plt.scatter(yellowP[0, :], yellowP[1, :], c='yellow')
    58 plt.title('Exercise Set')
    59 plt.show()
  • 相关阅读:
    一个男人该有的气质
    有没有想过,也许一辈子你都是个小人物
    System.IO.File.WriteAllText("log.txt", "dddd");
    cn_windows_10_enterprise_version_1703_updated_june_2017_x64_dvd_10720588.iso
    Visual Studio 2015 update 3各版本下载地址
    优麒麟 16.04 LTS(长期支持)版本
    干货!最全羽毛球技术动态分解gif图
    添加缓存 绝对时间过期
    C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑
    无法解析依赖项。“Microsoft.Net.Http 2.2.29”与 'Microsoft.Net.Http.zh-Hans
  • 原文地址:https://www.cnblogs.com/Yi-920259020/p/12668773.html
Copyright © 2011-2022 走看看