SlideShare a Scribd company logo
モデル
予測値Y’ 真の予測値Y
損失関数
損失率
オプティマイザー
①モデルは何か?
②損失関数は何を使っているか?
③オプティマイザーは何を使っているか?
15num_coeffs = 6
16trY_coeffs = [1, 2, 3, 4, 5, 6]
17trY = 0
18for i in range(num_coeffs):
19 #print(i)
20 trY += trY_coeffs[i] * np.power(trX, i)
21 #print(trX)
22 #print(trY)
23
24trY += np.random.randn(*trX.shape) * 1.5
25
26#print(trX)
27#print(trY)
28plt.scatter(trX, trY)
29plt.show()
F(x) = Wn*X^n + … + W1*x + W0
https://github.com/RuoAndo/seminar/blob/master/jt/7-nonlinear.py
41w = tf.Variable([0.] * num_coeffs, name="parameters")
42y_model = model(X, w)
43
44cost = tf.reduce_sum(tf.square(Y-y_model))
45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
46
47sess = tf.Session()
48init = tf.global_variables_initializer()
49sess.run(init)
50
51for epoch in range(training_epochs):
52 for (x, y) in zip(trX, trY):
53 sess.run(train_op, feed_dict={X: x, Y: y})
54
55w_val = sess.run(w)
56print(w_val)
[1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995]
session.runの引数
train_opを探す。
41w = tf.Variable([0.] * num_coeffs, name="parameters")
42y_model = model(X, w)
43
44cost = tf.reduce_sum(tf.square(Y-y_model))
45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
46
47sess = tf.Session()
48init = tf.global_variables_initializer()
49sess.run(init)
50
51for epoch in range(training_epochs):
52 for (x, y) in zip(trX, trY):
53 sess.run(train_op, feed_dict={X: x, Y: y})
54
55w_val = sess.run(w)
56print(w_val)
[1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995]
損失関数は
何か?
41w = tf.Variable([0.] * num_coeffs, name="parameters")
42y_model = model(X, w)
43
44cost = tf.reduce_sum(tf.square(Y-y_model))
45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
46
47sess = tf.Session()
48init = tf.global_variables_initializer()
49sess.run(init)
50
51for epoch in range(training_epochs):
52 for (x, y) in zip(trX, trY):
53 sess.run(train_op, feed_dict={X: x, Y: y})
54
55w_val = sess.run(w)
56print(w_val)
[1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995]
モデルを探す。
41w = tf.Variable([0.] * num_coeffs, name="parameters")
42y_model = model(X, w)
43
44cost = tf.reduce_sum(tf.square(Y-y_model))
45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
46
47sess = tf.Session()
48init = tf.global_variables_initializer()
49sess.run(init)
50
51for epoch in range(training_epochs):
52 for (x, y) in zip(trX, trY):
53 sess.run(train_op, feed_dict={X: x, Y: y})
54
55w_val = sess.run(w)
56print(w_val)
[1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995]
34def model(X, w):
35 terms = []
36 for i in range(num_coeffs):
37 term = tf.multiply(w[i], tf.pow(X, i))
38 terms.append(term)
39 return tf.add_n(terms)
モデル
34def model(X, w):
35 terms = []
36 for i in range(num_coeffs):
37 term = tf.multiply(w[i], tf.pow(X, i))
38 terms.append(term)
39 return tf.add_n(terms)
モデル
15num_coeffs = 6
16trY_coeffs = [1, 2, 3, 4, 5, 6]
17trY = 0
18for i in range(num_coeffs):
19 #print(i)
20 trY += trY_coeffs[i] * np.power(trX, i)
生成器
60plt.scatter(trX, trY)
61trY2 = 0
62for i in range(num_coeffs):
63 trY2 += w_val[i] * np.power(trX, i)
64plt.plot(trX, trY2, 'r')
65plt.show()
15num_coeffs = 6
16trY_coeffs = [1, 2, 3, 4, 5, 6]
17trY = 0
18for i in range(num_coeffs):
19 #print(i)
20 trY += trY_coeffs[i] * np.power(trX, i)
生成器

More Related Content

DOCX
PYTHON. AM CALL Pricing Trees
DOCX
Monte-carlo sim pricing EU call
PDF
Derivatives Lesson Oct 13
PPSX
Tensorflow basics
PDF
Processing資料(5) 正弦波と極座標
PDF
Program to reflecta triangle
PDF
Day 1a examples
DOCX
PythonArtCode
PYTHON. AM CALL Pricing Trees
Monte-carlo sim pricing EU call
Derivatives Lesson Oct 13
Tensorflow basics
Processing資料(5) 正弦波と極座標
Program to reflecta triangle
Day 1a examples
PythonArtCode

What's hot (20)

PDF
Baby Steps to Machine Learning at DevFest Lagos 2019
PDF
What is TensorFlow and why do we use it
PPT
Dynamic allocation
PPTX
Extreme Value
DOCX
Public class arithmetic operatordemo
DOCX
Segundo Punto
DOCX
Maple Code for Steepest Descent
PDF
Basics of Computer graphics lab
PPTX
Sketching derivatives
PDF
Rombo matriz
DOCX
Ejercicios Scilab Completo
PDF
10CSL67 CG LAB PROGRAM 4
PPTX
Pointer example
DOCX
Taller De Scilab
DOCX
Trabajo Scilab
PPTX
Derivatives in graphing-dfs
PPTX
Quad fcn
PPT
ML: A Strongly Typed Functional Language
PDF
Proga 0601
Baby Steps to Machine Learning at DevFest Lagos 2019
What is TensorFlow and why do we use it
Dynamic allocation
Extreme Value
Public class arithmetic operatordemo
Segundo Punto
Maple Code for Steepest Descent
Basics of Computer graphics lab
Sketching derivatives
Rombo matriz
Ejercicios Scilab Completo
10CSL67 CG LAB PROGRAM 4
Pointer example
Taller De Scilab
Trabajo Scilab
Derivatives in graphing-dfs
Quad fcn
ML: A Strongly Typed Functional Language
Proga 0601
Ad

Similar to 【AI実装4】TensorFlowのプログラムを読む2 非線形回帰 (20)

DOCX
機会学習レポート
PDF
TensorFlow Tutorial
PDF
2016 dg2
PPTX
深層学習後半
PPTX
深層学習前半
PPTX
Introduction to TensorFlow
PPTX
深層学習前半
PDF
Assignment 5.2.pdf
PPTX
TensorFlow in Practice
PDF
Tensor flow description of ML Lab. document
PDF
ML基本からResNetまで
PDF
DF1 - Py - Ovcharenko - Theano Tutorial
PDF
Assignment 6.2a.pdf
PPTX
Tensorflow, deep learning and recurrent neural networks without a ph d
PDF
Theano vs TensorFlow | Edureka
PDF
ラビットチャレンジ 深層学習Day1 day2レポート
PDF
A Transformer-based Framework for Multivariate Time Series Representation Lea...
PPTX
Introduction to Tensorflow
PPTX
Introduction to PyTorch
PDF
Assignment 5.1.pdf
機会学習レポート
TensorFlow Tutorial
2016 dg2
深層学習後半
深層学習前半
Introduction to TensorFlow
深層学習前半
Assignment 5.2.pdf
TensorFlow in Practice
Tensor flow description of ML Lab. document
ML基本からResNetまで
DF1 - Py - Ovcharenko - Theano Tutorial
Assignment 6.2a.pdf
Tensorflow, deep learning and recurrent neural networks without a ph d
Theano vs TensorFlow | Edureka
ラビットチャレンジ 深層学習Day1 day2レポート
A Transformer-based Framework for Multivariate Time Series Representation Lea...
Introduction to Tensorflow
Introduction to PyTorch
Assignment 5.1.pdf
Ad

More from Ruo Ando (20)

PDF
KISTI-NII Joint Security Workshop 2023.pdf
PDF
Gartner 「セキュリティ&リスクマネジメントサミット 2019」- 安藤
PDF
解説#86 決定木 - ss.pdf
PDF
SaaSアカデミー for バックオフィス アイドルと学ぶDX講座 ~アイドル戦略に見るDXを専門家が徹底解説~
PDF
解説#83 情報エントロピー
PDF
解説#82 記号論理学
PDF
解説#81 ロジスティック回帰
PDF
解説#74 連結リスト
PDF
解説#76 福岡正信
PDF
解説#77 非加算無限
PDF
解説#1 C言語ポインタとアドレス
PDF
解説#78 誤差逆伝播
PDF
解説#73 ハフマン符号
PDF
【技術解説20】 ミニバッチ確率的勾配降下法
PDF
【技術解説4】assertion failureとuse after-free
PDF
ITmedia Security Week 2021 講演資料
PPTX
ファジングの解説
PDF
AI(機械学習・深層学習)との協働スキルとOperational AIの事例紹介 @ ビジネス+ITセミナー 2020年11月
PDF
Intel Trusted Computing Group 1st Workshop
PDF
情報セキュリティと標準化I 第15回
KISTI-NII Joint Security Workshop 2023.pdf
Gartner 「セキュリティ&リスクマネジメントサミット 2019」- 安藤
解説#86 決定木 - ss.pdf
SaaSアカデミー for バックオフィス アイドルと学ぶDX講座 ~アイドル戦略に見るDXを専門家が徹底解説~
解説#83 情報エントロピー
解説#82 記号論理学
解説#81 ロジスティック回帰
解説#74 連結リスト
解説#76 福岡正信
解説#77 非加算無限
解説#1 C言語ポインタとアドレス
解説#78 誤差逆伝播
解説#73 ハフマン符号
【技術解説20】 ミニバッチ確率的勾配降下法
【技術解説4】assertion failureとuse after-free
ITmedia Security Week 2021 講演資料
ファジングの解説
AI(機械学習・深層学習)との協働スキルとOperational AIの事例紹介 @ ビジネス+ITセミナー 2020年11月
Intel Trusted Computing Group 1st Workshop
情報セキュリティと標準化I 第15回

Recently uploaded (20)

PPTX
Sustainable Sites - Green Building Construction
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Geodesy 1.pptx...............................................
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Welding lecture in detail for understanding
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
web development for engineering and engineering
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Construction Project Organization Group 2.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPT
Project quality management in manufacturing
PDF
composite construction of structures.pdf
Sustainable Sites - Green Building Construction
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Lecture Notes Electrical Wiring System Components
Geodesy 1.pptx...............................................
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Welding lecture in detail for understanding
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Operating System & Kernel Study Guide-1 - converted.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
web development for engineering and engineering
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Construction Project Organization Group 2.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
bas. eng. economics group 4 presentation 1.pptx
Foundation to blockchain - A guide to Blockchain Tech
Project quality management in manufacturing
composite construction of structures.pdf

【AI実装4】TensorFlowのプログラムを読む2 非線形回帰

  • 2. 15num_coeffs = 6 16trY_coeffs = [1, 2, 3, 4, 5, 6] 17trY = 0 18for i in range(num_coeffs): 19 #print(i) 20 trY += trY_coeffs[i] * np.power(trX, i) 21 #print(trX) 22 #print(trY) 23 24trY += np.random.randn(*trX.shape) * 1.5 25 26#print(trX) 27#print(trY) 28plt.scatter(trX, trY) 29plt.show() F(x) = Wn*X^n + … + W1*x + W0 https://github.com/RuoAndo/seminar/blob/master/jt/7-nonlinear.py
  • 3. 41w = tf.Variable([0.] * num_coeffs, name="parameters") 42y_model = model(X, w) 43 44cost = tf.reduce_sum(tf.square(Y-y_model)) 45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) 46 47sess = tf.Session() 48init = tf.global_variables_initializer() 49sess.run(init) 50 51for epoch in range(training_epochs): 52 for (x, y) in zip(trX, trY): 53 sess.run(train_op, feed_dict={X: x, Y: y}) 54 55w_val = sess.run(w) 56print(w_val) [1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995] session.runの引数 train_opを探す。
  • 4. 41w = tf.Variable([0.] * num_coeffs, name="parameters") 42y_model = model(X, w) 43 44cost = tf.reduce_sum(tf.square(Y-y_model)) 45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) 46 47sess = tf.Session() 48init = tf.global_variables_initializer() 49sess.run(init) 50 51for epoch in range(training_epochs): 52 for (x, y) in zip(trX, trY): 53 sess.run(train_op, feed_dict={X: x, Y: y}) 54 55w_val = sess.run(w) 56print(w_val) [1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995] 損失関数は 何か?
  • 5. 41w = tf.Variable([0.] * num_coeffs, name="parameters") 42y_model = model(X, w) 43 44cost = tf.reduce_sum(tf.square(Y-y_model)) 45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) 46 47sess = tf.Session() 48init = tf.global_variables_initializer() 49sess.run(init) 50 51for epoch in range(training_epochs): 52 for (x, y) in zip(trX, trY): 53 sess.run(train_op, feed_dict={X: x, Y: y}) 54 55w_val = sess.run(w) 56print(w_val) [1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995] モデルを探す。
  • 6. 41w = tf.Variable([0.] * num_coeffs, name="parameters") 42y_model = model(X, w) 43 44cost = tf.reduce_sum(tf.square(Y-y_model)) 45train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) 46 47sess = tf.Session() 48init = tf.global_variables_initializer() 49sess.run(init) 50 51for epoch in range(training_epochs): 52 for (x, y) in zip(trX, trY): 53 sess.run(train_op, feed_dict={X: x, Y: y}) 54 55w_val = sess.run(w) 56print(w_val) [1.0518903 1.7557341 4.2570124 5.756541 3.2840345 5.1628995] 34def model(X, w): 35 terms = [] 36 for i in range(num_coeffs): 37 term = tf.multiply(w[i], tf.pow(X, i)) 38 terms.append(term) 39 return tf.add_n(terms) モデル
  • 7. 34def model(X, w): 35 terms = [] 36 for i in range(num_coeffs): 37 term = tf.multiply(w[i], tf.pow(X, i)) 38 terms.append(term) 39 return tf.add_n(terms) モデル 15num_coeffs = 6 16trY_coeffs = [1, 2, 3, 4, 5, 6] 17trY = 0 18for i in range(num_coeffs): 19 #print(i) 20 trY += trY_coeffs[i] * np.power(trX, i) 生成器
  • 8. 60plt.scatter(trX, trY) 61trY2 = 0 62for i in range(num_coeffs): 63 trY2 += w_val[i] * np.power(trX, i) 64plt.plot(trX, trY2, 'r') 65plt.show() 15num_coeffs = 6 16trY_coeffs = [1, 2, 3, 4, 5, 6] 17trY = 0 18for i in range(num_coeffs): 19 #print(i) 20 trY += trY_coeffs[i] * np.power(trX, i) 生成器