Our main learning objective in this section is another nice example of supervised learning methods, and almost as simple as the nearest neighbor classifier too: linear regression. We'll introduce its close cousin, logistic regression as well.

이 섹션의 학습 목표는 지도학습의 좋은 예이자 가장 간단한 최근접 이웃 분류기인 선형 회귀입니다. 또한 이와 비슷한 로지스틱 회귀도 소개합니다.

<aside> 💡 Note

The difference between classification and regression There is a small but important difference in the kind of predictions that we should produce in different scenarios. While for example the nearest neighbor classifier chooses a class label for any item out of a given set of alternatives (like spam/ham, or 0,1,2,...,9), linear regression produces a numerical prediction that is not constrained to be an integer (a whole number as opposed to something like 3.14). So linear regression is better suited in situations where the output variable can be any number like the price of a product, the distance to an obstacle, the box-office revenue of the next Star Wars movie, and so on.

</aside>

<aside> 💡 Note

분류와 회귀의 차이 각각의 시나리오에서 생성해야 하는 예측의 종류에는 작지만 중요한 차이가 있습니다. 예를 들어 최근접 이웃 분류기는 주어진 선택지(스팸/스팸이 아님 또는 0,1,2,...,9)에서 클래스 레이블을 선택하지만, 선형 회귀는 정수(3.14와는 반대로 소숫점 아래가 없는 숫자)에 한정되지 않은 숫자 예측값을 생성합니다. 따라서 선형 회귀는 출력 변수가 물건의 가격, 장애물까지의 거리, 다음 스타워즈 영화의 박스오피스 수익 등과 같은 숫자인 상황에 더 적합합니다.

</aside>

The basic idea in linear regression is to add up the effects of each of the feature variables to produce the predicted value. The technical term for the adding up process is linear combination. The idea is very straightforward, and it can be illustrated by your shopping bill.

선형 회귀의 기본 아이디어는 각 피처 변수의 효과를 더함으로써 예측 값을 생성하는 것입니다. 이 때 더하는 것을 전문용어로 선형 결합이라고 합니다. 이 아이디어는 매우 간단하고, 쇼핑 영수증으로 설명할 수 있습니다.

<aside> 💡 Note

Thinking of linear regression as a shopping bill Suppose you go to the grocery store and buy 2.5kg potatoes, 1.0kg carrots, and two bottles of milk. If the price of potatoes is 2€ per kg, the price of carrots is 4€ per kg, and a bottle of milk costs 3€, then the bill, calculated by the cashier, totals 2.5 × 2€ + 1.0 × 4€ + 2 × 3€ = 15€. In linear regression, the amount of potatoes, carrots, and milk are the inputs in the data. The output is the cost of your shopping, which clearly depends on both the price and how much of each product you buy.

</aside>

<aside> 💡 Note

선형 회귀를 쇼핑 영수증으로 생각해보기 마트에 가서 감자 2.5kg, 당근 1.0kg, 우유 두 병을 산다고 합시다. 감자가 kg당 3000원, 당근이 kg당 6000원, 우유 한 병이 4500원이라면 캐셔가 계산한 영수증의 총 청구 금액은 2.5 × 3000원 + 1.0 × 6000원 + 2 × 4500원 = 22500원입니다. 선형 회귀에서, 감자, 당근, 우유의 양은 데이터의 입력에 해당합니다. 출력은 쇼핑 비용으로, 구매한 각 제품의 양과 가격에 따라 달라집니다.

</aside>

The word linear means that the increase in the output when one input feature is increased by some fixed amount is always the same. In other words, whenever you add, say, two kilos of carrots into your shopping basket, the bill goes up 8€. When you add another two kilos, the bill goes up another 8€, and if you add half as much, 1kg, the bill goes up exactly half as much, 4€.

선형이라는 단어는 하나의 입력 피처가 일정한 양만큼 증가할 때 출력의 증가도 항상 같다는 것을 의미합니다. 다시 말해, 장바구니에 당근을 2kg 더 넣을 때마다 영수증의 총 금액은 12000원만큼 더 올라갑니다. 당근을 새로 2kg 더 넣으면 12000원이 더 들고, 그 반인 1kg를 추가하면 총 금액은 정확히 반에 해당하는 6000원만큼 늘어납니다.

<aside> 💡 Key terminology

Coefficients or weights

In linear regression terminology, the prices of the different products would be called coefficients or weights (this may appear confusing since we measured the amount of potatoes and carrots by weight, but not let yourself be tricked by this). One of the main advantages of linear regression is its easy interpretability: the learned weights may in fact be more interesting than the predictions of the outputs.

For example, when we use linear regression to predict the life expectancy, the weight of smoking (cigarettes per day) is about minus half a year, meaning that smoking one cigarette more per day takes you on the average half a year closer to termination. Likewise, the weight of vegetable consumption (handful of vegetables per day) has weight plus one year, so eating a handful of greens gives every day gives you on the average one more year.

</aside>

<aside> 💡 핵심 용어

계수 또는 가중치weights

선형 회귀 용어에서는 서로 다른 제품의 가격을 계수 또는 가중치라고 합니다. (지금까지 감자와 당근의 양을 무게weight로 측정했기 때문에 혼란스러울 수 있지만, 무게와는 다릅니다). 선형 회귀의 주요 장점 중 하나는 해석이 용이하다는 것입니다. 학습된 가중치가 실제로 출력으로 나온 예측값보다 더 흥미로울 수도 있습니다.

예를 들어, 선형 회귀를 사용하여 기대 수명을 예측할 때 흡연의 가중치(하루에 피는 담배량)는 대략 반 년 감소입니다. 즉, 하루에 한 개비 이상의 담배를 흡연하면 기대수명이 평균 반 년이 줄어든다는 말입니다. 비슷한 맥락으로, 채소 섭취량(하루에 채소 한 줌)의 가중치는 1년 추가로, 매일 한 줌의 채소를 먹는다면 평균적으로 1년을 더 살 수 있습니다.

</aside>

Exercise 16: Linear regression

연습문제 16: 선형 회귀

Suppose that an extensive study is carried out, and it is found that in a particular country, the life expectancy (the average number of years that people live) among non-smoking women who don't eat any vegetables is 80 years. Suppose further that on the average, men live 5 years less. Also take the numbers mentioned above: every cigarette per day reduces the life expectancy by half a year, and a handful of veggies per day increases it by one year.

대규모 연구를 수행한 결과 특정 국가에서 채소를 먹지 않는 비흡연 여성의 평균 수명(사람이 사는 평균 년 수)이 80년이었다고 가정합시다. 또, 남성이 여성에 비해 평균적으로 5년을 적게 산다고 합시다. 앞서 언급한 수치도 참고하여, 하루 한 개비의 담배는 수명을 반 년 줄이고, 하루 한 줌의 채소는 수명을 1년씩 증가시킵니다.

Calculate the life expectancies for the following example cases:

아래 예시에 해당하는 기대 수명을 계산해 봅시다.

For example, the first case is a male (subtract 5 years), smokes 8 cigarettes per day (subtract 8 × 0.5 = 4 years), and eats two handfuls of veggies per day (add 2 × 1 = 2 years), so the predicted life expectancy is 80 - 5 - 4 + 2 = 73 years.

예를 들어, 첫 번째 경우는 남성(빼기 5년)이고, 하루에 담배를 8개비 피우며(빼기 8 x 0.5 = 4년), 하루에 두 줌의 채소를 섭취(더하기 2 × 1 = 2년) 합니다. 따라서 예상 수명은 80-5-4 + 2 = 73 년입니다.

Your task: Enter the correct value as an integer (whole number) for the missing sections A, B, and C above.

과제: 위의 빈 칸 A, B, C에 대한 올바른 정수값을 입력하십시오.

In the above exercise, the life expectancy of non-smoking, veggie-hating women, 80 years, was the starting point for the calculation. The technical term for the starting point is the intercept. We will return to this below when we discuss how to learn linear regression models from data.

위의 예제에서 채소를 먹지 않는 비흡연 여성의 평균 기대수명인 80세가 계산의 시작점이었습니다. 시작 지점을 전문용어로 절편이라고 합니다. 나중에 데이터로부터 선형 회귀 모델을 학습하는 방법을 배울 때 다시 이야기하겠습니다.

Learning linear regression

선형 회귀의 학습

Above, we discussed how predictions are obtained from linear regression when both the weights and the input features are known. So we are given the inputs and the weight, and we can produce the predicted output.

앞에서 가중치와 입력 피처가 모두 알려진 경우 선형 회귀 분석에서 예측을 얻는 방법에 대해 설명했습니다. 따라서 입력과 가중치가 주어지면 우리는 예상되는 결과를 생성 할 수 있습니다.