Day22 参加职训(机器学习与资料分析工程师培训班),Python程序设计

今天教学os模组

import os
filename = 'text.txt'
if os.path.exists(filename):
    os.remove(filename)
    print(f'{filename} 已经存在')
else:
    print(f'{filename} 不存在')
directory = 'OSexample'
# 如没有资料夹则建立
if not os.path.exists(directory):
    os.mkdir(directory)
else:
    print(f'{directory} 已存在')

    
# 如有此资料夹则删除    
if os.path.exists(directory):
    os.rmdir(directory)  
os.path.abspath('.') # 回传目前工作目录的绝对路径
os.path.abspath('..') # 回传目前工作目录上一层目录的绝对路径
os.path.dirname('课堂练习.ipynb')  #回传 '' →代表该档案在当前目录
os.path.getsize('/Users/aheat/Downloads/模型.txt') #取得档案大小(bytes)
os.path.isfile('课堂练习.ipynb')  # 确认是否为档案而非目录
os.path.join() # 连接成新的路径

後半段开始讲深度学习的一些概念,也教大家安装Tensorflow以及练习使用套件

Step1 :准备训练所需的资料

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import numpy as np
x_train = np.array([[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]])
y_train = np.array([[1,0],[0,1],[0,1],[1,0],[0,1],[1,0],[1,0],[0,1]])

Step2 : 建构类神经网路

model = Sequential()

model.add(Dense(10, activation='relu', input_dim=3))
model.add(Dense(4, activation='relu'))
model.add(Dense(2, activation='sigmoid'))

Step3 : 编译模型

model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics='accuracy')

Step4 : 训练模型

model.fit(x_train, y_train, epochs=3000, batch_size=3)

Step5 : 测试模型

x_test = np.array([[0,0,0]])
x_test.shape

y_test = np.array([[0,1]])
predict = model.predict(x_test)

test_loss, test_accuracy = model.evaluate(x_test, y_test)
print(f'Loss = {test_loss}, Accuracy = {test_accuracy}')

<<:  Nutanix NCSC-Level-1 Dumps PDF with Actual NCSC-Level-1 Exam Questions

>>:  Best iPhone Apps - To Create Contact Groups You Will Need an Additional App

Day04 UIKit 03 - SceneDelegate

SceneDelegate 从 iOS 13 开始,SceneDelegate 承担了 AppDel...

[Day23]C# 鸡础观念- 物件导向(oop)~属性(Property)

每天都在思考, 如果事情自己会做好就好了, 程序自己会自动检查就好了, 今天C#也有自动检查变数是否...

Visual studio 2019 使用AddressSanitizer检查程序码

AddressSanitizer (ASan) 是一种编译器和执行时间技术,会以 零 误报来公开许多...

[Day28] 介绍 CRUD

哈6夥伴们,这一路下来说明了一些简单的API,不知道夥伴们有没有发现,其实有些函式是常常使用的呢~~...

[Day18]ISO 27001 附录 A.6 资讯安全之组织

A.6 资讯安全之组织 A.6.1 内部组织 A.6.1.1 资讯安全之角色及责任 应定义及配置所有...