<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>반짝반짝 빈나는</title>
    <link>https://beenlife.tistory.com/</link>
    <description>먹고 여행하고 운동하는 것을 좋아하는,
IT엔지니어의 it한 감성라이프</description>
    <language>ko</language>
    <pubDate>Mon, 24 Aug 2026 07:47:02 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>빈나는</managingEditor>
    <image>
      <title>반짝반짝 빈나는</title>
      <url>https://t1.daumcdn.net/cfile/tistory/2236643C592994D628</url>
      <link>https://beenlife.tistory.com</link>
    </image>
    <item>
      <title>객체 지향 프로그래밍 개념 정리</title>
      <link>https://beenlife.tistory.com/120</link>
      <description>&lt;p&gt;&amp;lt;객체&amp;nbsp;지향&amp;nbsp;프로그래밍&amp;gt; &lt;br /&gt;1.&amp;nbsp;객체란? &lt;br /&gt;객체(Object)란&amp;nbsp;물리적으로&amp;nbsp;존재하거나&amp;nbsp;추상적으로&amp;nbsp;생각할&amp;nbsp;수&amp;nbsp;있는&amp;nbsp;것&amp;nbsp;중에서&amp;nbsp;자신의&amp;nbsp;속성을&amp;nbsp;가지고&amp;nbsp;있고&amp;nbsp;다른&amp;nbsp;것과&amp;nbsp;식별&amp;nbsp;가능한&amp;nbsp;것을&amp;nbsp;말한다. &lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;객체&amp;nbsp;간의&amp;nbsp;관계 &lt;br /&gt;객체는&amp;nbsp;개별적으로&amp;nbsp;사용될&amp;nbsp;수&amp;nbsp;있지만,&amp;nbsp;대부분&amp;nbsp;다른&amp;nbsp;객체와&amp;nbsp;관계를&amp;nbsp;맺고&amp;nbsp;있다.&amp;nbsp;이&amp;nbsp;관계의&amp;nbsp;종류에는&amp;nbsp;집합&amp;nbsp;관계,&amp;nbsp;사용&amp;nbsp;관계,&amp;nbsp;상속&amp;nbsp;관계가&amp;nbsp;있다. &lt;br /&gt;집합&amp;nbsp;관계&amp;nbsp;:&amp;nbsp;자동차&amp;nbsp;객체&amp;nbsp;&amp;lt;---&amp;gt;&amp;nbsp;엔진&amp;nbsp;객체,&amp;nbsp;타이어&amp;nbsp;객체,&amp;nbsp;핸들&amp;nbsp;객체 &lt;br /&gt;&lt;br /&gt;사용&amp;nbsp;관계&amp;nbsp;:&amp;nbsp;객체&amp;nbsp;간의&amp;nbsp;상호작용.&amp;nbsp;사람은&amp;nbsp;자동차를&amp;nbsp;사용하므로&amp;nbsp;사람과&amp;nbsp;자동차는&amp;nbsp;사용의&amp;nbsp;관계 &lt;br /&gt;&lt;br /&gt;상속&amp;nbsp;관계&amp;nbsp;:&amp;nbsp;상위(부모)&amp;nbsp;객체를&amp;nbsp;기반으로&amp;nbsp;하위(자식)&amp;nbsp;객체를&amp;nbsp;생성하는&amp;nbsp;관계.&amp;nbsp;자동차&amp;nbsp;객체&amp;nbsp;---&amp;gt;&amp;nbsp;기계&amp;nbsp;객체 &lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;객체&amp;nbsp;지향&amp;nbsp;프로그래밍의&amp;nbsp;특징 &lt;br /&gt;-&amp;nbsp;캡슐화(Encapsulation)&amp;nbsp;:&amp;nbsp;객체의&amp;nbsp;필드,&amp;nbsp;메소드를&amp;nbsp;하나로&amp;nbsp;묶고,&amp;nbsp;실제&amp;nbsp;구현&amp;nbsp;내용을&amp;nbsp;감추는&amp;nbsp;것.&amp;nbsp;외부&amp;nbsp;객체는&amp;nbsp;객체&amp;nbsp;내부의&amp;nbsp;구조를&amp;nbsp;알지&amp;nbsp;못하며&amp;nbsp;객체가&amp;nbsp;노출해서&amp;nbsp;제공하는&amp;nbsp;필드와&amp;nbsp;메소드만&amp;nbsp;이용할&amp;nbsp;수&amp;nbsp;있다. &lt;br /&gt;&lt;br /&gt;-&amp;nbsp;상속(Inheritance)&amp;nbsp;:&amp;nbsp;상위&amp;nbsp;객체를&amp;nbsp;재사용해서&amp;nbsp;하위&amp;nbsp;객체를&amp;nbsp;쉽고&amp;nbsp;빨리&amp;nbsp;설계할&amp;nbsp;수&amp;nbsp;있도록&amp;nbsp;도와주고,&amp;nbsp;이미&amp;nbsp;잘&amp;nbsp;개발된&amp;nbsp;객체를&amp;nbsp;재사용해서&amp;nbsp;새로운&amp;nbsp;객체를&amp;nbsp;만들기&amp;nbsp;때문에&amp;nbsp;반복된&amp;nbsp;코드의&amp;nbsp;중복을&amp;nbsp;줄여줌 &lt;br /&gt;&lt;br /&gt;-&amp;nbsp;다형성(Polymorphism)&amp;nbsp;:&amp;nbsp;같은&amp;nbsp;타입이지만&amp;nbsp;실행&amp;nbsp;결과가&amp;nbsp;다양한&amp;nbsp;객체를&amp;nbsp;이용할&amp;nbsp;수&amp;nbsp;있는&amp;nbsp;성질.&amp;nbsp;타이어&amp;nbsp;타입&amp;nbsp;--&amp;gt;&amp;nbsp;한국&amp;nbsp;타이어&amp;nbsp;객체,&amp;nbsp;금호&amp;nbsp;타이어&amp;nbsp;객체 &lt;br /&gt;&lt;br /&gt;&amp;lt;객체와&amp;nbsp;클래스&amp;gt; &lt;br /&gt;&lt;br /&gt;객체를&amp;nbsp;생성하는&amp;nbsp;순서&amp;nbsp;:&amp;nbsp;개발자&amp;nbsp;--(설계)--&amp;gt;&amp;nbsp;클래스(설계도)&amp;nbsp;--(인스턴스화)--&amp;gt;&amp;nbsp;인스턴스(객체)&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;lt;객체&amp;nbsp;생성과&amp;nbsp;클래스&amp;nbsp;변수&amp;gt; &lt;br /&gt;&lt;br /&gt;new&amp;nbsp;연산자를&amp;nbsp;사용해&amp;nbsp;클래스로부터&amp;nbsp;객체를&amp;nbsp;생성.&amp;nbsp;new&amp;nbsp;연산자로&amp;nbsp;생성된&amp;nbsp;객체는&amp;nbsp;메모리&amp;nbsp;힙(heap)&amp;nbsp;영역에&amp;nbsp;생성됨.&amp;nbsp;new&amp;nbsp;연산자는&amp;nbsp;힙&amp;nbsp;영역에&amp;nbsp;객체를&amp;nbsp;생성시킨&amp;nbsp;후,&amp;nbsp;객체의&amp;nbsp;주소를&amp;nbsp;리턴하도록&amp;nbsp;되어&amp;nbsp;있음.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;lt;클래스의&amp;nbsp;구성&amp;nbsp;멤버&amp;gt; &lt;br /&gt;-&amp;nbsp;필드:&amp;nbsp;객체의&amp;nbsp;데이터가&amp;nbsp;저장되는&amp;nbsp;곳 &lt;br /&gt;-&amp;nbsp;생성자(Constructor):&amp;nbsp;객체&amp;nbsp;생성&amp;nbsp;시&amp;nbsp;초기화&amp;nbsp;역할&amp;nbsp;담당 &lt;br /&gt;-&amp;nbsp;메소드:&amp;nbsp;객체&amp;nbsp;동작에&amp;nbsp;해당하는&amp;nbsp;실행&amp;nbsp;블록 &lt;br /&gt;&lt;br /&gt;&amp;lt;생성자&amp;gt; &lt;br /&gt;1.&amp;nbsp;생성자&amp;nbsp;오버로딩&amp;nbsp;:&amp;nbsp;매개&amp;nbsp;변수를&amp;nbsp;달리하는&amp;nbsp;생성자를&amp;nbsp;여러개&amp;nbsp;선언하는&amp;nbsp;것.&amp;nbsp;생성자&amp;nbsp;오버로딩&amp;nbsp;시&amp;nbsp;주의할&amp;nbsp;점은&amp;nbsp;매개&amp;nbsp;변수의&amp;nbsp;타입과&amp;nbsp;개수&amp;nbsp;그리고&amp;nbsp;선언된&amp;nbsp;순서가&amp;nbsp;똑같을&amp;nbsp;경우&amp;nbsp;매개&amp;nbsp;변수&amp;nbsp;이름만&amp;nbsp;바꾸는&amp;nbsp;것은&amp;nbsp;생성자&amp;nbsp;오버로딩이라고&amp;nbsp;볼&amp;nbsp;수&amp;nbsp;없음. &lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;다른&amp;nbsp;생성자&amp;nbsp;호출(this()) &lt;br /&gt;생성자&amp;nbsp;오버로딩이&amp;nbsp;많아질&amp;nbsp;경우&amp;nbsp;생성자&amp;nbsp;간의&amp;nbsp;중복된&amp;nbsp;코드가&amp;nbsp;발생할&amp;nbsp;수&amp;nbsp;있다.&amp;nbsp;매개&amp;nbsp;변수의&amp;nbsp;수만&amp;nbsp;달리하고&amp;nbsp;필드&amp;nbsp;초기화&amp;nbsp;내용이&amp;nbsp;비슷한&amp;nbsp;생성자에서&amp;nbsp;이러한&amp;nbsp;현상을&amp;nbsp;많이&amp;nbsp;볼&amp;nbsp;수&amp;nbsp;있다. &lt;br /&gt;이&amp;nbsp;경우에는&amp;nbsp;필드&amp;nbsp;초기화&amp;nbsp;내용은&amp;nbsp;한&amp;nbsp;생성자에만&amp;nbsp;집중적으로&amp;nbsp;작성하고,&amp;nbsp;나머지&amp;nbsp;생성자는&amp;nbsp;초기화&amp;nbsp;내용을&amp;nbsp;가지고&amp;nbsp;있는&amp;nbsp;생성자를&amp;nbsp;호출하는&amp;nbsp;방법으로&amp;nbsp;개선할&amp;nbsp;수&amp;nbsp;있다.&amp;nbsp;생성자에서&amp;nbsp;다른&amp;nbsp;생성자를&amp;nbsp;호출할&amp;nbsp;때에는&amp;nbsp;다음과&amp;nbsp;같이&amp;nbsp;this()&amp;nbsp;코드를&amp;nbsp;사용한다. &lt;br /&gt;this()는&amp;nbsp;자신의&amp;nbsp;다른&amp;nbsp;생성자를&amp;nbsp;호출하는&amp;nbsp;코드로&amp;nbsp;반드시&amp;nbsp;생성자의&amp;nbsp;첫줄에서만&amp;nbsp;허용된다. &lt;br /&gt;&lt;br /&gt;&amp;lt;메소드&amp;gt; &lt;br /&gt;1.&amp;nbsp;매개&amp;nbsp;변수의&amp;nbsp;수를&amp;nbsp;모를&amp;nbsp;경우&amp;nbsp;:&amp;nbsp;해결책은&amp;nbsp;매개&amp;nbsp;변수를&amp;nbsp;배열&amp;nbsp;타입으로&amp;nbsp;선언하는&amp;nbsp;것이다. &lt;br /&gt;ex&amp;nbsp;)&amp;nbsp;int&amp;nbsp;sum1(int[]&amp;nbsp;values)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;br /&gt;But,&amp;nbsp;매개변수를&amp;nbsp;배열&amp;nbsp;타입으로&amp;nbsp;선언하면,&amp;nbsp;메소드를&amp;nbsp;호출하기&amp;nbsp;전에&amp;nbsp;배열을&amp;nbsp;생성해야&amp;nbsp;하는&amp;nbsp;불편한&amp;nbsp;점이&amp;nbsp;있다. &lt;br /&gt;그래서&amp;nbsp;배열을&amp;nbsp;생성하지&amp;nbsp;않고&amp;nbsp;갑의&amp;nbsp;리스트만&amp;nbsp;넘겨주는&amp;nbsp;방법도&amp;nbsp;있다. &lt;br /&gt;매개변수를&amp;nbsp;&quot;...&quot;를&amp;nbsp;사용해서&amp;nbsp;선언하면,&amp;nbsp;메소드&amp;nbsp;호출&amp;nbsp;시&amp;nbsp;넘겨준&amp;nbsp;값의&amp;nbsp;수에&amp;nbsp;따라&amp;nbsp;자동으로&amp;nbsp;배열이&amp;nbsp;생성되고&amp;nbsp;매개값으로&amp;nbsp;사용된다. &lt;br /&gt;ex&amp;nbsp;)&amp;nbsp;int&amp;nbsp;sum2(int&amp;nbsp;...&amp;nbsp;values)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/p&gt;
&lt;p&gt;2.&amp;nbsp;메소드&amp;nbsp;오버로딩 &lt;br /&gt;클래스&amp;nbsp;내에&amp;nbsp;같은&amp;nbsp;이름의&amp;nbsp;메소드를&amp;nbsp;여러&amp;nbsp;개&amp;nbsp;선언하는&amp;nbsp;것. &lt;br /&gt;오버로딩의&amp;nbsp;사전적&amp;nbsp;의미는&amp;nbsp;많이&amp;nbsp;싣는&amp;nbsp;것. &lt;br /&gt;하나의&amp;nbsp;메소드&amp;nbsp;이름으로&amp;nbsp;여러&amp;nbsp;기능을&amp;nbsp;담는다&amp;nbsp;하여&amp;nbsp;붙여진&amp;nbsp;이름. &lt;br /&gt;메소드&amp;nbsp;오버로딩의&amp;nbsp;조건은&amp;nbsp;매개변수의&amp;nbsp;타입,&amp;nbsp;개수,&amp;nbsp;순서&amp;nbsp;중&amp;nbsp;하나가&amp;nbsp;달라야함.&lt;/p&gt;
&lt;p&gt;&amp;lt;인스턴스&amp;nbsp;멤버와&amp;nbsp;this&amp;gt; &lt;br /&gt;인스턴스&amp;nbsp;멤버란&amp;nbsp;객체(인스턴스)를&amp;nbsp;생성&amp;nbsp;후&amp;nbsp;사용할&amp;nbsp;수&amp;nbsp;있는&amp;nbsp;필드와&amp;nbsp;메소드를&amp;nbsp;말하는데,&amp;nbsp;이들을&amp;nbsp;각각&amp;nbsp;인스턴스&amp;nbsp;필드,&amp;nbsp;인스턴스&amp;nbsp;메소드라&amp;nbsp;부름 &lt;br /&gt;여태까지&amp;nbsp;보았던&amp;nbsp;모든&amp;nbsp;필드와&amp;nbsp;메소드는&amp;nbsp;인스턴스&amp;nbsp;멤버였음&lt;/p&gt;
&lt;p&gt;객체&amp;nbsp;내부에서도&amp;nbsp;인스턴스&amp;nbsp;멤버에&amp;nbsp;접근하기&amp;nbsp;위해&amp;nbsp;this를&amp;nbsp;사용할&amp;nbsp;수&amp;nbsp;있음. &lt;br /&gt;this란,&amp;nbsp;우리가&amp;nbsp;자신을&amp;nbsp;&quot;나&quot;라고&amp;nbsp;하듯이&amp;nbsp;객체는&amp;nbsp;자신을&amp;nbsp;&quot;this&quot;&amp;nbsp;라고함.&lt;/p&gt;
&lt;p&gt;따라서 this.model은 자신이 가지고 있는 model 필드라는 뜻임.&lt;/p&gt;
&lt;p&gt;this는 주로 생성자와 메소드의 매개변수 이름이 필드와 동일한 경우, 인스턴스&amp;nbsp;멤버인&amp;nbsp;필드임을&amp;nbsp;명시하고자&amp;nbsp;할&amp;nbsp;때&amp;nbsp;사용됨.&lt;/p&gt;
&lt;p&gt;&amp;lt;정적&amp;nbsp;멤버와&amp;nbsp;static&amp;gt; &lt;br /&gt;정적(static)은&amp;nbsp;'고정된'&amp;nbsp;의미를&amp;nbsp;가지고&amp;nbsp;있음. &lt;br /&gt;정적&amp;nbsp;멤버는&amp;nbsp;클래스에&amp;nbsp;고정된&amp;nbsp;멤버로서&amp;nbsp;객체를&amp;nbsp;생성하지&amp;nbsp;않고&amp;nbsp;사용할&amp;nbsp;수&amp;nbsp;있는&amp;nbsp;필드와&amp;nbsp;메소드를&amp;nbsp;말함. &lt;br /&gt;이들을&amp;nbsp;각각&amp;nbsp;정적&amp;nbsp;필드,&amp;nbsp;정적&amp;nbsp;메소드라고&amp;nbsp;부름. &lt;br /&gt;정적&amp;nbsp;멤버는&amp;nbsp;객체(인스턴스)에&amp;nbsp;소속된&amp;nbsp;멤버가&amp;nbsp;아니라&amp;nbsp;클래스에&amp;nbsp;소속된&amp;nbsp;멤버이기&amp;nbsp;때문에&amp;nbsp;클래스&amp;nbsp;멤버라고도&amp;nbsp;함.&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp;정적&amp;nbsp;멤버&amp;nbsp;선언 &lt;br /&gt;static&amp;nbsp;키워드를&amp;nbsp;추가로&amp;nbsp;붙여&amp;nbsp;사용한다. &lt;br /&gt;정적&amp;nbsp;필드와&amp;nbsp;정적&amp;nbsp;메소드는&amp;nbsp;클래스에&amp;nbsp;고정된&amp;nbsp;멤버이므로&amp;nbsp;클래스&amp;nbsp;로더가&amp;nbsp;클래스(바이트&amp;nbsp;코드)를&amp;nbsp;로딩해서 &lt;br /&gt;메소드&amp;nbsp;메모리&amp;nbsp;영역에&amp;nbsp;적재할&amp;nbsp;때&amp;nbsp;클래스별로&amp;nbsp;관리된다.&amp;nbsp;따라서&amp;nbsp;클래스의&amp;nbsp;로딩이&amp;nbsp;끝나면&amp;nbsp;바로&amp;nbsp;사용할&amp;nbsp;수&amp;nbsp;있다. &lt;br /&gt;&lt;br /&gt;정적필드&amp;nbsp;선언&amp;nbsp;판단&amp;nbsp;기준은 &lt;br /&gt;객체마다&amp;nbsp;가지고&amp;nbsp;있어야&amp;nbsp;할&amp;nbsp;데이터라면&amp;nbsp;인스턴스&amp;nbsp;필드로&amp;nbsp;선언하고, &lt;br /&gt;객체마다&amp;nbsp;가지고&amp;nbsp;있을&amp;nbsp;필요성이&amp;nbsp;없는&amp;nbsp;공용적인&amp;nbsp;데이터라면&amp;nbsp;정적&amp;nbsp;필드로&amp;nbsp;선언하는&amp;nbsp;것이&amp;nbsp;좋다. &lt;br /&gt;ex)&amp;nbsp;파이(3.14)는&amp;nbsp;객체마다&amp;nbsp;가지고&amp;nbsp;있을&amp;nbsp;필요가&amp;nbsp;없는&amp;nbsp;변하지&amp;nbsp;않는&amp;nbsp;공용적인&amp;nbsp;데이터이므로&amp;nbsp;정적&amp;nbsp;필드로&amp;nbsp;선언하는&amp;nbsp;것이&amp;nbsp;좋음 &lt;br /&gt;&lt;br /&gt;정적메소드&amp;nbsp;선언&amp;nbsp;판단&amp;nbsp;기준은 &lt;br /&gt;인스턴스&amp;nbsp;필드를&amp;nbsp;이용해서&amp;nbsp;실행해야&amp;nbsp;한다면&amp;nbsp;인스턴스&amp;nbsp;메소드로&amp;nbsp;선언하고, &lt;br /&gt;인스턴스&amp;nbsp;필드를&amp;nbsp;이용하지&amp;nbsp;않는다면&amp;nbsp;정적메소드로&amp;nbsp;선언한다. &lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;정적&amp;nbsp;멤버&amp;nbsp;사용 &lt;br /&gt;클래스가&amp;nbsp;메모리로&amp;nbsp;로딩되면&amp;nbsp;정적&amp;nbsp;멤버&amp;nbsp;바로&amp;nbsp;사용&amp;nbsp;가능. &lt;br /&gt;클래스&amp;nbsp;이름과&amp;nbsp;함께&amp;nbsp;도트(.)&amp;nbsp;연산자로&amp;nbsp;접근함 &lt;br /&gt;클래스.필드; &lt;br /&gt;클래스.메소드(매개값); &lt;br /&gt;&lt;br /&gt;정적필드와&amp;nbsp;정적&amp;nbsp;메소드는&amp;nbsp;객체&amp;nbsp;참조&amp;nbsp;변수로도&amp;nbsp;접근이&amp;nbsp;가능하지만,&amp;nbsp;클래스&amp;nbsp;이름으로&amp;nbsp;접근하는&amp;nbsp;것이&amp;nbsp;좋다. &lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;정적&amp;nbsp;초기화&amp;nbsp;블록 &lt;br /&gt;정적&amp;nbsp;필드는&amp;nbsp;필드&amp;nbsp;선언과&amp;nbsp;동시에&amp;nbsp;초기값을&amp;nbsp;준다. &lt;br /&gt;계산이&amp;nbsp;필요한&amp;nbsp;초기화&amp;nbsp;작업이&amp;nbsp;있을&amp;nbsp;경우&amp;nbsp;정적&amp;nbsp;블록(static&amp;nbsp;block)을&amp;nbsp;사용한다. &lt;br /&gt;static&amp;nbsp;{ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;... &lt;br /&gt;} &lt;br /&gt;정적&amp;nbsp;블록은&amp;nbsp;클래스가&amp;nbsp;메모리로&amp;nbsp;로딩될&amp;nbsp;때&amp;nbsp;자동적으로&amp;nbsp;실행됨. &lt;br /&gt;정적블록은&amp;nbsp;클래스&amp;nbsp;내부에&amp;nbsp;여러&amp;nbsp;개가&amp;nbsp;선언되어도&amp;nbsp;상관없음. &lt;br /&gt;&lt;br /&gt;4.&amp;nbsp;정적&amp;nbsp;메소드와&amp;nbsp;블록&amp;nbsp;선언&amp;nbsp;시&amp;nbsp;주의할&amp;nbsp;점 &lt;br /&gt;객체가&amp;nbsp;없어도&amp;nbsp;실행된다는&amp;nbsp;특징&amp;nbsp;때무에,&amp;nbsp;이들&amp;nbsp;내부에&amp;nbsp;인스턴스&amp;nbsp;필드나&amp;nbsp;인스턴스&amp;nbsp;메소드를&amp;nbsp;사용할&amp;nbsp;수&amp;nbsp;없음. &lt;br /&gt;또한&amp;nbsp;this&amp;nbsp;키워드도&amp;nbsp;사용&amp;nbsp;불가능 &lt;br /&gt;정적&amp;nbsp;메소드와&amp;nbsp;정적&amp;nbsp;블록에서&amp;nbsp;인스턴스&amp;nbsp;멤버를&amp;nbsp;사용하고&amp;nbsp;싶다면&amp;nbsp;객체를&amp;nbsp;먼저&amp;nbsp;생성하고&amp;nbsp;참조&amp;nbsp;변수로&amp;nbsp;접근해야함.&lt;/p&gt;</description>
      <category>개발레시피/└ 언어</category>
      <category>Java</category>
      <category>OOP</category>
      <category>객체지향</category>
      <category>객체지향프로그래밍</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/120</guid>
      <comments>https://beenlife.tistory.com/120#entry120comment</comments>
      <pubDate>Thu, 25 Feb 2021 17:40:18 +0900</pubDate>
    </item>
    <item>
      <title>Generator based AI 개선</title>
      <link>https://beenlife.tistory.com/119</link>
      <description>&lt;p data-ke-size=&quot;size18&quot;&gt;&lt;br /&gt;1. BERT Embedding 방식의 필요성 &lt;br /&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;-&amp;nbsp;one-hot&amp;nbsp;encoding&amp;nbsp;embedding&amp;nbsp;방식&amp;nbsp;:&amp;nbsp;text를&amp;nbsp;벡터로&amp;nbsp;바꿔주지만&amp;nbsp;단어간&amp;nbsp;유사도를&amp;nbsp;측정하기&amp;nbsp;어렵고,&amp;nbsp;희귀&amp;nbsp;단어,&amp;nbsp;이름,&amp;nbsp;숫자나&amp;nbsp;단어장에&amp;nbsp;없는&amp;nbsp;단어에&amp;nbsp;대한&amp;nbsp;학습에&amp;nbsp;어려움이&amp;nbsp;존재 &lt;br /&gt;-&amp;nbsp;이로&amp;nbsp;인해&amp;nbsp;OOV&amp;nbsp;(out&amp;nbsp;of&amp;nbsp;vocabulary)&amp;nbsp;문제&amp;nbsp;발생 &lt;br /&gt;-&amp;nbsp;사전에&amp;nbsp;training&amp;nbsp;하지&amp;nbsp;않은&amp;nbsp;label이&amp;nbsp;input으로&amp;nbsp;들어올&amp;nbsp;경우&amp;nbsp;OOV&amp;nbsp;문제로&amp;nbsp;예측을&amp;nbsp;정상적으로&amp;nbsp;하지&amp;nbsp;못하는&amp;nbsp;현상 &lt;br /&gt;-&amp;nbsp;따라서&amp;nbsp;미등록&amp;nbsp;단어&amp;nbsp;(OOV)&amp;nbsp;문제에&amp;nbsp;대해&amp;nbsp;해결하고자&amp;nbsp;embedding&amp;nbsp;방식을&amp;nbsp;변경할&amp;nbsp;필요가&amp;nbsp;있었음. &lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;BERT&amp;nbsp;Embedding&amp;nbsp;방식? &lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;-&amp;nbsp;구글에서&amp;nbsp;개발한&amp;nbsp;NLP&amp;nbsp;사전&amp;nbsp;훈련&amp;nbsp;기술이며,&amp;nbsp;특정&amp;nbsp;분야에&amp;nbsp;국한된&amp;nbsp;기술이&amp;nbsp;아니라&amp;nbsp;모든&amp;nbsp;자연어&amp;nbsp;처리&amp;nbsp;분야에서&amp;nbsp;좋은&amp;nbsp;성능을&amp;nbsp;내는&amp;nbsp;범용&amp;nbsp;Language&amp;nbsp;Model임 &lt;br /&gt;-&amp;nbsp;Word&amp;nbsp;Piece&amp;nbsp;임베딩&amp;nbsp;방식&amp;nbsp;:&amp;nbsp;자주&amp;nbsp;등장하는&amp;nbsp;sub-word는&amp;nbsp;그&amp;nbsp;자체&amp;nbsp;단위가&amp;nbsp;되고,&amp;nbsp;자주&amp;nbsp;등장하지&amp;nbsp;않는&amp;nbsp;단어(rare&amp;nbsp;word)는&amp;nbsp;sub-word로&amp;nbsp;쪼개짐. &lt;br /&gt;-&amp;nbsp;Word&amp;nbsp;Piece&amp;nbsp;임베딩은&amp;nbsp;모든&amp;nbsp;언어에&amp;nbsp;적용&amp;nbsp;가능하며,&amp;nbsp;sub-word&amp;nbsp;단위로&amp;nbsp;단어를&amp;nbsp;분절.&amp;nbsp;OOV&amp;nbsp;처리에&amp;nbsp;효과적이고&amp;nbsp;정확도&amp;nbsp;상승효과도&amp;nbsp;있음. &lt;br /&gt;-&amp;nbsp;단어장에&amp;nbsp;없는&amp;nbsp;단어,&amp;nbsp;희귀&amp;nbsp;단어&amp;nbsp;등이&amp;nbsp;label&amp;nbsp;값으로&amp;nbsp;등장하여도&amp;nbsp;사전에&amp;nbsp;훈련했던&amp;nbsp;단어장을&amp;nbsp;참조하여&amp;nbsp;유사한&amp;nbsp;단어&amp;nbsp;묶음을&amp;nbsp;조회해&amp;nbsp;예측&amp;nbsp;가능 &lt;br /&gt;&amp;nbsp;&amp;nbsp;(ex:&amp;nbsp;phone&amp;nbsp;number&amp;nbsp;name&amp;nbsp;&amp;rarr;&amp;nbsp;smartphone&amp;nbsp;numbers&amp;nbsp;name&amp;nbsp;예측&amp;nbsp;가능) &lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;Beam&amp;nbsp;Search&amp;nbsp;알고리즘의&amp;nbsp;필요성 &lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;-&amp;nbsp;모델이&amp;nbsp;달라지지&amp;nbsp;않는&amp;nbsp;한&amp;nbsp;계속&amp;nbsp;같은&amp;nbsp;값을&amp;nbsp;예측함 &lt;br /&gt;&amp;nbsp;&amp;nbsp;ex)&amp;nbsp;&quot;test&quot;라는&amp;nbsp;단어를&amp;nbsp;예측하도록&amp;nbsp;훈련시켰다면&amp;nbsp;계속&amp;nbsp;&quot;test&quot;&amp;nbsp;값만&amp;nbsp;예측함. &lt;br /&gt;&amp;nbsp;&amp;nbsp;이유&amp;nbsp;:&amp;nbsp;특정&amp;nbsp;문자&amp;nbsp;다음에&amp;nbsp;오는&amp;nbsp;문자를&amp;nbsp;확률이&amp;nbsp;가장&amp;nbsp;높은&amp;nbsp;글자를&amp;nbsp;매번&amp;nbsp;선택하기&amp;nbsp;때문&amp;nbsp;(greedy&amp;nbsp;방식) &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;4.&amp;nbsp;Beam-Search? &lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;-&amp;nbsp;Beam-Search&amp;nbsp;:&amp;nbsp;매&amp;nbsp;스탭마다&amp;nbsp;beam&amp;nbsp;갯수만큼&amp;nbsp;후보를&amp;nbsp;유지하면서&amp;nbsp;서치를&amp;nbsp;하는&amp;nbsp;방식 &lt;br /&gt;-&amp;nbsp;모든&amp;nbsp;후보가&amp;nbsp;&amp;lt;eos&amp;gt;로&amp;nbsp;마무리될&amp;nbsp;때까지&amp;nbsp;가장&amp;nbsp;확률이&amp;nbsp;높은&amp;nbsp;K개의&amp;nbsp;후보군을&amp;nbsp;유지함. &lt;br /&gt;-&amp;nbsp;따라서&amp;nbsp;형식에&amp;nbsp;맞는&amp;nbsp;다양한&amp;nbsp;값&amp;nbsp;생성이&amp;nbsp;가능함&amp;nbsp;(ex:&amp;nbsp;예측값&amp;nbsp;2020-07-28&amp;nbsp;외에&amp;nbsp;2020-07-30,&amp;nbsp;2020-07-29&amp;nbsp;으로&amp;nbsp;예측&amp;nbsp;가능) &lt;br /&gt;&lt;br /&gt;5.&amp;nbsp;BERT&amp;nbsp;상세보기 &lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;-&amp;nbsp;BERT(Bidirectional&amp;nbsp;Encoder&amp;nbsp;Representations&amp;nbsp;from&amp;nbsp;Transformers) &lt;br /&gt;-&amp;nbsp;18년&amp;nbsp;10월에&amp;nbsp;논문이&amp;nbsp;공개된&amp;nbsp;구글의&amp;nbsp;새로운&amp;nbsp;Language&amp;nbsp;Representation&amp;nbsp;Model임. &lt;br /&gt;-&amp;nbsp;NLP의&amp;nbsp;11개&amp;nbsp;테스크에&amp;nbsp;최고&amp;nbsp;성능을&amp;nbsp;기록함 &lt;br /&gt;-&amp;nbsp;text&amp;nbsp;=&amp;nbsp;&quot;Here&amp;nbsp;is&amp;nbsp;the&amp;nbsp;sentence&amp;nbsp;I&amp;nbsp;want&amp;nbsp;embeddings&amp;nbsp;for.&quot; &lt;br /&gt;&amp;nbsp;&amp;nbsp;['[CLS]',&amp;nbsp;'here',&amp;nbsp;'is',&amp;nbsp;'the',&amp;nbsp;'sentence',&amp;nbsp;'i',&amp;nbsp;'want',&amp;nbsp;'em',&amp;nbsp;'##bed',&amp;nbsp;'##ding',&amp;nbsp;'##s',&amp;nbsp;'for',&amp;nbsp;'.',&amp;nbsp;'[SEP]'] &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;.&amp;nbsp;original&amp;nbsp;word가&amp;nbsp;subword로&amp;nbsp;쪼개짐 &lt;br /&gt;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&quot;##bed&quot;는&amp;nbsp;어떤&amp;nbsp;단어의&amp;nbsp;일부,&amp;nbsp;subword라는&amp;nbsp;뜻.&amp;nbsp;독립적인&amp;nbsp;단어&amp;nbsp;&quot;bed&quot;랑&amp;nbsp;다르다는&amp;nbsp;것을&amp;nbsp;보여주기&amp;nbsp;위해 &lt;br /&gt;&amp;nbsp;&amp;nbsp;.&amp;nbsp;전체&amp;nbsp;단어가&amp;nbsp;BERT&amp;nbsp;vocab에&amp;nbsp;없으면&amp;nbsp;subword로&amp;nbsp;쪼갬&amp;nbsp;(vocab에서&amp;nbsp;찾을&amp;nbsp;때까지&amp;nbsp;쪼갬).&amp;nbsp;끝까지&amp;nbsp;못&amp;nbsp;찾으면&amp;nbsp;철자&amp;nbsp;하나씩까지&amp;nbsp;쪼갬&lt;/p&gt;</description>
      <category>개발레시피/└ 머신러닝</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/119</guid>
      <comments>https://beenlife.tistory.com/119#entry119comment</comments>
      <pubDate>Wed, 16 Dec 2020 17:13:19 +0900</pubDate>
    </item>
    <item>
      <title>Generator based AI</title>
      <link>https://beenlife.tistory.com/118</link>
      <description>&lt;p&gt;Generator&amp;nbsp;based&amp;nbsp;AI &lt;br /&gt;&lt;br /&gt;1.&amp;nbsp;Approach &lt;br /&gt;-&amp;nbsp;tf-idf로&amp;nbsp;추출한&amp;nbsp;label값과&amp;nbsp;value의&amp;nbsp;시작&amp;nbsp;글자를&amp;nbsp;입력받아&amp;nbsp;첫&amp;nbsp;번째&amp;nbsp;글자를&amp;nbsp;예측 &lt;br /&gt;-&amp;nbsp;이&amp;nbsp;글자를&amp;nbsp;다시&amp;nbsp;반복해서&amp;nbsp;모델에&amp;nbsp;집어넣어&amp;nbsp;두&amp;nbsp;번째&amp;nbsp;글자를&amp;nbsp;예측 &lt;br /&gt;-&amp;nbsp;이&amp;nbsp;과정을&amp;nbsp;&quot;eos&quot;가&amp;nbsp;출력될&amp;nbsp;때까지&amp;nbsp;반복 &lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;Dataset &lt;br /&gt;-&amp;nbsp;value:&amp;nbsp;target&amp;nbsp;value &lt;br /&gt;-&amp;nbsp;label:&amp;nbsp;mobile&amp;nbsp;element의&amp;nbsp;tf-idf로&amp;nbsp;라벨링한&amp;nbsp;대표값 &lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;Embedding &lt;br /&gt;-&amp;nbsp;기존:&amp;nbsp;label값에&amp;nbsp;대하여&amp;nbsp;one&amp;nbsp;hot&amp;nbsp;encoding&amp;nbsp;사용 &lt;br /&gt;-&amp;nbsp;one&amp;nbsp;hot의&amp;nbsp;단점:&amp;nbsp;text를&amp;nbsp;숫자로&amp;nbsp;바꿔주지만&amp;nbsp;단어간&amp;nbsp;유사도를&amp;nbsp;측정하기&amp;nbsp;어려움 &lt;br /&gt;-&amp;nbsp;또한&amp;nbsp;미등록&amp;nbsp;단어(out&amp;nbsp;of&amp;nbsp;vocabulary)문제&amp;nbsp;발생 &lt;br /&gt;-&amp;nbsp;따라서&amp;nbsp;BERT&amp;nbsp;model을&amp;nbsp;사용하기로함. &lt;br /&gt;&lt;br /&gt;4.&amp;nbsp;Classifier &lt;br /&gt;-&amp;nbsp;LSTM에서&amp;nbsp;처리한&amp;nbsp;결과를&amp;nbsp;바탕으로&amp;nbsp;다음&amp;nbsp;글자가&amp;nbsp;무엇이&amp;nbsp;될&amp;nbsp;지&amp;nbsp;예측 &lt;br /&gt;&lt;br /&gt;5.&amp;nbsp;Training &lt;br /&gt;-&amp;nbsp;MatricCalculator:&amp;nbsp;학습/검증&amp;nbsp;데이터에&amp;nbsp;대한&amp;nbsp;정확도를&amp;nbsp;기록 &lt;br /&gt;-&amp;nbsp;save_checkpoint:&amp;nbsp;모델의&amp;nbsp;파라미터를&amp;nbsp;파일로&amp;nbsp;저장 &lt;br /&gt;-&amp;nbsp;load_checkpoint:&amp;nbsp;저장한&amp;nbsp;모델&amp;nbsp;파라미터를&amp;nbsp;불러와&amp;nbsp;모델에&amp;nbsp;씌움 &lt;br /&gt;-&amp;nbsp;save_dict_to_json:&amp;nbsp;모델의&amp;nbsp;학습경과를&amp;nbsp;json&amp;nbsp;파일로&amp;nbsp;저장 &lt;br /&gt;&lt;br /&gt;6.&amp;nbsp;Beam-Search &lt;br /&gt;-&amp;nbsp;매&amp;nbsp;스탭마다&amp;nbsp;beam&amp;nbsp;갯수(K)만큼&amp;nbsp;후보를&amp;nbsp;유지하면서&amp;nbsp;서치를&amp;nbsp;하는&amp;nbsp;방식 &lt;br /&gt;-&amp;nbsp;K&amp;nbsp;개의&amp;nbsp;예측한&amp;nbsp;후보값&amp;nbsp;중&amp;nbsp;random&amp;nbsp;한&amp;nbsp;값을&amp;nbsp;return하도록&amp;nbsp;개선&amp;nbsp;(다양한&amp;nbsp;input&amp;nbsp;data&amp;nbsp;제공을&amp;nbsp;위해)&lt;/p&gt;</description>
      <category>개발레시피/└ 머신러닝</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/118</guid>
      <comments>https://beenlife.tistory.com/118#entry118comment</comments>
      <pubDate>Wed, 16 Dec 2020 17:02:11 +0900</pubDate>
    </item>
    <item>
      <title>Object Detection</title>
      <link>https://beenlife.tistory.com/116</link>
      <description>&lt;h2 data-ke-size=&quot;size26&quot;&gt;1.&amp;nbsp;Object&amp;nbsp;Detection이란?&lt;/h2&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&lt;br /&gt;Object&amp;nbsp;Detection은&amp;nbsp;Image&amp;nbsp;Classification&amp;nbsp;task에&amp;nbsp;사물의&amp;nbsp;위치를&amp;nbsp;Bounding&amp;nbsp;Box로&amp;nbsp;예측하는&amp;nbsp;Regression&amp;nbsp;task가&amp;nbsp;추가된&amp;nbsp;문제! &lt;br /&gt;&lt;br /&gt;multi-labeled&amp;nbsp;classification&amp;nbsp;:&amp;nbsp;한&amp;nbsp;이미지에&amp;nbsp;여러&amp;nbsp;class&amp;nbsp;존재 &lt;br /&gt;&lt;br /&gt;boounding&amp;nbsp;box&amp;nbsp;regression&amp;nbsp;:&amp;nbsp;box의&amp;nbsp;좌표&amp;nbsp;값을&amp;nbsp;예측 &lt;br /&gt;&lt;br /&gt;따라서&amp;nbsp;Object&amp;nbsp;Detection&amp;nbsp;=&amp;nbsp;Multi-labeled&amp;nbsp;Classification&amp;nbsp;+&amp;nbsp;Bounding&amp;nbsp;Box&amp;nbsp;Regression &lt;/p&gt;
&lt;h2 data-ke-size=&quot;size26&quot;&gt;2. Sliding Window &lt;/h2&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&lt;br /&gt;다양한&amp;nbsp;scale의&amp;nbsp;window를&amp;nbsp;이미지의&amp;nbsp;왼쪽&amp;nbsp;위부터&amp;nbsp;오른쪽&amp;nbsp;아래까지&amp;nbsp;sliding하며&amp;nbsp;score를&amp;nbsp;계산하는&amp;nbsp;방법을&amp;nbsp;의미. &lt;br /&gt;하나의&amp;nbsp;이미지에서&amp;nbsp;여러번&amp;nbsp;score를&amp;nbsp;계산하여야&amp;nbsp;하므로&amp;nbsp;속도&amp;nbsp;측면에서&amp;nbsp;비효율적 &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 data-ke-size=&quot;size26&quot;&gt;3.&amp;nbsp;Selective&amp;nbsp;Search&amp;nbsp;(SS) &lt;br /&gt;&lt;br /&gt;&lt;/h2&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;영상의&amp;nbsp;계층적&amp;nbsp;구조를&amp;nbsp;활용하여&amp;nbsp;영역을&amp;nbsp;탐색하고&amp;nbsp;그룹화하는&amp;nbsp;과정을&amp;nbsp;반복하며&amp;nbsp;객체의&amp;nbsp;위치를&amp;nbsp;proposal&amp;nbsp;해주는&amp;nbsp;기능을&amp;nbsp;수행 &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 data-ke-size=&quot;size26&quot;&gt;4. R-CNN? &lt;/h2&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&lt;br /&gt;Object&amp;nbsp;Detection에&amp;nbsp;CNN을&amp;nbsp;적용한&amp;nbsp;첫&amp;nbsp;논문으로,&amp;nbsp;Selective&amp;nbsp;Search와&amp;nbsp;CNN을&amp;nbsp;결합한&amp;nbsp;방법론 &lt;br /&gt;&lt;br /&gt;input&amp;nbsp;image가&amp;nbsp;있으면&amp;nbsp;Selective&amp;nbsp;Search를&amp;nbsp;통해&amp;nbsp;Region&amp;nbsp;Proposal을&amp;nbsp;수행함. &lt;br /&gt;그&amp;nbsp;뒤&amp;nbsp;Proposal된&amp;nbsp;영역들을&amp;nbsp;CNN의&amp;nbsp;고정&amp;nbsp;사이즈를&amp;nbsp;가지는&amp;nbsp;입력으로&amp;nbsp;변환시키고,&amp;nbsp;각&amp;nbsp;영역마다&amp;nbsp;Classification을&amp;nbsp;수행하는&amp;nbsp;방식으로&amp;nbsp;되어있음. &lt;br /&gt;또한&amp;nbsp;Proposal된&amp;nbsp;Region에서&amp;nbsp;실제&amp;nbsp;object&amp;nbsp;위치와&amp;nbsp;가까워지도록&amp;nbsp;보정해주는&amp;nbsp;Regression도&amp;nbsp;수행됨. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;1-Stage&amp;nbsp;Object&amp;nbsp;Detector&lt;/b&gt;&amp;nbsp;:&amp;nbsp;탐색&amp;nbsp;영역을&amp;nbsp;찾는&amp;nbsp;Region&amp;nbsp;Proposal과&amp;nbsp;해당&amp;nbsp;영역을&amp;nbsp;분류하는&amp;nbsp;Detection&amp;nbsp;두&amp;nbsp;가지&amp;nbsp;과정을&amp;nbsp;한번에&amp;nbsp;처리하는&amp;nbsp;방법론 &lt;br /&gt;-&amp;nbsp;SSD,&amp;nbsp;YOLO &lt;br /&gt;-&amp;nbsp;빠르지만&amp;nbsp;부정확하다 &lt;br /&gt;&lt;br /&gt;&lt;b&gt;2-Stage&amp;nbsp;Object&amp;nbsp;Detector&lt;/b&gt;&amp;nbsp;:&amp;nbsp;두&amp;nbsp;가지&amp;nbsp;과정이&amp;nbsp;순차적으로&amp;nbsp;수행되는&amp;nbsp;방법론 &lt;br /&gt;-&amp;nbsp;Fast&amp;nbsp;R-CNN,&amp;nbsp;Faster&amp;nbsp;R-CNN &lt;br /&gt;-&amp;nbsp;비교적&amp;nbsp;느리지만&amp;nbsp;정확하다 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>개발레시피/└ 머신러닝</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/116</guid>
      <comments>https://beenlife.tistory.com/116#entry116comment</comments>
      <pubDate>Fri, 4 Sep 2020 17:49:15 +0900</pubDate>
    </item>
    <item>
      <title>[Android] adb 자주쓰는 명령어 모음 / adb 명령어로 APK 추출</title>
      <link>https://beenlife.tistory.com/115</link>
      <description>&lt;p&gt;1. adb shell 실행&lt;/p&gt;
&lt;p&gt;#adb shell&lt;/p&gt;
&lt;p&gt;2. 설치된 패키지 검색&lt;/p&gt;
&lt;p&gt;$pm list packages -f&lt;/p&gt;
&lt;p&gt;특정 단어를 포함한 package 찾기&lt;/p&gt;
&lt;p&gt;$pm list packages -f|grep &quot;검색어&quot;&lt;/p&gt;
&lt;p&gt;3. apk 추출하기&lt;/p&gt;
&lt;p&gt;ex)package:&lt;span style=&quot;color: #ee2323;&quot;&gt;/data/app/com.example.app-1.apk&lt;/span&gt;=com.example.app&lt;/p&gt;
&lt;p&gt;위 검색 결과 중 빨간색 문자만 쓴다.&lt;/p&gt;
&lt;p&gt;#adb pull /data/app/~~~~.apk downloaded.apk&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4. 현재 실행중인 application name 가져오기&lt;/p&gt;
&lt;p&gt;#&lt;span&gt;adb shell dumpsys window windows &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; find &lt;/span&gt;&lt;span&gt;&quot;mCurrentFocus&quot;&lt;/span&gt;&lt;/p&gt;</description>
      <category>개발레시피/└ 유틸</category>
      <category>ADB</category>
      <category>Android</category>
      <category>APK추출</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/115</guid>
      <comments>https://beenlife.tistory.com/115#entry115comment</comments>
      <pubDate>Tue, 7 Jan 2020 15:54:52 +0900</pubDate>
    </item>
    <item>
      <title>단일 스레드와 멀티 스레드</title>
      <link>https://beenlife.tistory.com/114</link>
      <description>&lt;h2&gt;단일 스레드와 멀티 스레드&lt;/h2&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;스레드란?&lt;/h3&gt;&lt;p&gt;스레드는 CPU의 이용의 기본 단위다.&lt;/p&gt;&lt;p&gt;프로세스 내에서 프로그램 명령을 실행하는 기본 단위이자 흐름, 개체라고 할 수 있다.&lt;/p&gt;&lt;p&gt;스레드는 스레드 ID, 프로그램 카운터, 레지스터 집합, 스택 으로 구성된다.&lt;/p&gt;&lt;p&gt;스레드는 같은 프로세스에 속한 다른 스레드와 코드, 데이터 섹션, 열린 파일이나 신호와 같은 운영체제 자원들을 공유한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;프로세스에 하나의 제어 모델이 있으면 단일 스레드이며,&lt;/p&gt;&lt;p&gt;프로세스가 다수의 제어 스레드를 가진다면 다중 스레드 모델이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;단일 스레드&lt;/h3&gt;&lt;p&gt;- 하나의 프로세스에서 하나의 스레드 실행&lt;/p&gt;&lt;p&gt;- 하나의 레지스터와 스택으로 표현&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;멀티 스레드&lt;/h3&gt;&lt;p&gt;- 프로그램을 다수의 실행 단위로 나누어 실행&lt;/p&gt;&lt;p&gt;- 프로세스 내에서 자원을 공유하여 자원생성과 관리의 중복을 최소화&lt;/p&gt;&lt;p&gt;- 서버가 많은 요청을 효율적으로 수행할 수 있는 환경을 제공&lt;/p&gt;&lt;p&gt;- 각각의 스레드가 고유의 레지스터와 스택으로 표현됨&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;단일 스레드 모델&lt;/h3&gt;&lt;p&gt;다양한 요인드이 결합된 데이터에 대한 통계적 분석 연산의 경우는 멀티 스레드 모델이 더 적합하다.&lt;/p&gt;&lt;p&gt;필요한 구간에 여러 개의 스레드를 배치해 시스템 자원을 최대한 활용하여 빠르게 연산을 완료하도록 설계할 수 있다.&lt;/p&gt;&lt;p&gt;하지만 이와 같은 상황을 모든 프로그램이 맞닥뜨리는 것은 아니다.&lt;/p&gt;&lt;p&gt;요청에 대한 빠른 반응을 요구하는 네트워크 서버의 프로그램일 경우 단일 스레드 모델이 더 적합할 수도 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;단일 스레드와 멀티스레드의 장단점&lt;/h2&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;단일 스레드의 장점&lt;/h3&gt;&lt;p&gt;1) 자원 접근에 대한 동기화를 신경쓰지 않아도 된다.&lt;/p&gt;&lt;p&gt;여러 개의 스레드가 공유된 자원을 사용할 경우 각 스레드가 원하는 결과를 얻게 하려면&lt;/p&gt;&lt;p&gt;공용 자원에 대한 접근이 통제되어야 하며 이 작업은 프로그래머에게 많은 노력을 요구하고 비용을 발생시킨다.&lt;/p&gt;&lt;p&gt;단일 스레드 모델에서는 이러한 작업이 필요하지 않다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;2) 문맥 교환(context switch) 작업을 요구하지 않는다.&lt;/p&gt;&lt;p&gt;문맥 교환은 여러 개의 프로세스가 하나의 프로세서를 공유할 때 발생하는 작업으로 많은 비용을 필요로 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;단일 스레드의 단점&lt;/h3&gt;&lt;p&gt;1) 여러 개의 CPU를 활용하지 못한다.&lt;/p&gt;&lt;p&gt;프로세서를 최대한 활용하게 하려면 cluster 모듈을 사용하거나 외부에서 여러 개의 프로그램 인스턴스를 실행시키는 방법을 사용해야 한다.&lt;/p&gt;&lt;p&gt;이 때 고려해야할 문제가 있는데, 바로 다수의 프로그램 인스턴스가 어떻게 상태를 공유할 것인가에 대한 문제다.&lt;/p&gt;&lt;p&gt;사실 이것은 멀티 스레드 환경의 서버 프로그램도 확장성을 확보하기 위해 풀어야 할 숙제이긴 하다.&lt;/p&gt;&lt;p&gt;단순하고 빠른 메모리 기반 NoSQL 데이터 베이스인 Redist가 좋은 고려대상이다.&lt;/p&gt;&lt;p&gt;하지만 서버 프로그램 인스턴스 간 상태 공유를 최소화하거나 가능하면 없애는 방향으로 아키텍처를 설계하는 것이 가장 바람직한 방법이라고 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;멀티 스레드의 장점&lt;/h3&gt;&lt;p&gt;1) 새로운 프로세스를 생성하는 것보다 기존 프로세스에서 스레드를 생성하는 것이 빠르다.&lt;/p&gt;&lt;p&gt;2) 프로세스의 자원과 상태를 공유하여 효율적으로 운영이 가능하다&lt;/p&gt;&lt;p&gt;3) 프로세스의 문맥교환보다 스레드의 문맥교환이 더 빠르다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;멀티 스레드의 단점&lt;/h3&gt;&lt;p&gt;1) 하나의 스레드만 실행중일 때에는 실행시간이 되려 지연될 수 있다.&lt;/p&gt;&lt;p&gt;2) 멀티 스레딩을 위해 운영체제의 지원이 필요하다.&lt;/p&gt;&lt;p&gt;3) 스레드 스케쥴링을 신경써야 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>개발레시피/└ 유틸</category>
      <category>스레드</category>
      <category>프로세스</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/114</guid>
      <comments>https://beenlife.tistory.com/114#entry114comment</comments>
      <pubDate>Fri, 28 Dec 2018 16:16:20 +0900</pubDate>
    </item>
    <item>
      <title>[딥러닝] 로지스틱 회귀: 참 거짓의 판단 장치</title>
      <link>https://beenlife.tistory.com/113</link>
      <description>&lt;p&gt;아래 내용은 '모두의 딥러닝' 책을 스터디 하여 정리한 내용입니다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;참 거짓 판단 장치: 로지스틱 회귀&lt;/h2&gt;&lt;p&gt;참과 거짓 중에 하나를 내놓는 과정은 로지스틱 회귀의 원리를 거쳐 이루어진다.&lt;/p&gt;&lt;p&gt;참, 거짓을 구분하는 로지스틱 회귀의 원리를 이용해 '참, 거짓 미니 판단 장치'를 만들어 주어진 입력 값의 특징을 추출하고,&lt;/p&gt;&lt;p&gt;이를 저장해서 '모델'을 만든다.&lt;/p&gt;&lt;p&gt;그 후 누군가 비슷한 질문을 하면 지금까지 만들어 놓은 이 모델을 꺼내어 답을 한다.&lt;/p&gt;&lt;p&gt;이것이 바로 딥러닝의 동작 원리이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;1. 로지스틱 회귀의 정의&lt;/h3&gt;&lt;p&gt;좌표의 형태가 직선으로 해결되기에 적절하지 않은 경우도 있다.&lt;/p&gt;&lt;p&gt;예를 들어 공부한 시간에 따른 합격 여부가 있다고 해보자.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;합격을 1, 불합격을 0이라고 했을 때 이는 일차 방정식을 만들 수 있을까?&lt;/p&gt;&lt;p&gt;점들의 특성을 정확하게 담아내려면 직선이 아니라 다음과 같이 S자 형태여야 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이처럼 로지스틱 회귀는 선형 회귀와 마찬가지로&lt;/p&gt;&lt;p&gt;적절한 선을 그려가는 과정이다.&lt;/p&gt;&lt;p&gt;다만, 직선이 아니라 참(1)과 거짓(0) 사이를 구분하는 S자 형태의 선을 그어주는 작업이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;2. 시그모이드 함수&lt;/h3&gt;&lt;p&gt;이렇게 S자 형태로 그래프가 그려지는 함수가 시그모이드 함수이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;우리가 구해야 하는 값은 결국 ax+b이다.&lt;/p&gt;&lt;p&gt;앞서 구한 직선 방정식과는 다르게 여기에서 a와 b는 어떤 의미를 가지고 있을까?&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;먼저 a는 그래프의 경사도를 결정한다.&lt;/p&gt;&lt;p&gt;a값이 커지면 경사가 커지고 a값이 작아지면 경사가 작아진다.&lt;/p&gt;&lt;p&gt;b는 그래프의 좌우이동을 의미한다.&lt;/p&gt;&lt;p&gt;b가 크면 오른쪽(+)으로, 작아지면 왼쪽(-)으로 이동한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;따라서 a와 b의 값이 클수록 오차가 생긴다.&lt;/p&gt;&lt;p&gt;a가 작아질수록 오차는 무한대로 커지지만, a가 커진다고 해서 오차가 무한대로 커지지는 않는다.&lt;/p&gt;&lt;p&gt;b값은 너무 크거나 작을 경우 오차가 무한대로 커지므로 이차 함수 그래프로 표현할 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;3. 오차 공식&lt;/h3&gt;&lt;p&gt;시그모이드 함수에서 a와 b의 값을 어떻게 구할까?&lt;/p&gt;&lt;p&gt;경사하강법으로 구할 수 있다.&lt;/p&gt;&lt;p&gt;경사 하강법은 먼저 오차를 구한 다음 오차가 작은 쪽으로 이동시키는 방법이었다.&lt;/p&gt;&lt;p&gt;그렇다면 이번에도 오차를 구하는 공식이 필요한데, 오차 공식을 도출하기 위해&lt;/p&gt;&lt;p&gt;시그모이드 함수 그래프의 특징을 살펴보면,&lt;/p&gt;&lt;p&gt;y값이 0과 1 사이라는 것이다.&lt;/p&gt;&lt;p&gt;따라서 실제 값이 1일 때 예측 값이 0에 가까워지면 오차가 커져야 한다.&lt;/p&gt;&lt;p&gt;반대로 실제 값이 0일 때 예측 값이 1에 가까워지는 경우에도 오차가 커진다.&lt;/p&gt;&lt;p&gt;이를 공식으로 만들 수 있게 해 주는 함수가 바로 로그 함수이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;4. 로그 함수&lt;/h3&gt;&lt;p&gt;공식을 보면 실제 값 y가 1이면 B부분이 없어지고 0이면 A부분이 없어진다.&lt;/p&gt;&lt;p&gt;따라서 y값에 따라 각 그래프를 사용하게 된다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;5. 코딩으로 확인하기(로지스틱 회귀)&lt;/h3&gt;&lt;button type=&quot;button&quot; class=&quot;btn_more&quot; id=&quot;more113_0&quot; data-id=&quot;113_0&quot;&gt;더보기&lt;/button&gt;&lt;div class=&quot;moreless_content&quot; id=&quot;content113_0&quot; style=&quot;display: none;&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less113_0&quot; data-id=&quot;113_0&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;
  &lt;p class=&quot;txt_view&quot;&gt;&lt;div class=&quot;colorscripter-code&quot; style=&quot;color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important; overflow:auto&quot;&gt;&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin:0; padding:0; border:none; background-color:#fafafa; border-radius:4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding:6px; border-right:2px solid #e5e5e5&quot;&gt;&lt;div style=&quot;margin:0; padding:0; word-break:normal; text-align:right; color:#666; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;line-height:130%&quot;&gt;1&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;2&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;3&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;4&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;5&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;6&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;7&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;8&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;9&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;10&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;11&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;12&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;13&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;14&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;15&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;16&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;17&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;18&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;19&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;20&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;21&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;22&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;23&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;24&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;25&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;26&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;27&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;28&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;29&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;30&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;31&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;32&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;padding:6px 0&quot;&gt;&lt;div style=&quot;margin:0; padding:0; color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;tensorflow&amp;nbsp;as&amp;nbsp;tf&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;numpy&amp;nbsp;as&amp;nbsp;np&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x,y의&amp;nbsp;데이터&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;data&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;10&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;12&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;14&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x_data&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[x_row[&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;x_row&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y_data&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[y_row[&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;y_row&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;a와&amp;nbsp;b의&amp;nbsp;값을&amp;nbsp;임의로&amp;nbsp;정한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;a&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_normal([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;dtype&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;b&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_normal([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;dtype&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;y&amp;nbsp;시그모이드&amp;nbsp;함수의&amp;nbsp;방정식을&amp;nbsp;세운다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;/&lt;/span&gt;(&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;np.e&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;(&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;a&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;x_data&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;b))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;loss를&amp;nbsp;구하는&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;loss&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;tf.reduce_mean(np.array(y_data)&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&amp;nbsp;tf.log(y)&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;np.array(y_data))&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&amp;nbsp;tf.log(&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;y))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;학습률&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;learning_rate&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0.&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;5&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;loss를&amp;nbsp;최소로&amp;nbsp;하는&amp;nbsp;값&amp;nbsp;찾기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;gradient_decent&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;학습&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;with&amp;nbsp;tf.Session()&amp;nbsp;as&amp;nbsp;sess:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(tf.global_variables_initializer())&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color:#0099cc&quot;&gt;60001&lt;/span&gt;):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(gradient_decent)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;if&lt;/span&gt;&amp;nbsp;i&amp;nbsp;%&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;6000&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;Epoch:&amp;nbsp;%.f,&amp;nbsp;loss&amp;nbsp;=&amp;nbsp;%.4f,&amp;nbsp;기울기&amp;nbsp;a&amp;nbsp;=&amp;nbsp;%.4f,&amp;nbsp;y절편&amp;nbsp;=%.4f&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(i,&amp;nbsp;sess.run(loss),&amp;nbsp;sess.run(a),&amp;nbsp;sess.run(b)))&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;vertical-align:bottom; padding:0 2px 4px 0&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: white;&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: rgb(229, 229, 229); border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/p&gt;
&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less113_0&quot; data-id=&quot;113_0&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;p&gt;오차(loss)값이 점점 줄어들고 a와 b의 최적값을 찾아가는 것을 볼 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;6. 여러 입력 값을 갖는 로지스틱 회귀&lt;/h3&gt;&lt;p&gt;선형 회귀때와 마찬가지로 변수가 많아지면 더 정확하게 예측을 할 수 있다.&lt;/p&gt;&lt;p&gt;변수가 x에서 x1, x2로 추가되면 각각의 기울기 a1, a2도 계산해야 한다.&lt;/p&gt;&lt;p&gt;즉 ax부분이 a1x1 + a2x2로 바뀐다. 이는 행렬곱을 이용해 [a1, a2] * [x1, x2] 로도 표현할 수 있다.&lt;/p&gt;&lt;p&gt;텐서플로에서는 matmul() 함수를 이용해 행렬곱을 적용할 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;button type=&quot;button&quot; class=&quot;btn_more&quot; id=&quot;more113_1&quot; data-id=&quot;113_1&quot;&gt;더보기&lt;/button&gt;&lt;div class=&quot;moreless_content&quot; id=&quot;content113_1&quot; style=&quot;display: none;&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less113_1&quot; data-id=&quot;113_1&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;
  &lt;p class=&quot;txt_view&quot;&gt;&lt;div class=&quot;colorscripter-code&quot; style=&quot;color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important; overflow:auto&quot;&gt;&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin:0; padding:0; border:none; background-color:#fafafa; border-radius:4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding:6px; border-right:2px solid #e5e5e5&quot;&gt;&lt;div style=&quot;margin:0; padding:0; word-break:normal; text-align:right; color:#666; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;line-height:130%&quot;&gt;1&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;2&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;3&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;4&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;5&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;6&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;7&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;8&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;9&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;10&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;11&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;12&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;13&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;14&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;15&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;16&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;17&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;18&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;19&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;20&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;21&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;22&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;23&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;24&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;25&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;26&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;27&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;28&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;29&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;30&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;31&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;32&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;33&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;34&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;35&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;36&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;37&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;38&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;39&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;40&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;41&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;42&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;43&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;44&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;45&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;46&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;47&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;48&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;49&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;50&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;51&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;52&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;53&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;padding:6px 0&quot;&gt;&lt;div style=&quot;margin:0; padding:0; color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;tensorflow&amp;nbsp;as&amp;nbsp;tf&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;numpy&amp;nbsp;as&amp;nbsp;np&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;실행할&amp;nbsp;때마다&amp;nbsp;같은&amp;nbsp;결과를&amp;nbsp;출력하기&amp;nbsp;위한&amp;nbsp;seed값&amp;nbsp;설정&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;seed&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;np.random.seed(seed)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;tf.set_random_seed(seed)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x,y의&amp;nbsp;데이터&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x_data&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;np.array([[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;3&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;3&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;10&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;7&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;12&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;14&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;9&lt;/span&gt;]])&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y_data&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;np.array([&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]).reshape(&lt;span style=&quot;color:#0099cc&quot;&gt;7&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;입력&amp;nbsp;값을&amp;nbsp;플레이스&amp;nbsp;홀더에&amp;nbsp;저장&amp;nbsp;(플레이스홀더는&amp;nbsp;입력&amp;nbsp;값을&amp;nbsp;저장하는&amp;nbsp;일종의&amp;nbsp;그릇이다)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;X&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.placeholder(tf.float64,&amp;nbsp;shape&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;[None,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;])&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;Y&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.placeholder(tf.float64,&amp;nbsp;shape&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;[None,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;])&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;a와&amp;nbsp;b의&amp;nbsp;값을&amp;nbsp;임의로&amp;nbsp;정한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;a&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;dtype&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;tf.float64))&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;[2,1]&amp;nbsp;의미&amp;nbsp;:&amp;nbsp;들어오는&amp;nbsp;값은&amp;nbsp;2개,&amp;nbsp;나가는&amp;nbsp;값은&amp;nbsp;1개&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;b&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;dtype&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;tf.float64))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;y&amp;nbsp;시그모이드&amp;nbsp;함수의&amp;nbsp;방정식을&amp;nbsp;세운다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;변수가&amp;nbsp;x에서&amp;nbsp;x1,&amp;nbsp;x2로&amp;nbsp;추가되면&amp;nbsp;각각의&amp;nbsp;기울기&amp;nbsp;a1,&amp;nbsp;a2도&amp;nbsp;계산해야&amp;nbsp;한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;즉&amp;nbsp;ax부분이&amp;nbsp;a1x1&amp;nbsp;+&amp;nbsp;a2x2로&amp;nbsp;바뀐다.&amp;nbsp;이는&amp;nbsp;행렬곱을&amp;nbsp;이용해&amp;nbsp;[a1,&amp;nbsp;a2]&amp;nbsp;*&amp;nbsp;[x1,&amp;nbsp;x2]&amp;nbsp;로도&amp;nbsp;표현할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;텐서플로에서는&amp;nbsp;matmul()&amp;nbsp;함수를&amp;nbsp;이용해&amp;nbsp;행렬곱을&amp;nbsp;적용할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.sigmoid(tf.matmul(X,&amp;nbsp;a)&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;b)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;loss를&amp;nbsp;구하는&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;loss&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;tf.reduce_mean(Y&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&amp;nbsp;tf.log(y)&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;Y)&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&amp;nbsp;tf.log(&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;y))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;학습률&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;learning_rate&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0.&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;loss를&amp;nbsp;최소로&amp;nbsp;하는&amp;nbsp;값&amp;nbsp;찾기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;gradient_decent&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;predicted&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.cast(y&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0.&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;5&lt;/span&gt;,&amp;nbsp;dtype&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;tf.float64)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;accuracy&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.reduce_mean(tf.cast(tf.equal(predicted,&amp;nbsp;Y),&amp;nbsp;dtype&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;tf.float64))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;학습&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;with&amp;nbsp;tf.Session()&amp;nbsp;as&amp;nbsp;sess:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(tf.global_variables_initializer())&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color:#0099cc&quot;&gt;3001&lt;/span&gt;):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a_,&amp;nbsp;b_,&amp;nbsp;loss_,&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;sess.run([a,&amp;nbsp;b,&amp;nbsp;loss,&amp;nbsp;gradient_decent],&amp;nbsp;feed_dict&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;{X:&amp;nbsp;x_data,&amp;nbsp;Y:&amp;nbsp;y_data})&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;if&lt;/span&gt;&amp;nbsp;(i&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;)&amp;nbsp;%&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;300&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;step=%d,&amp;nbsp;a1=%.4f,&amp;nbsp;a2=%.4f,&amp;nbsp;b=%4f,&amp;nbsp;loss=%.4f&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(i&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;,&amp;nbsp;a_[&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;],&amp;nbsp;a_[&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;b_,&amp;nbsp;loss_))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;실제&amp;nbsp;값&amp;nbsp;적용하기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_x&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;np.array([&lt;span style=&quot;color:#0099cc&quot;&gt;7&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;6.&lt;/span&gt;]).reshape(&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;)&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;7,&amp;nbsp;6은&amp;nbsp;각각&amp;nbsp;공부한&amp;nbsp;시간과&amp;nbsp;과외&amp;nbsp;수업&amp;nbsp;수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_y&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;sess.run(y,&amp;nbsp;feed_dict&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;{X:&amp;nbsp;new_x})&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;공부한&amp;nbsp;시간&amp;nbsp;:&amp;nbsp;%d,&amp;nbsp;과외&amp;nbsp;수업&amp;nbsp;횟수:&amp;nbsp;%d&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(new_x[:,&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;],&amp;nbsp;new_x[:,&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;합격&amp;nbsp;가능성:&amp;nbsp;%6.2f&amp;nbsp;%%&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(new_y&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;100&lt;/span&gt;))&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align:right; margin-top:-13px; margin-right:5px; font-size:9px; font-style:italic&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: rgb(229, 229, 229);&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;vertical-align:bottom; padding:0 2px 4px 0&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: white;&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: rgb(229, 229, 229); border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/p&gt;
&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less113_1&quot; data-id=&quot;113_1&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;오차 값이 점차 줄어들고 a1, a2, b가 각각 최적값을 찾아가는 것을 알 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;7. 실제 값 적용하기&lt;/h3&gt;&lt;p&gt;공부한 시간과 과외 수업 횟수에 대한 예측 값을 구해보자.&lt;/p&gt;&lt;p&gt;예를들어 7시간 공부하고 과외를 6번 받은 학생의 합격 가능성을 계산해 보겠다고 하자.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; # 실제 값 적용하기&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; new_x = np.array([7, 6.]).reshape(1, 2) # 7, 6은 각각 공부한 시간과 과외 수업 수&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; new_y = sess.run(y, feed_dict={X: new_x})&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; print(&quot;공부한 시간 : %d, 과외 수업 횟수: %d&quot; % (new_x[:,0], new_x[:,1]))&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; print(&quot;합격 가능성: %6.2f %%&quot; % (new_y*100))&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[실제 결과]&lt;/p&gt;&lt;p&gt;공부한 시간 : 7, 과외 수업 횟수: 6&lt;/p&gt;&lt;p&gt;합격 가능성:&amp;nbsp; 85.66 %&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;8. 로지스틱 회귀에서 퍼셉트론으로&lt;/h3&gt;&lt;p&gt;입력 값을 통해 출력 값을 구하는 함수 y는 다음과 같이 표현할 수 있었다.&lt;/p&gt;&lt;p&gt;y = a1x1 + a2x2 + b&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;우리가 가진 값은 x1, x2이고 이를 입력값이라고 한다.&lt;/p&gt;&lt;p&gt;그리고 계산으로 얻는 값 y를 출력 값이라고 한다.&lt;/p&gt;&lt;p&gt;즉 출력 값 y를 구하려면 a값과 b 값이 필요하다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;x1과 x2가 입력되고, 각각 가중치 a1, a2를 만난다. 여기에 b 값을 더한 후 시그모이드 함수를 거쳐 1 또는 0의 출력 값 y를 출력한다.&lt;/p&gt;&lt;p&gt;1957년, 코넬 항공 연구소의 프랑크 로젠블라트라는 사람이 이 개념을 고안해 발표하고 여기에 '퍼셉트론'이라는 이름을 붙였다.&lt;/p&gt;&lt;p&gt;이 퍼셉트론은 그 후 여러 학자들의 노력을 통해 인공신경망, 오차 역전파 등의 발전을 거쳐 지금의 딥러닝으로 이어지게 된다.&lt;/p&gt;</description>
      <category>개발레시피/└ 머신러닝</category>
      <category>딥러닝</category>
      <category>로지스틱회귀</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/113</guid>
      <comments>https://beenlife.tistory.com/113#entry113comment</comments>
      <pubDate>Wed, 26 Dec 2018 19:51:42 +0900</pubDate>
    </item>
    <item>
      <title>[딥러닝] 경사 하강법 (오차 수정하기)</title>
      <link>https://beenlife.tistory.com/112</link>
      <description>&lt;h2&gt;오차 수정하기: 경사 하강법&lt;/h2&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;그래프에서 오차를 비교하여 가장 작은 방향으로 이동시키는 방법&lt;/p&gt;&lt;p&gt;미분 기울기를 이용&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;미분 : 한 점에서의 순간 기울기&lt;/p&gt;&lt;p&gt;함수 f(x)를 x로 미분하라는 것은,&lt;/p&gt;&lt;p&gt;x의 변화량이 0에 가까울 만큼 작을 때&lt;/p&gt;&lt;p&gt;y 변화량의 차이를&lt;/p&gt;&lt;p&gt;x 변화량으로 나눈 값(순간 변화율)을 구하라는 뜻&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;1. 경사 하강법&lt;/h3&gt;&lt;p&gt;이차 함수 그래프에서 기울기 a를 변화시켜서 그 자리에서 미분하면 각 점에서의 순간 기울기가 그려진다.&lt;/p&gt;&lt;p&gt;우리가 찾는 최솟값 m에서의 순간 기울기는&lt;/p&gt;&lt;p&gt;이차 함수 포물선이므로, x축과 평행한 선이 된다.&lt;/p&gt;&lt;p&gt;즉 기울기가 0이다.&lt;/p&gt;&lt;p&gt;따라서 우리가 할 일은 '미분 값이 0인 지점'을 찾는 일이다.&lt;/p&gt;&lt;p&gt;이를 위해 다음 과정을 거치는데&lt;/p&gt;&lt;p&gt;1) a1에서 미분을 구한다&lt;/p&gt;&lt;p&gt;2) 구해진 기울기의 반대 방향으로 이동시킨 a2에서의 미분을 구한다&lt;/p&gt;&lt;p&gt;3) a3에서 미분을 구한다&lt;/p&gt;&lt;p&gt;4) 3)의 값이 0이 아니면 위 과정을 계속 반복한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;경사 하강법은 이렇게 반복적으로 기울기 a를 변화시켜서 m의 값을 찾아내는 방법이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;2. 학습률&lt;/h3&gt;&lt;p&gt;학습률을 너무 크게 잡으면 한 점으로 수렴하지 않고 발산한다.&lt;/p&gt;&lt;p&gt;따라서 어느 정도 이동시킬지 신중히 결정해야 하는데,&lt;/p&gt;&lt;p&gt;이때 이동 거리를 정해주는 것이 바로 학습률이다.&lt;/p&gt;&lt;p&gt;딥러닝에서는 학습률의 값을 적절히 바꾸면서 최적의 학습률을 찾아 가는 것은&lt;/p&gt;&lt;p&gt;중요한 최적화 과정 중 하나이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;참고) '케라스는 학습률을 자동으로 조절해 준다고 한다.'&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;다시 말해, 경사하강법은 오차의 변화에 따라 이차 함수 그래프를 만들고&lt;/p&gt;&lt;p&gt;적절한 학습률을 설정해 미분 값이 0인 지점을 구하는 것이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;y절편 b의 값도 같은 성질을 가지고 있어서, b값이 너무 크거나 작으면 오차도 함께 커진다.&lt;/p&gt;&lt;p&gt;그래서 최적의 b값을 구할 때 또한 경사 하강법을 사용한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;3. 코딩으로 확인하기 (경사 하강법)&lt;/h3&gt;&lt;button type=&quot;button&quot; class=&quot;btn_more&quot; id=&quot;more112_0&quot; data-id=&quot;112_0&quot;&gt;코드보기&lt;/button&gt;&lt;div class=&quot;moreless_content&quot; id=&quot;content112_0&quot; style=&quot;display: none;&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less112_0&quot; data-id=&quot;112_0&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;
  &lt;p class=&quot;txt_view&quot;&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;colorscripter-code&quot; style=&quot;color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important; overflow:auto&quot;&gt;&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin:0; padding:0; border:none; background-color:#fafafa; border-radius:4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding:6px; border-right:2px solid #e5e5e5&quot;&gt;&lt;div style=&quot;margin:0; padding:0; word-break:normal; text-align:right; color:#666; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;line-height:130%&quot;&gt;1&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;2&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;3&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;4&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;5&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;6&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;7&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;8&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;9&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;10&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;11&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;12&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;13&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;14&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;15&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;16&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;17&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;18&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;19&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;20&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;21&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;22&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;23&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;24&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;25&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;26&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;27&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;28&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;29&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;30&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;31&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;32&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;33&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;34&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;35&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;36&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;37&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;38&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;39&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;40&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;41&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;42&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;padding:6px 0&quot;&gt;&lt;div style=&quot;margin:0; padding:0; color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;tensorflow&amp;nbsp;as&amp;nbsp;tf&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x,y의&amp;nbsp;데이터&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;81&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;93&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;91&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;97&lt;/span&gt;]]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x_data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[x_row[&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;x_row&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y_data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[y_row[&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;y_row&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&amp;nbsp;a와&amp;nbsp;y절편&amp;nbsp;b의&amp;nbsp;값을&amp;nbsp;임의로&amp;nbsp;정한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;단,&amp;nbsp;기울기의&amp;nbsp;범위는&amp;nbsp;0~10&amp;nbsp;사이이며,&amp;nbsp;y절편은&amp;nbsp;0~100&amp;nbsp;사이에서&amp;nbsp;변하게&amp;nbsp;한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;a&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;10&lt;/span&gt;,&amp;nbsp;dtype&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;b&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;100&lt;/span&gt;,&amp;nbsp;dtype&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;y에&amp;nbsp;대한&amp;nbsp;일차&amp;nbsp;방정식&amp;nbsp;ax+b의&amp;nbsp;식을&amp;nbsp;세운다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;a&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;x_data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;b&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;텐서플로&amp;nbsp;RMSE&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;rmse&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.sqrt(tf.reduce_mean(tf.square(y&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;y_data)))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;학습률&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;learning_rate&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0.&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;RMSE&amp;nbsp;값을&amp;nbsp;최소로&amp;nbsp;하는&amp;nbsp;값&amp;nbsp;찾기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;tensorflow의&amp;nbsp;GradientDescentOptimizer()&amp;nbsp;함수를&amp;nbsp;이용해&amp;nbsp;경사&amp;nbsp;하강법을&amp;nbsp;구할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;gradient_decent&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.train.GradientDescentOptimizer(learning_rate).minimize(rmse)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;텐서플로를&amp;nbsp;이용한&amp;nbsp;학습&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;with&amp;nbsp;tf.Session()&amp;nbsp;as&amp;nbsp;sess:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;변수&amp;nbsp;초기화&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(tf.global_variables_initializer())&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;2001번&amp;nbsp;실행(0번째를&amp;nbsp;포함하므로)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;step&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color:#0099cc&quot;&gt;2001&lt;/span&gt;):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(gradient_decent)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;100번마다&amp;nbsp;출력&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;if&lt;/span&gt;&amp;nbsp;step&amp;nbsp;%&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;100&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;Epoch:&amp;nbsp;%.f,&amp;nbsp;RMSE&amp;nbsp;=&amp;nbsp;%.04f,&amp;nbsp;기울기&amp;nbsp;a&amp;nbsp;=&amp;nbsp;%.4f,&amp;nbsp;y절편&amp;nbsp;b&amp;nbsp;=&amp;nbsp;%.4f&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(step,&amp;nbsp;sess.run(rmse),&amp;nbsp;sess.run(a),&amp;nbsp;sess.run(b)))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;평균&amp;nbsp;제곱근&amp;nbsp;오차(RMSE)의&amp;nbsp;변화와&amp;nbsp;기울기&amp;nbsp;a가&amp;nbsp;2.3에&amp;nbsp;수렴하는&amp;nbsp;것,&amp;nbsp;y절편&amp;nbsp;b가&amp;nbsp;79에&amp;nbsp;수렴하는&amp;nbsp;과정을&amp;nbsp;확인할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&amp;nbsp;2.3과&amp;nbsp;y절편&amp;nbsp;79는&amp;nbsp;앞서&amp;nbsp;최소제곱법을&amp;nbsp;통해&amp;nbsp;미리&amp;nbsp;확인한&amp;nbsp;정답과&amp;nbsp;같다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;이렇게&amp;nbsp;하면&amp;nbsp;최소&amp;nbsp;제곱법을&amp;nbsp;쓰지&amp;nbsp;않고&amp;nbsp;기울기&amp;nbsp;a와&amp;nbsp;y절편&amp;nbsp;b의&amp;nbsp;값을&amp;nbsp;구할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;평균&amp;nbsp;제곱근&amp;nbsp;오차와&amp;nbsp;경사하강법을&amp;nbsp;통해서&amp;nbsp;말이다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;이와&amp;nbsp;같은&amp;nbsp;방식을&amp;nbsp;x가&amp;nbsp;여러&amp;nbsp;개인&amp;nbsp;다중&amp;nbsp;선형&amp;nbsp;회귀에서도&amp;nbsp;사용한다.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align:right; margin-top:-13px; margin-right:5px; font-size:9px; font-style:italic&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: rgb(229, 229, 229);&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;vertical-align:bottom; padding:0 2px 4px 0&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: white;&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: rgb(229, 229, 229); border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/p&gt;
&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less112_0&quot; data-id=&quot;112_0&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;4. 다중 선형 회귀&lt;/h3&gt;&lt;p&gt;상황에 따라 더 정확한 예측을 위해 추가 정보를 입력해야 하며,&lt;/p&gt;&lt;p&gt;정보를 추가해 새로운 에측 값을 구하려면 변수의 개수를 늘려 '다중 선형 회귀'를 만들어 주어야 한다.&lt;/p&gt;&lt;p&gt;예를 들어 x2로 과외 수업 횟수의 독립 변수가 생겼다고 가정하면&lt;/p&gt;&lt;p&gt;y = a1x2 + a2x2 + b 와 같은 식이 나온다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이 두 기울기 a1, a2는 어떻게 구할 수 있을까?&lt;/p&gt;&lt;p&gt;경사 하강법을 그대로 적용하면 된다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;5. 코딩으로 확인하기 (다중 선형 회귀)&lt;/h3&gt;&lt;button type=&quot;button&quot; class=&quot;btn_more&quot; id=&quot;more112_1&quot; data-id=&quot;112_1&quot;&gt;코드보기&lt;/button&gt;&lt;div class=&quot;moreless_content&quot; id=&quot;content112_1&quot; style=&quot;display: none;&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less112_1&quot; data-id=&quot;112_1&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;
  &lt;p class=&quot;txt_view&quot;&gt;&lt;div class=&quot;colorscripter-code&quot; style=&quot;color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important; overflow:auto&quot;&gt;&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin:0; padding:0; border:none; background-color:#fafafa; border-radius:4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding:6px; border-right:2px solid #e5e5e5&quot;&gt;&lt;div style=&quot;margin:0; padding:0; word-break:normal; text-align:right; color:#666; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;line-height:130%&quot;&gt;1&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;2&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;3&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;4&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;5&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;6&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;7&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;8&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;9&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;10&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;11&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;12&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;13&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;14&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;15&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;16&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;17&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;18&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;19&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;20&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;21&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;22&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;23&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;24&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;25&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;26&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;27&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;28&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;29&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;30&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;31&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;32&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;33&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;34&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;35&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;36&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;37&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;38&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;39&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;40&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;41&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;42&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;padding:6px 0&quot;&gt;&lt;div style=&quot;margin:0; padding:0; color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;tensorflow&amp;nbsp;as&amp;nbsp;tf&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x1,&amp;nbsp;x2,&amp;nbsp;y의&amp;nbsp;데이터&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;81&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;93&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;91&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;3&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;97&lt;/span&gt;]]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x1&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[x_row1[&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;x_row1&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x2&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[x_row2[&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;x_row2&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;새로&amp;nbsp;추가되는&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y_data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[y_row[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;y_row&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&amp;nbsp;a와&amp;nbsp;y절편&amp;nbsp;b의&amp;nbsp;값을&amp;nbsp;임의로&amp;nbsp;정한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;단,&amp;nbsp;기울기의&amp;nbsp;범위는&amp;nbsp;0~10&amp;nbsp;사이이며,&amp;nbsp;y절편은&amp;nbsp;0~100&amp;nbsp;사이에서&amp;nbsp;변하게&amp;nbsp;한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;a1&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;10&lt;/span&gt;,&amp;nbsp;dtype&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;a2&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;10&lt;/span&gt;,&amp;nbsp;dtype&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;))&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;새로&amp;nbsp;추가되는&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;b&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.Variable(tf.random_uniform([&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;],&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;100&lt;/span&gt;,&amp;nbsp;dtype&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.float64,&amp;nbsp;seed&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;y에&amp;nbsp;대한&amp;nbsp;일차&amp;nbsp;방정식&amp;nbsp;ax+b의&amp;nbsp;식을&amp;nbsp;세운다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;a1&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;x1&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;a2&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;x2&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;b&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;텐서플로&amp;nbsp;RMSE&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;rmse&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.sqrt(tf.reduce_mean(tf.square(y&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;y_data)))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;학습률&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;learning_rate&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0.&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;RMSE&amp;nbsp;값을&amp;nbsp;최소로&amp;nbsp;하는&amp;nbsp;값&amp;nbsp;찾기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;tensorflow의&amp;nbsp;GradientDescentOptimizer()&amp;nbsp;함수를&amp;nbsp;이용해&amp;nbsp;경사&amp;nbsp;하강법을&amp;nbsp;구할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;gradient_decent&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;tf.train.GradientDescentOptimizer(learning_rate).minimize(rmse)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;텐서플로를&amp;nbsp;이용한&amp;nbsp;학습&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;with&amp;nbsp;tf.Session()&amp;nbsp;as&amp;nbsp;sess:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;변수&amp;nbsp;초기화&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(tf.global_variables_initializer())&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;2001번&amp;nbsp;실행(0번째를&amp;nbsp;포함하므로)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;step&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color:#0099cc&quot;&gt;2001&lt;/span&gt;):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sess.run(gradient_decent)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;100번마다&amp;nbsp;출력&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;if&lt;/span&gt;&amp;nbsp;step&amp;nbsp;%&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;100&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;:&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;Epoch:&amp;nbsp;%.f,&amp;nbsp;RMSE&amp;nbsp;=&amp;nbsp;%.04f,&amp;nbsp;기울기&amp;nbsp;a1&amp;nbsp;=&amp;nbsp;%.4f,&amp;nbsp;기울기&amp;nbsp;a2&amp;nbsp;=&amp;nbsp;%.4f,&amp;nbsp;y절편&amp;nbsp;b&amp;nbsp;=&amp;nbsp;%.4f&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(step,&amp;nbsp;sess.run(rmse),&amp;nbsp;sess.run(a1),&amp;nbsp;sess.run(a2),&amp;nbsp;sess.run(b)))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;이를&amp;nbsp;그래프로&amp;nbsp;표현하면&amp;nbsp;1차원&amp;nbsp;예측&amp;nbsp;직선이&amp;nbsp;3차원&amp;nbsp;'예측&amp;nbsp;평면'으로&amp;nbsp;바뀐다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;과외&amp;nbsp;수업&amp;nbsp;횟수라는&amp;nbsp;새로운&amp;nbsp;변수가&amp;nbsp;추가되면서&amp;nbsp;1차원&amp;nbsp;직선에서만&amp;nbsp;움직이던&amp;nbsp;예측&amp;nbsp;결과가&amp;nbsp;더&amp;nbsp;넓은&amp;nbsp;평면&amp;nbsp;범위&amp;nbsp;안에서&amp;nbsp;움직이게&amp;nbsp;되고,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;이로&amp;nbsp;인해&amp;nbsp;좀&amp;nbsp;더&amp;nbsp;정밀한&amp;nbsp;예측을&amp;nbsp;할&amp;nbsp;수&amp;nbsp;있다.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align:right; margin-top:-13px; margin-right:5px; font-size:9px; font-style:italic&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: rgb(229, 229, 229);&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;vertical-align:bottom; padding:0 2px 4px 0&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: white;&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: rgb(229, 229, 229); border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/p&gt;
&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less112_1&quot; data-id=&quot;112_1&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>개발레시피/└ 머신러닝</category>
      <category>경사하강법</category>
      <category>딥러닝</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/112</guid>
      <comments>https://beenlife.tistory.com/112#entry112comment</comments>
      <pubDate>Mon, 24 Dec 2018 15:55:14 +0900</pubDate>
    </item>
    <item>
      <title>[딥러닝] 선형 회귀</title>
      <link>https://beenlife.tistory.com/111</link>
      <description>&lt;h2&gt;선형 회귀&lt;/h2&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;x값이 변함에 따라 y값도 변한다는 정의 안에서, 독립적으로 변할 수 있는 값 x를 독립 변수라고 한다.&lt;/p&gt;&lt;p&gt;또한, 이 독립 변수에 따라 종속적으로 변하는 y를 종속변수라고 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;선형회귀 : 독립변수 x를 사용해 종속변수 y의 움직임을 예측하고 설명하는 작업을 말한다.&lt;/p&gt;&lt;p&gt;정확한 직선을 그려내는 과정이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;독립변수가 x 하나뿐이어서 이것만으로 정확히 설명할 수 없을 때는 x1, x2, x3...등 x값을 여러 개 준비해 놓을 수 있다.&lt;/p&gt;&lt;p&gt;단순선형회귀 : 하나의 x값만으로도 y값을 설명할 수 있을 때&lt;/p&gt;&lt;p&gt;(ex : '공부한 시간'에 따른 성적)&lt;/p&gt;&lt;p&gt;다중선형회귀 : x값이 여러개 필요할 때&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;1. 가장 훌륭한 예측선 그리기&lt;/h3&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;y = ax + b 의 식으로 일차 함수 그래프를 나타낼 수 있다.&lt;/p&gt;&lt;p&gt;선형 회귀는 결국 최적의 a, b값을 찾아내는 작업이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;2. 최소 제곱법&lt;/h3&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;최소 제곱법이란 회귀 분석에서 사용되는 표준 방식이다.&lt;/p&gt;&lt;p&gt;최소제곱법을 통해 기울기 a와 y절편 b의 값을 구하면서, 가장 잘 그어진 예측 직선을 그릴 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;a = x의 편차(각 값과 평균과의 차이)를 제곱해서 합한 값을 분모로 놓고,&lt;/p&gt;&lt;p&gt;x와 y의 편차를 곱해서 합한 값을 분자로 놓으면 기울기가 나온다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;b = y의 평균에서 x의 평균과 기울기의 곱을 빼면 b의 값이 나온다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이렇게, a와 b의 값을 구하여 할당한 후&lt;/p&gt;&lt;p&gt;x를 대입했을 때 나오는 y의 값을 '예측 값'이라고 부른다.&lt;/p&gt;&lt;p&gt;좌표 평면에 예측 값을 찍은 후, 이 점들을 연결해 직선을 그으면&lt;/p&gt;&lt;p&gt;오차가 최저가 되는 직선이 완성된다.(예측 직선)&lt;/p&gt;&lt;p&gt;이 직선에 다른 x의 값을 넣어서 y 값을 예측할 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;3. 코딩으로 구현해보기 (최소 제곱법)&lt;/h3&gt;&lt;button type=&quot;button&quot; class=&quot;btn_more&quot; id=&quot;more111_0&quot; data-id=&quot;111_0&quot;&gt;코드보기&lt;/button&gt;&lt;div class=&quot;moreless_content&quot; id=&quot;content111_0&quot; style=&quot;display: none;&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less111_0&quot; data-id=&quot;111_0&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;
  &lt;p class=&quot;txt_view&quot;&gt;&lt;div class=&quot;colorscripter-code&quot; style=&quot;color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important; overflow:auto&quot;&gt;&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin:0; padding:0; border:none; background-color:#fafafa; border-radius:4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding:6px; border-right:2px solid #e5e5e5&quot;&gt;&lt;div style=&quot;margin:0; padding:0; word-break:normal; text-align:right; color:#666; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;line-height:130%&quot;&gt;1&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;2&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;3&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;4&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;5&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;6&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;7&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;8&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;9&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;10&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;11&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;12&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;13&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;14&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;15&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;16&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;17&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;18&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;19&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;20&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;21&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;22&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;23&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;24&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;25&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;26&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;27&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;28&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;29&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;30&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;31&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;32&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;33&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;padding:6px 0&quot;&gt;&lt;div style=&quot;margin:0; padding:0; color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;numpy&amp;nbsp;as&amp;nbsp;np&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;수치&amp;nbsp;계산을&amp;nbsp;위해&amp;nbsp;만들어진&amp;nbsp;라이브러리&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;81&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;93&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;91&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;97&lt;/span&gt;]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x와&amp;nbsp;y의&amp;nbsp;평균값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;mx&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;np.mean(x)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;my&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;np.mean(y)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;x의&amp;nbsp;평균값:&quot;&lt;/span&gt;,&amp;nbsp;mx)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;y의&amp;nbsp;평균값:&quot;&lt;/span&gt;,&amp;nbsp;my)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&amp;nbsp;공식의&amp;nbsp;분모&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;divisor&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;sum([(mx&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;&amp;nbsp;i)&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;x])&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#x의&amp;nbsp;평균값과&amp;nbsp;x의&amp;nbsp;각&amp;nbsp;원소들의&amp;nbsp;차를&amp;nbsp;제곱&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&amp;nbsp;공식의&amp;nbsp;분자&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x와&amp;nbsp;y의&amp;nbsp;편차를&amp;nbsp;곱해서&amp;nbsp;합한&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;def&lt;/span&gt;&amp;nbsp;top(x,&amp;nbsp;mx,&amp;nbsp;y,&amp;nbsp;my):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color:#066de2&quot;&gt;len&lt;/span&gt;(x)):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;(x[i]&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;mx)&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&amp;nbsp;(y[i]&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;my)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;return&lt;/span&gt;&amp;nbsp;d&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;dividend&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;top(x,&amp;nbsp;mx,&amp;nbsp;y,&amp;nbsp;my)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;분모:&quot;&lt;/span&gt;,&amp;nbsp;divisor)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;분자:&quot;&lt;/span&gt;,&amp;nbsp;dividend)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기와&amp;nbsp;y절편&amp;nbsp;구하기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;a&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;dividend&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;/&lt;/span&gt;&amp;nbsp;divisor&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;b&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;my&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;&amp;nbsp;(mx&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;a)&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;y의&amp;nbsp;평균에서&amp;nbsp;x의&amp;nbsp;평균과&amp;nbsp;기울기의&amp;nbsp;곱을&amp;nbsp;뺀&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;기울기&amp;nbsp;a&amp;nbsp;=&quot;&lt;/span&gt;,&amp;nbsp;a)&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;y절편&amp;nbsp;b&amp;nbsp;=&quot;&lt;/span&gt;,&amp;nbsp;b)&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align:right; margin-top:-13px; margin-right:5px; font-size:9px; font-style:italic&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: rgb(229, 229, 229);&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;vertical-align:bottom; padding:0 2px 4px 0&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: white;&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: rgb(229, 229, 229); border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/p&gt;
&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less111_0&quot; data-id=&quot;111_0&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;h3&gt;4. 평균 제곱근 오차&lt;/h3&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이렇게 선을 그리고 난 후 얼마나 잘 그려졌는지를 평가하는 오차 평가 알고리즘이 필요하다.&lt;/p&gt;&lt;p&gt;오차를 평가하는 방법 중 가장 많이 사용되는 평균 제곱근 오차에 대해 알아보자.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;5. 잘못 그은 선 바로잡기&lt;/h3&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;오차 = 실제 값 - 예측 값&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;오차의 합을 구할 때는, 부호를 없애야 정확한 오차를 구할 수 있기 때문에&lt;/p&gt;&lt;p&gt;각 오차의 값을 제곱해준다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;오차의 합에 n으로 나누면 오차 합의 평균을 구할 수 있다.(평균 제곱 오차)&lt;/p&gt;&lt;p&gt;평균 제곱 오차에 제곱근을 씌워 단위를 낮춘다. 이를 평균 제곱근 오차 라고 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;정리하면, '평균 제곱근 오차'의 계산 결과가 가장 작은 선을 찾는 작업이다.&lt;/p&gt;&lt;p&gt;선형 회귀란 임의의 직선을 그어 이에 대한 평균 제곱근 오차를 구하고, 이 값을 가장 작게 만들어 주는 a와 b를 찾아가는 작업이라고 말할 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;6. 코딩으로 구현해보기 (평균 제곱근 오차)&lt;/h3&gt;&lt;button type=&quot;button&quot; class=&quot;btn_more&quot; id=&quot;more111_1&quot; data-id=&quot;111_1&quot;&gt;코드 보기&lt;/button&gt;&lt;div class=&quot;moreless_content&quot; id=&quot;content111_1&quot; style=&quot;display: none;&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less111_1&quot; data-id=&quot;111_1&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;
  &lt;p class=&quot;txt_view&quot;&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;colorscripter-code&quot; style=&quot;color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important; overflow:auto&quot;&gt;&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin:0; padding:0; border:none; background-color:#fafafa; border-radius:4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding:6px; border-right:2px solid #e5e5e5&quot;&gt;&lt;div style=&quot;margin:0; padding:0; word-break:normal; text-align:right; color:#666; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;line-height:130%&quot;&gt;1&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;2&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;3&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;4&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;5&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;6&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;7&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;8&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;9&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;10&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;11&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;12&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;13&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;14&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;15&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;16&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;17&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;18&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;19&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;20&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;21&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;22&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;23&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;24&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;25&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;26&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;27&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;28&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;29&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;30&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;31&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;32&lt;/div&gt;&lt;div style=&quot;line-height:130%&quot;&gt;33&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;padding:6px 0&quot;&gt;&lt;div style=&quot;margin:0; padding:0; color:#010101; font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height:130%&quot;&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;import&lt;/span&gt;&amp;nbsp;numpy&amp;nbsp;as&amp;nbsp;np&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;기울기&amp;nbsp;a와&amp;nbsp;y절편&amp;nbsp;b&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;ab&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;3&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;76&lt;/span&gt;]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;x,&amp;nbsp;y의&amp;nbsp;데이터&amp;nbsp;값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;data&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;81&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;4&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;93&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;6&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;91&lt;/span&gt;],&amp;nbsp;[&lt;span style=&quot;color:#0099cc&quot;&gt;8&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color:#0099cc&quot;&gt;97&lt;/span&gt;]]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;x&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[i[&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;y&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[i[&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;data]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;y&amp;nbsp;=&amp;nbsp;ax&amp;nbsp;+&amp;nbsp;b에&amp;nbsp;a와&amp;nbsp;b&amp;nbsp;값을&amp;nbsp;대입하여&amp;nbsp;결과를&amp;nbsp;출력하는&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;def&lt;/span&gt;&amp;nbsp;predict(x):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;return&lt;/span&gt;&amp;nbsp;ab[&lt;span style=&quot;color:#0099cc&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;x&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;ab[&lt;span style=&quot;color:#0099cc&quot;&gt;1&lt;/span&gt;]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;RMSE&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;def&lt;/span&gt;&amp;nbsp;rmse(p,&amp;nbsp;a):&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#p:&amp;nbsp;예측값,&amp;nbsp;a:&amp;nbsp;실제값&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;return&lt;/span&gt;&amp;nbsp;np.sqrt(((p&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;-&lt;/span&gt;a)&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#0099cc&quot;&gt;2&lt;/span&gt;).mean())&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#np.sqrt()는&amp;nbsp;제곱근을,&amp;nbsp;**2는&amp;nbsp;제곱을&amp;nbsp;구하라는&amp;nbsp;뜻,&amp;nbsp;mean()은&amp;nbsp;평균값을&amp;nbsp;구하라는&amp;nbsp;뜻&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;RMSE&amp;nbsp;함수를&amp;nbsp;각&amp;nbsp;y값에&amp;nbsp;대입하여&amp;nbsp;최종&amp;nbsp;값을&amp;nbsp;구하는&amp;nbsp;함수&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;def&lt;/span&gt;&amp;nbsp;rmse_val(predict_result,&amp;nbsp;y):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;return&lt;/span&gt;&amp;nbsp;rmse(np.array(predict_result),&amp;nbsp;np.array(y))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;예측&amp;nbsp;값이&amp;nbsp;들어갈&amp;nbsp;빈&amp;nbsp;리스트&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;predict_result&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;모든&amp;nbsp;값을&amp;nbsp;한&amp;nbsp;번씩&amp;nbsp;대입하여&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color:#a71d5d&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color:#066de2&quot;&gt;len&lt;/span&gt;(x)):&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;그&amp;nbsp;결과&amp;nbsp;predict_result&amp;nbsp;리스트를&amp;nbsp;완성한다.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;predict_result.append(predict(x[i]))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;공부한&amp;nbsp;시간=%.f,&amp;nbsp;실제&amp;nbsp;점수=%.f,&amp;nbsp;예측&amp;nbsp;점수=%.f,&quot;&lt;/span&gt;&amp;nbsp;%&amp;nbsp;(x[i],&amp;nbsp;y[i],&amp;nbsp;predict(x[i])))&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#999999&quot;&gt;#&amp;nbsp;최종&amp;nbsp;RMSE&amp;nbsp;출력&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;padding:0 6px; white-space:pre; line-height:130%&quot;&gt;&lt;span style=&quot;color:#066de2&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color:#63a35c&quot;&gt;&quot;RMSE&amp;nbsp;최종값:&amp;nbsp;&quot;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#0086b3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color:#a71d5d&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color:#066de2&quot;&gt;str&lt;/span&gt;(rmse_val(predict_result,&amp;nbsp;y)))&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align:right; margin-top:-13px; margin-right:5px; font-size:9px; font-style:italic&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: rgb(229, 229, 229);&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style=&quot;vertical-align:bottom; padding:0 2px 4px 0&quot;&gt;&lt;a href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; style=&quot;color: white;&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: rgb(229, 229, 229); border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/p&gt;
&lt;button type=&quot;button&quot; class=&quot;btn_less&quot; id=&quot;less111_1&quot; data-id=&quot;111_1&quot;&gt;&lt;span class=&quot;txt_fold&quot;&gt;접기&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이렇게 오차가 약 3.3166이라는 것을 알았다.&lt;/p&gt;&lt;p&gt;이제 남은 것은 이 오차를 줄이면서 새로운 선을 긋는 것이다.&lt;/p&gt;&lt;p&gt;이를 위해서는 a와 b의 값을 적절히 조절하면서 오차의 변화를 살펴보고,&lt;/p&gt;&lt;p&gt;그 오차가 최소화되는 a와 b의 값을 구해야 한다.&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>개발레시피/└ 머신러닝</category>
      <category>딥러닝</category>
      <category>머신러닝</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/111</guid>
      <comments>https://beenlife.tistory.com/111#entry111comment</comments>
      <pubDate>Mon, 24 Dec 2018 14:16:01 +0900</pubDate>
    </item>
    <item>
      <title>[Docker] Dockerfile 명령어</title>
      <link>https://beenlife.tistory.com/110</link>
      <description>&lt;h3&gt;Dockerfile 명령어&lt;/h3&gt;&lt;p&gt;FROM : 베이스 이미지 지정&lt;/p&gt;&lt;p&gt;MAINTAINER : Dockerfile 생성자&lt;/p&gt;&lt;p&gt;RUN : 커맨드 실행&lt;/p&gt;&lt;p&gt;CMD : 데몬 실행&lt;/p&gt;&lt;p&gt;LABEL : 라벨 설정&lt;/p&gt;&lt;p&gt;EXPOSE : 포트 export&lt;/p&gt;&lt;p&gt;ENV : 환경변수 설정&lt;/p&gt;&lt;p&gt;ADD : 파일 및 디렉터리 추가&lt;/p&gt;&lt;p&gt;COPY : 파일 복사&lt;/p&gt;&lt;p&gt;VOLUME : 볼륨 마운트&lt;/p&gt;&lt;p&gt;ENTRYPOINT : 데몬 실행&lt;/p&gt;&lt;p&gt;USER : 사용자 설정&lt;/p&gt;&lt;p&gt;WORKDIR : 작업 디렉터리 지정&lt;/p&gt;&lt;p&gt;ONBUILD : build 완료 후 실행될 명령어&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;Dockerfile로 Docker이미지 생성&lt;/h3&gt;&lt;div&gt;docker build -t [생성할 이미지명]:[태그명] [Dockerfile 경로]&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <category>개발레시피/└ 유틸</category>
      <category>docker</category>
      <author>빈나는</author>
      <guid isPermaLink="true">https://beenlife.tistory.com/110</guid>
      <comments>https://beenlife.tistory.com/110#entry110comment</comments>
      <pubDate>Fri, 21 Dec 2018 17:59:13 +0900</pubDate>
    </item>
  </channel>
</rss>