Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
golbin
TensorFlow-Tutorials
Repository navigation
Code
Issues
23
(23)
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
TensorFlow-Tutorials
/
03 - TensorFlow Basic
/
03 - Linear Regression.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
44 lines (35 loc) · 1.93 KB
master
Breadcrumbs
TensorFlow-Tutorials
/
03 - TensorFlow Basic
/
03 - Linear Regression.py
Copy path
Top
File metadata and controls
Code
Blame
44 lines (35 loc) · 1.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# X 와 Y 의 상관관계를 분석하는 기초적인 선형 회귀 모델을 만들고 실행해봅니다.
import
tensorflow
as
tf
x_data
=
[
1
,
2
,
3
]
y_data
=
[
1
,
2
,
3
]
W
=
tf
.
Variable
(
tf
.
random_uniform
([
1
],
-
1.0
,
1.0
))
b
=
tf
.
Variable
(
tf
.
random_uniform
([
1
],
-
1.0
,
1.0
))
# name: 나중에 텐서보드등으로 값의 변화를 추적하거나 살펴보기 쉽게 하기 위해 이름을 붙여줍니다.
X
=
tf
.
placeholder
(
tf
.
float32
,
name
=
"X"
)
Y
=
tf
.
placeholder
(
tf
.
float32
,
name
=
"Y"
)
print
(
X
)
print
(
Y
)
# X 와 Y 의 상관 관계를 분석하기 위한 가설 수식을 작성합니다.
# y = W * x + b
# W 와 X 가 행렬이 아니므로 tf.matmul 이 아니라 기본 곱셈 기호를 사용했습니다.
hypothesis
=
W
*
X
+
b
# 손실 함수를 작성합니다.
# mean(h - Y)^2 : 예측값과 실제값의 거리를 비용(손실) 함수로 정합니다.
cost
=
tf
.
reduce_mean
(
tf
.
square
(
hypothesis
-
Y
))
# 텐서플로우에 기본적으로 포함되어 있는 함수를 이용해 경사 하강법 최적화를 수행합니다.
optimizer
=
tf
.
train
.
GradientDescentOptimizer
(
learning_rate
=
0.1
)
# 비용을 최소화 하는 것이 최종 목표
train_op
=
optimizer
.
minimize
(
cost
)
# 세션을 생성하고 초기화합니다.
with
tf
.
Session
()
as
sess
:
sess
.
run
(
tf
.
global_variables_initializer
())
# 최적화를 100번 수행합니다.
for
step
in
range
(
100
):
# sess.run 을 통해 train_op 와 cost 그래프를 계산합니다.
# 이 때, 가설 수식에 넣어야 할 실제값을 feed_dict 을 통해 전달합니다.
_
,
cost_val
=
sess
.
run
([
train_op
,
cost
],
feed_dict
=
{
X
:
x_data
,
Y
:
y_data
})
print
(
step
,
cost_val
,
sess
.
run
(
W
),
sess
.
run
(
b
))
# 최적화가 완료된 모델에 테스트 값을 넣고 결과가 잘 나오는지 확인해봅니다.
print
(
"
\n
=== Test ==="
)
print
(
"X: 5, Y:"
,
sess
.
run
(
hypothesis
,
feed_dict
=
{
X
:
5
}))
print
(
"X: 2.5, Y:"
,
sess
.
run
(
hypothesis
,
feed_dict
=
{
X
:
2.5
}))
You can’t perform that action at this time.