当前位置:网站首页>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()
边栏推荐
- MySQL中建表时 pk、nn、qu、b、un、zf、ai、g代表的意思
- 计算BDP值和wnd值
- Pdf snapshot artifact
- Leetcode/ binary addition
- 新时代生产力工具——FlowUs 息流全方位评测
- (2022 Niuke multi School II) l-link with level editor I (dynamic planning)
- Tutorial: encryption keys in cloud (using golang and CLI)
- Ceres solver version 1.14 and eigen3.2.9
- 同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网
- Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
猜你喜欢

An SQL execution process

【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口

剑指 Offer 45. 把数组排成最小的数

同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网

New discovery of ROS callback function

Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
![(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动](/img/90/0d94d26be8128d77de65919763fda5.png)
(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动

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

ARM裸板调试之JTAG调试源码级调试

Use abp Zero builds a third-party login module (4): wechat applet development
随机推荐
(牛客多校二)G-Link with Monotonic Subsequence(构造题)
Openzeppelin scalable template library contract initialization details
[ultra detailed diagram] FPN + mask RCNN
(16)[系统调用]追踪系统调用(3环)
Vim配置Golang开发环境
Leetcode/ integer division
Detailed explanation of arm instruction CMP
SAP FICO section III BDC and ltmc import S4 financial account
R language uses LM function to build multiple linear regression model and write regression equation according to model coefficient
How to start if you want to be a product manager?
idea常用10个快捷键
机器学习 Keras拟合正弦函数
函数模板学习记录
HTB-Arctic
Use abp Zero builds a third-party login module (4): wechat applet development
PostgreSQL learning 04 PG_ hint_ Plan installation and use, SQL optimization knowledge
(2022 Niuke multi School II) k-link with bracket sequence I (dynamic planning)
New discovery of ROS callback function
日期(DAY 76)
Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network