SlideShare a Scribd company logo
1 of 8
Download to read offline
モデル
予測値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

What's hot

Extreme Value
Extreme ValueExtreme Value
Extreme Value
nclamelas
 
Maple Code for Steepest Descent
Maple Code for Steepest DescentMaple Code for Steepest Descent
Maple Code for Steepest Descent
Jeremy Lane
 
Rombo matriz
Rombo matrizRombo matriz
Rombo matriz
epetekaun
 
ML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional LanguageML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional Language
lijx127
 

What's hot (20)

Baby Steps to Machine Learning at DevFest Lagos 2019
Baby Steps to Machine Learning at DevFest Lagos 2019Baby Steps to Machine Learning at DevFest Lagos 2019
Baby Steps to Machine Learning at DevFest Lagos 2019
 
What is TensorFlow and why do we use it
What is TensorFlow and why do we use itWhat is TensorFlow and why do we use it
What is TensorFlow and why do we use it
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
 
Extreme Value
Extreme ValueExtreme Value
Extreme Value
 
Public class arithmetic operatordemo
Public class arithmetic operatordemoPublic class arithmetic operatordemo
Public class arithmetic operatordemo
 
Segundo Punto
Segundo PuntoSegundo Punto
Segundo Punto
 
Maple Code for Steepest Descent
Maple Code for Steepest DescentMaple Code for Steepest Descent
Maple Code for Steepest Descent
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Sketching derivatives
Sketching derivativesSketching derivatives
Sketching derivatives
 
week-15x
week-15xweek-15x
week-15x
 
Rombo matriz
Rombo matrizRombo matriz
Rombo matriz
 
Ejercicios Scilab Completo
Ejercicios Scilab CompletoEjercicios Scilab Completo
Ejercicios Scilab Completo
 
10CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 410CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 4
 
Pointer example
Pointer examplePointer example
Pointer example
 
Taller De Scilab
Taller De ScilabTaller De Scilab
Taller De Scilab
 
Trabajo Scilab
Trabajo ScilabTrabajo Scilab
Trabajo Scilab
 
Derivatives in graphing-dfs
Derivatives in graphing-dfsDerivatives in graphing-dfs
Derivatives in graphing-dfs
 
Quad fcn
Quad fcnQuad fcn
Quad fcn
 
ML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional LanguageML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional Language
 
Proga 0601
Proga 0601Proga 0601
Proga 0601
 

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

Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
lauracallander
 
Succumbing to the Python in Financial Markets
Succumbing to the Python in Financial MarketsSuccumbing to the Python in Financial Markets
Succumbing to the Python in Financial Markets
dcerezo
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
Abi finni
 

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

Машинное обучение на JS. С чего начать и куда идти | Odessa Frontend Meetup #12
Машинное обучение на JS. С чего начать и куда идти | Odessa Frontend Meetup #12Машинное обучение на JS. С чего начать и куда идти | Odessa Frontend Meetup #12
Машинное обучение на JS. С чего начать и куда идти | Odessa Frontend Meetup #12
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Python + Tensorflow: how to earn money in the Stock Exchange with Deep Learni...
Python + Tensorflow: how to earn money in the Stock Exchange with Deep Learni...Python + Tensorflow: how to earn money in the Stock Exchange with Deep Learni...
Python + Tensorflow: how to earn money in the Stock Exchange with Deep Learni...
 
Succumbing to the Python in Financial Markets
Succumbing to the Python in Financial MarketsSuccumbing to the Python in Financial Markets
Succumbing to the Python in Financial Markets
 
Pytorch for tf_developers
Pytorch for tf_developersPytorch for tf_developers
Pytorch for tf_developers
 
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager ExecutionTensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to Tensorflow
 
Regression Tree.pdf
Regression Tree.pdfRegression Tree.pdf
Regression Tree.pdf
 
Assignment 6.2a.pdf
Assignment 6.2a.pdfAssignment 6.2a.pdf
Assignment 6.2a.pdf
 
Python profiling
Python profilingPython profiling
Python profiling
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
 
Os lab upto_1st_mid
Os lab upto_1st_midOs lab upto_1st_mid
Os lab upto_1st_mid
 
Os lab upto 1st mid
Os lab upto 1st midOs lab upto 1st mid
Os lab upto 1st mid
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
 
maXbox starter65 machinelearning3
maXbox starter65 machinelearning3maXbox starter65 machinelearning3
maXbox starter65 machinelearning3
 
Intelligent System Optimizations
Intelligent System OptimizationsIntelligent System Optimizations
Intelligent System Optimizations
 
Python
PythonPython
Python
 
Tensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentTensor flow description of ML Lab. document
Tensor flow description of ML Lab. document
 

More from Ruo Ando

More from Ruo Ando (20)

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

Recently uploaded

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 

Recently uploaded (20)

The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 

【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) 生成器