当前位置:网站首页>Machine learning keras fitting sine function
Machine learning keras fitting sine function
2022-07-25 06:07:00 【==Microsoft==】
1.dataset
from random import random
import numpy as np
def f(x):
a = -1
b = 1
c = 1
return a * (x ** 2) + b * x + c
def g(x):
k = 1
b = 1
return k * x + b
def h(x):
return np.sin(x)
def get_data(num):
cnt = (np.random.random(100) - 0.5) * 20
cnt = np.sort(cnt)
X = cnt
Y = h(cnt)
return X, Y
if __name__ == '__main__':
X, Y = get_data(100)
print(X)
print(Y)
2.keras
from turtle import color
import matplotlib.pyplot as plt
import numpy as np
import get_data
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
X, Y = get_data.get_data(500)
model = Sequential()
# Number of neurons in the current layer :1 Activate function type :sigmoid Input data characteristic latitude :1
model.add(Dense(units=200, input_dim=1))
model.add(Dense(units=100))
model.add(Dense(units=100))
model.add(Dense(units=100, activation='sigmoid'))
# model.add(Dense(units=100, activation='sigmoid'))
# model.add(Dense(units=100, activation='sigmoid'))
# model.add(Dense(units=100, activation='sigmoid'))
# model.add(Dense(units=100, activation='sigmoid'))
# model.add(Dense(units=100, activation='sigmoid'))
# model.add(Dense(units=100, activation='sigmoid'))
model.add(Dense(units=1))
# Loss function ( Mean square error ) Optimizer (sgd: Stochastic gradient descent algorithm ) Evaluation criteria (accuracy: Accuracy )
model.compile(loss='mse', optimizer=SGD(lr=0.01), metrics=['accuracy'])
model.summary()
model.fit(X, Y, epochs=10000, batch_size=20)
pres = model.predict(X)
plt.scatter(X, Y)
plt.plot(X, pres, color='red')
plt.show()
边栏推荐
- 机器学习 Keras拟合正弦函数
- 【C语言】指针和数组的深入理解(第一期)
- The computer accesses the Internet normally with the same network cable, and the mobile phone connects to WiFi successfully, but it cannot access the Internet
- R language uses rowmedians function to calculate the row data median value of all data rows in dataframe
- Tutorial: encryption keys in cloud (using golang and CLI)
- Define usage method and template
- MFC IniFile Unicode mode reading method
- Analyzing the principle of DNS resolution in kubernetes cluster
- VBA common objects
- Date (day 76)
猜你喜欢

SAP FICO 第三节 BDC和LTMC导入S4财务科目

(Niuke multi school I in 2022) i-chiitoitsu (expected DP)

Ffmpeg notes (I) fundamentals of audio and video

剑指 Offer 36. 二叉搜索树与双向链表

Sword finger offer 54. the k-th node of the binary search tree

Softing pnGate系列网关:将PROFIBUS总线集成到PROFINET网络

VO, dto, do, Po distinction and use

基于ISO13209(OTX)实现EOL下线序列

node.express中req.body总是undefind解决

How to play a data mining game entry Edition
随机推荐
Baidu, Alibaba, Tencent, who fell first?
(15) [driver development] over written copy
PostgreSQL learning 04 PG_ hint_ Plan installation and use, SQL optimization knowledge
y76.第四章 Prometheus大厂监控体系及实战 -- prometheus进阶(七)
HTB-Devel
SAP FICO section III BDC and ltmc import S4 financial account
同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网
10、渲染基础
leetcode/整数除法
Brief introduction of acoustic filter Market
Codeforces Round #809 (Div. 2)
HTB-Optimum
Dynamic planning learning notes
R language Visual scatter diagram, geom using ggrep package_ text_ The repl function avoids overlapping labels between data points (set the hJust parameter to show that labels of all data points are a
Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
Singing "Seven Mile fragrance" askew -- pay tribute to Jay
ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off
Ceres solver version 1.14 and eigen3.2.9
对于von Mises distribution(冯·米塞斯分布)的一点心得
(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动