当前位置:网站首页>机器学习 Keras拟合正弦函数
机器学习 Keras拟合正弦函数
2022-07-25 06:06: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()
# 当前层神经元数量:1 激活函数类型:sigmoid 输入数据特征纬度: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))
# 损失函数(均方误差) 优化器(sgd:随机梯度下降算法) 评估标准(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()
边栏推荐
- PHP warehouse inventory management system source code WMS source code
- 出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
- Blocking Queue Analysis
- 对于von Mises distribution(冯·米塞斯分布)的一点心得
- Unity 模型简化/合并 一键式插件
- 同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网
- Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
- Run length test of R language: use the runs.test function to perform run length test on binary sequence data (check whether the sequence is random)
- 2020icpc Jiangxi warm up e.robot sends red packets (DFS)
- HTB-Granpa
猜你喜欢

Unity model simplification / consolidation one click plug-in

Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network

求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!

Prometheus operator configures promethesrule alarm rules

Use abp Zero builds a third-party login module (4): wechat applet development

Mechanism and principle of multihead attention and masked attention

(2022牛客多校)D-Link with Game Glitch(spfa)

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

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

Sword finger offer 36. binary search tree and bidirectional linked list
随机推荐
QT qtextedit setting qscrollbar style sheet does not take effect solution
[typescript manual]
[ultra detailed diagram] FPN + mask RCNN
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
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
HTB-Beep
Binary search tree (day 75)
Sword finger offer 45. arrange the array into the smallest number
VO, dto, do, Po distinction and use
Ceres solver version 1.14 and eigen3.2.9
"Everyday Mathematics" serial 61: March 1
A little experience about von Mises distribution
Date (day 76)
Summer summary 2
Equal proportion of R language test group: use the prop.test function to test whether the success proportion of the two groups is equal
Msys2 common configuration
Idea commonly used 10 shortcut keys
R language data The table package performs aggregation transforms of data packets and calculates the grouping interquartile range (IQR) of dataframe data
Calculate BDP value and wnd value
2020icpc Jiangxi warm up e.robot sends red packets (DFS)