├── class03 ├── helper │ ├── __init__.py │ ├── calculate.py │ └── show.py ├── utils.py ├── main.py └── class03.ipynb ├── class09 ├── k-means.png ├── gender_submission.csv └── test.csv ├── class06 ├── salary_data.png └── Salary_Data.csv ├── class08 ├── decisiontree.py ├── drug200.csv ├── hw5_solution.ipynb └── kNN.ipynb ├── class01 ├── main.py └── class01.ipynb ├── class10 ├── hw4.ipynb └── Dictonary.ipynb ├── class02 ├── main.py └── class02.ipynb ├── class04 └── main.py └── class07 ├── logistic_regression.ipynb └── standardscaler.ipynb /class03/helper/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /class09/k-means.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThousandAI/pycs4001/HEAD/class09/k-means.png -------------------------------------------------------------------------------- /class06/salary_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThousandAI/pycs4001/HEAD/class06/salary_data.png -------------------------------------------------------------------------------- /class03/helper/calculate.py: -------------------------------------------------------------------------------- 1 | def get_max(numbers): 2 | return max(numbers) 3 | 4 | def get_distance(point1, point2): 5 | return ((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)**(1/2) 6 | -------------------------------------------------------------------------------- /class03/helper/show.py: -------------------------------------------------------------------------------- 1 | def say_hello(guest): 2 | print(f"Hello {guest}") 3 | 4 | def introduce(name, age, gender): 5 | print(f"My name is: {name}") 6 | print(f"My age is: {age}") 7 | print(f"My gender is: {gender}") -------------------------------------------------------------------------------- /class03/utils.py: -------------------------------------------------------------------------------- 1 | def say_hello(guest): 2 | print(f"Hello {guest}") 3 | 4 | def introduce(name, age, gender): 5 | print(f"My name is: {name}") 6 | print(f"My age is: {age}") 7 | print(f"My gender is: {gender}") 8 | 9 | def get_max(numbers): 10 | return max(numbers) 11 | 12 | def get_distance(point1, point2): 13 | return ((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)**(1/2) 14 | 15 | #print("Hello This is utils.py") 16 | 17 | if __name__ == "__main__": 18 | print("Hello") 19 | print("Hello This is utils.py") -------------------------------------------------------------------------------- /class06/Salary_Data.csv: -------------------------------------------------------------------------------- 1 | YearsExperience,Salary 2 | 1.1,39343.00 3 | 1.3,46205.00 4 | 1.5,37731.00 5 | 2.0,43525.00 6 | 2.2,39891.00 7 | 2.9,56642.00 8 | 3.0,60150.00 9 | 3.2,54445.00 10 | 3.2,64445.00 11 | 3.7,57189.00 12 | 3.9,63218.00 13 | 4.0,55794.00 14 | 4.0,56957.00 15 | 4.1,57081.00 16 | 4.5,61111.00 17 | 4.9,67938.00 18 | 5.1,66029.00 19 | 5.3,83088.00 20 | 5.9,81363.00 21 | 6.0,93940.00 22 | 6.8,91738.00 23 | 7.1,98273.00 24 | 7.9,101302.00 25 | 8.2,113812.00 26 | 8.7,109431.00 27 | 9.0,105582.00 28 | 9.5,116969.00 29 | 9.6,112635.00 30 | 10.3,122391.00 31 | 10.5,121872.00 32 | -------------------------------------------------------------------------------- /class08/decisiontree.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import matplotlib.pyplot as plt 4 | 5 | data = pd.read_csv("./drug200.csv") 6 | # print(data.head(5)) 7 | 8 | x = data.iloc[:,:-1] 9 | y = data.iloc[:,-1:] 10 | 11 | dummy_x = pd.get_dummies(x) 12 | # print(dummy_x) 13 | 14 | from sklearn.model_selection import train_test_split 15 | 16 | train_x, test_x, train_y, test_y = train_test_split(dummy_x, y, test_size=0.2, random_state=10) 17 | 18 | print(f"train_x shape: {train_x.shape}") 19 | print(f"test_x shape: {test_x.shape}") 20 | 21 | from sklearn.tree import DecisionTreeClassifier 22 | tree = DecisionTreeClassifier(criterion="entropy", max_depth = 4, random_state=10) 23 | tree.fit(train_x, train_y) 24 | y_pred = tree.predict(test_x) 25 | 26 | from sklearn import metrics 27 | print("DecisionTree Accuracy: ", metrics.accuracy_score(test_y, y_pred)) 28 | -------------------------------------------------------------------------------- /class01/main.py: -------------------------------------------------------------------------------- 1 | # Author: Thousand AI 2 | 3 | # 註解 4 | 5 | # 變數 Variable 6 | """ 7 | x = 3 # assign 賦值 8 | y = 2.5 9 | z = "Hello Python" 10 | a = True 11 | b = False 12 | 13 | # 原生型態 Primitive type 14 | print(type(x)) 15 | print(type(y)) 16 | print(type(z)) 17 | print(type(a)) 18 | print(type(b)) 19 | """ 20 | 21 | # Pass by reference 22 | """ 23 | x = 3 24 | y = x 25 | print(id(x), id(y)) 26 | x = x + 1 27 | print(id(x), id(y)) 28 | z = 4 29 | print(id(z)) 30 | """ 31 | 32 | # 輸出 print 33 | """ 34 | print("Hello") # 自動換行 35 | print("Python") 36 | 37 | print("Hello", end=" ") 38 | print("Python") 39 | 40 | print("Hello", end=",") 41 | print("Python") 42 | 43 | print("Hello, Python.\nI'm Thousand.") 44 | """ 45 | 46 | # 輸出格式 (format) 47 | """ 48 | guest = "Allie" 49 | host = "Thousand" 50 | 51 | print("Hello, " + guest + ". My name is " + host + ".") 52 | print(f"Hello, {guest}. My name is {host}.") 53 | print("Hello, {}. My name is {}.".format(guest, host)) 54 | 55 | pi = 3.14159265 56 | print(f"Pi is {pi:.3f}") 57 | print("Pi is {:.3f}".format(pi)) 58 | """ 59 | 60 | # 資料型態不同導致運算結果不同 61 | """ 62 | a = "123" 63 | b = "456" 64 | c = 123 65 | d = 456 66 | print(a+b) 67 | print(c+d) 68 | """ 69 | 70 | # 輸入 71 | """ 72 | number = input("") 73 | print(f"Your number is {number}") 74 | print(type(number)) # string 75 | number = int(number) 76 | print(type(number)) 77 | """ 78 | 79 | # 輸入時候就轉型 80 | """ 81 | number = int(input("Enter a number: ")) 82 | print(f"Your number is {number}") 83 | print(type(number)) 84 | """ 85 | 86 | # try except 87 | """ 88 | try: 89 | number = int(input("Enter a number: ")) 90 | print(f"Your number is: {number}") 91 | except ValueError: 92 | print("輸入格式錯誤,請輸入數字") 93 | """ 94 | 95 | # operator 96 | """ 97 | x = 5 98 | y = 3 99 | print(f"x+y={x+y}") 100 | print(f"x-y={x-y}") 101 | print(f"x*y={x*y}") 102 | print(f"x/y={x/y}") # 小數點除法 103 | print(f"x/y={x//y}") # 整數除法 104 | print(f"x*x*x={x**3}") 105 | print(f"x%y={x%y}") 106 | """ 107 | 108 | # 餘數應用 109 | """ 110 | num = int(input("Enter a number: ")) 111 | print(f"百位數字: {num//100}") 112 | print(f"十位數字: {(num//10)%10}") 113 | print(f"個位數字: {num%10}") 114 | """ 115 | 116 | # 交換數值 117 | """ 118 | x = int(input("x: ")) 119 | y = int(input("y: ")) 120 | #tem = x 121 | # x = y 122 | # y = tem 123 | x,y = y,x 124 | print(f"x: {x}, y:{y}") 125 | """ 126 | 127 | # 控制流程 128 | """ 129 | num = int(input()) 130 | if num > 200: 131 | print(f"{num} > 200") 132 | else: 133 | print(f"{num} <= 200") 134 | """ 135 | 136 | # 非 0 是 True,0 是 False 137 | """ 138 | if 0: 139 | print("This is Ture") 140 | else: 141 | print("This is False") 142 | """ 143 | 144 | # if/elif/else 145 | """ 146 | num = int(input()) 147 | if num > 200: 148 | print(f"{num} > 200") 149 | elif 100 <= num <= 200: 150 | print(f"100 <= {num} <= 200") 151 | else: 152 | print(f"{num} < 100") 153 | """ 154 | 155 | # if/elif/else vs. 多個 if 156 | """ 157 | num = 3 158 | if num >= 2: 159 | print(f"{num} >= 2") 160 | elif num >= 1: 161 | print(f"{num} >= 1") 162 | else: 163 | print(f"{num} >= 0") 164 | 165 | if num >= 2: 166 | print(f"{num} >= 2") 167 | if num >= 1: 168 | print(f"{num} >= 1") 169 | if num >= 0: 170 | print(f"{num} >= 2") 171 | """ 172 | 173 | # if/else 解答 174 | """ 175 | x = int(input()) 176 | y = int(input()) 177 | z = int(input()) 178 | 179 | if x > y: 180 | ans = x 181 | else: 182 | ans = y 183 | 184 | if z > ans: 185 | ans = z 186 | 187 | print(f"最大值: {ans}") 188 | """ 189 | 190 | # Nested if 191 | """ 192 | n = int(input("Enter a number")) 193 | if n % 2 == 1: 194 | print("Weird") 195 | elif n % 2 == 0: 196 | if 2 <= n <= 5: 197 | print("Not Weird") 198 | elif 6 <= n <= 20: 199 | print("Weird") 200 | elif n > 20: 201 | print("Not Weird") 202 | """ 203 | 204 | # while 迴圈 205 | i = 0 206 | while i < 10: 207 | print(i) 208 | i += 1 209 | 210 | -------------------------------------------------------------------------------- /class10/hw4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "hw4.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyOp2jckWPD46ouveoLBxgE8", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": { 34 | "id": "wcKs8YcGNKCx" 35 | }, 36 | "outputs": [], 37 | "source": [ 38 | "import numpy as np\n", 39 | "A = np.zeros((2,3))\n", 40 | "B = np.zeros((3,2))" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "source": [ 46 | "print(\"A:\")\n", 47 | "for i in range(2):\n", 48 | " A[i,:] = np.array(list(map(lambda x: int(x), input().split())))\n", 49 | "print(\"B:\")\n", 50 | "for i in range(3):\n", 51 | " B[i,:] = np.array(list(map(lambda x: int(x), input().split())))" 52 | ], 53 | "metadata": { 54 | "colab": { 55 | "base_uri": "https://localhost:8080/" 56 | }, 57 | "id": "Usk4LqW5NwlJ", 58 | "outputId": "6dd5e72c-81d1-4855-83f3-add506597ab6" 59 | }, 60 | "execution_count": 4, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "A:\n", 67 | "2 3 5\n", 68 | "5 7 8\n", 69 | "B:\n", 70 | "1 2\n", 71 | "3 10\n", 72 | "2 6\n" 73 | ] 74 | } 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "source": [ 80 | "print(A)" 81 | ], 82 | "metadata": { 83 | "colab": { 84 | "base_uri": "https://localhost:8080/" 85 | }, 86 | "id": "JonRFZncOPyx", 87 | "outputId": "42f4fcbb-fda5-43eb-81cc-7d00082dcd0c" 88 | }, 89 | "execution_count": 5, 90 | "outputs": [ 91 | { 92 | "output_type": "stream", 93 | "name": "stdout", 94 | "text": [ 95 | "[[2. 3. 5.]\n", 96 | " [5. 7. 8.]]\n" 97 | ] 98 | } 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "source": [ 104 | "print(B)" 105 | ], 106 | "metadata": { 107 | "colab": { 108 | "base_uri": "https://localhost:8080/" 109 | }, 110 | "id": "KsvGEI-SOlKv", 111 | "outputId": "a58cc5be-dcdf-40b3-a15e-0b2ace14db7d" 112 | }, 113 | "execution_count": 6, 114 | "outputs": [ 115 | { 116 | "output_type": "stream", 117 | "name": "stdout", 118 | "text": [ 119 | "[[ 1. 2.]\n", 120 | " [ 3. 10.]\n", 121 | " [ 2. 6.]]\n" 122 | ] 123 | } 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "source": [ 129 | "ans = np.matmul(A,B)\n", 130 | "print(ans)" 131 | ], 132 | "metadata": { 133 | "colab": { 134 | "base_uri": "https://localhost:8080/" 135 | }, 136 | "id": "TPBQd0JVOqVu", 137 | "outputId": "8c761e14-9d4b-4cc2-8efb-30a14168ebe1" 138 | }, 139 | "execution_count": 7, 140 | "outputs": [ 141 | { 142 | "output_type": "stream", 143 | "name": "stdout", 144 | "text": [ 145 | "[[ 21. 64.]\n", 146 | " [ 42. 128.]]\n" 147 | ] 148 | } 149 | ] 150 | } 151 | ] 152 | } -------------------------------------------------------------------------------- /class10/Dictonary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Dictonary.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyMHTG6lpLXP14BWd2qnLh1A", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": { 34 | "id": "feg2ihYiAOQ_" 35 | }, 36 | "outputs": [], 37 | "source": [ 38 | "dic = {\"Harry\":32, \"Berry\": 31, \"Thousand\":21, \"Becky\": 50, \"Allie\":37}" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "source": [ 44 | "for x in dic.items():\n", 45 | " print(x)" 46 | ], 47 | "metadata": { 48 | "colab": { 49 | "base_uri": "https://localhost:8080/" 50 | }, 51 | "id": "K3WumleEAbT0", 52 | "outputId": "3612bc17-0606-4e7b-945f-230599240c5d" 53 | }, 54 | "execution_count": 2, 55 | "outputs": [ 56 | { 57 | "output_type": "stream", 58 | "name": "stdout", 59 | "text": [ 60 | "('Harry', 32)\n", 61 | "('Berry', 31)\n", 62 | "('Thousand', 21)\n", 63 | "('Becky', 50)\n", 64 | "('Allie', 37)\n" 65 | ] 66 | } 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "source": [ 72 | "sorted_tuple = sorted(dic.items(), key=lambda x: x[1])\n", 73 | "print(sorted_tuple)" 74 | ], 75 | "metadata": { 76 | "colab": { 77 | "base_uri": "https://localhost:8080/" 78 | }, 79 | "id": "bfY9lducAYwR", 80 | "outputId": "cb93a01f-b237-445b-c1ac-960d446f6004" 81 | }, 82 | "execution_count": 3, 83 | "outputs": [ 84 | { 85 | "output_type": "stream", 86 | "name": "stdout", 87 | "text": [ 88 | "[('Thousand', 21), ('Berry', 31), ('Harry', 32), ('Allie', 37), ('Becky', 50)]\n" 89 | ] 90 | } 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "source": [ 96 | "dic = {key:value for key, value in sorted_tuple}\n", 97 | "print(dic)" 98 | ], 99 | "metadata": { 100 | "colab": { 101 | "base_uri": "https://localhost:8080/" 102 | }, 103 | "id": "LZC7H8cDArbt", 104 | "outputId": "743ab586-2c24-46d8-d873-c640fb0b6579" 105 | }, 106 | "execution_count": 4, 107 | "outputs": [ 108 | { 109 | "output_type": "stream", 110 | "name": "stdout", 111 | "text": [ 112 | "{'Thousand': 21, 'Berry': 31, 'Harry': 32, 'Allie': 37, 'Becky': 50}\n" 113 | ] 114 | } 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "source": [ 120 | "ans = {}\n", 121 | "for key, value in sorted_tuple:\n", 122 | " ans[key] = value\n", 123 | "print(ans)" 124 | ], 125 | "metadata": { 126 | "colab": { 127 | "base_uri": "https://localhost:8080/" 128 | }, 129 | "id": "Nk-IO33DBBSU", 130 | "outputId": "8183a9af-d23a-4928-945b-f3544634aff9" 131 | }, 132 | "execution_count": 5, 133 | "outputs": [ 134 | { 135 | "output_type": "stream", 136 | "name": "stdout", 137 | "text": [ 138 | "{'Thousand': 21, 'Berry': 31, 'Harry': 32, 'Allie': 37, 'Becky': 50}\n" 139 | ] 140 | } 141 | ] 142 | } 143 | ] 144 | } -------------------------------------------------------------------------------- /class02/main.py: -------------------------------------------------------------------------------- 1 | # for 迴圈 2 | """ 3 | for i in range(0,10,1): 4 | print(i) 5 | 6 | # for i in range(10): 7 | # print(i) 8 | 9 | """ 10 | 11 | """ 12 | # for 迴圈解答 (1) 13 | n = int(input()) 14 | for i in range(1,n+1,1): 15 | print(i) 16 | """ 17 | 18 | # for 迴圈解答 (2) 19 | """ 20 | n = int(input()) 21 | for i in range(n,-1,-1): 22 | print(i) 23 | """ 24 | 25 | # for 迴圈解答 (3) 26 | """ 27 | n = int(input()) 28 | ans = 0 29 | for i in range(1,n+1,1): 30 | ans = ans + i # ans += i 31 | print(ans) 32 | """ 33 | 34 | # for 迴圈解答 (4) 35 | """ 36 | n = int(input()) 37 | ans = 0 38 | for i in range(n): 39 | temp = int(input()) 40 | ans += temp 41 | print(ans) 42 | """ 43 | 44 | # 無窮迴圈 45 | """ 46 | i = 1 47 | while True: 48 | print(i) 49 | """ 50 | 51 | # break 52 | """ 53 | x = 0 54 | while x <= 10: 55 | x += 1 56 | if x == 3: 57 | break 58 | print(x) 59 | """ 60 | 61 | # continue 62 | """ 63 | x = 0 64 | while x <= 10: 65 | x += 1 66 | if x == 3: 67 | continue 68 | print(x) 69 | """ 70 | 71 | # break (解答) 72 | """ 73 | ans = 0 74 | count = 0 75 | while True: 76 | x = input() 77 | if x == 'q' or x == 'Q': 78 | break 79 | ans += int(x) 80 | count += 1 81 | print(f"總和: {ans}") 82 | print(f"平均: {ans/count:.2f}") 83 | """ 84 | 85 | # 串列 list 86 | """ 87 | numbers = [3, 5, 6, 10, 2, 8] 88 | cat = ["cookie", 2, 3.2] 89 | """ 90 | 91 | # index && slice 92 | """ 93 | numbers = [3, 5, 6, 10, 2, 8] 94 | print(numbers[0]) 95 | print(numbers[2]) 96 | print(numbers[-1]) 97 | print(numbers[-3]) 98 | print(len(numbers)) 99 | print(numbers[1:3]) 100 | print(numbers[:3]) 101 | print(numbers[3:]) 102 | print(numbers[2:-1]) 103 | print(numbers[-1:-4]) 104 | print(numbers[-3:]) 105 | print(numbers[:]) 106 | """ 107 | 108 | # 串列 methods 109 | """ 110 | numbers = [3, 5, 6] 111 | numbers.insert(2, 8) 112 | print(f"After insert: {numbers}") 113 | numbers.append(8) 114 | print(f"After append: {numbers}") 115 | numbers.remove(8) 116 | print(f"After remove: {numbers}") # 移走第一個 117 | numbers.sort() # 由小到大 118 | print(f"After sort: {numbers}") 119 | numbers.reverse() 120 | print(f"After reverse: {numbers}") 121 | numbers.pop() 122 | print(f"After pop: {numbers}") 123 | """ 124 | 125 | # 串列 assign 記憶體問題 126 | """ 127 | num1 = [1, 2, 3, 4, 5] 128 | num2 = num1 129 | num1.append(6) 130 | print(f"num1: {num1}, num2: {num2}") 131 | num3 = num1[:] 132 | num4 = num1.copy() 133 | num1.append(7) 134 | num3.append(8) 135 | print(f"num1: {num1}, num2: {num2}, num3: {num3}, num4: {num4}" ) 136 | """ 137 | 138 | # 迴圈 + 串列 139 | """ 140 | numbers = [3, 5, 6, 10, 2, 8] 141 | for i in range(len(numbers)): 142 | print(numbers[i], end = " ") 143 | print() # 換行 144 | # 由右到左 145 | for i in range(len(numbers)-1,-1,-1): 146 | print(numbers[i], end = " ") 147 | """ 148 | 149 | # python 風格寫法 150 | """ 151 | numbers = [3, 5, 6, 10, 2, 8] 152 | for v in numbers: 153 | print(v, end=" ") 154 | print() 155 | 156 | # enumerate 157 | for i, v in enumerate(numbers): 158 | print(f"index: {i}, value: {v}") 159 | """ 160 | 161 | # 迴圈 + 串列 (解答) 162 | """ 163 | n = int(input()) 164 | ans = [] 165 | for i in range(n): 166 | temp = int(input()) 167 | ans.append(temp) 168 | print(f"總和: {sum(ans)}, 最小值: {min(ans)}, 最大值: {max(ans)}") 169 | """ 170 | 171 | # 字串 172 | """ 173 | name = "Thousand" 174 | print(name[0]) 175 | print(len(name)) 176 | name = name.lower() # 記得 assign 回去 177 | print(name) 178 | name = name.upper() 179 | print(name) 180 | print(name[0].islower()) 181 | print(name[0].isupper()) 182 | """ 183 | 184 | # 字串 split 185 | """ 186 | s = input() # 3 5 6 10 2 8 187 | print(s.split()) #["3", "5", "6", "10", "2", "8"] 188 | s = input() # 3,5,6,10,2,8 189 | print(s.split(",")) #["3", "5", "6", "10", "2", "8"] 190 | """ 191 | 192 | # 迴圈 + 字串 (解答1) 193 | """ 194 | s = input() 195 | s = s.split() 196 | ans = [] 197 | for v in s: 198 | ans.append(int(v)) 199 | print(ans) 200 | """ 201 | 202 | # 迴圈 + 字串 (解答2) 203 | """ 204 | s = input() 205 | count = 0 206 | for v in s: 207 | if v == "a": 208 | count += 1 209 | print(count) 210 | """ 211 | 212 | # 列表推導式 list comprehension 213 | 214 | # 產生 [0,1,2,3,4,5] 215 | """ 216 | ans = [] 217 | for i in range(6): 218 | ans.append(i) 219 | 220 | ans = [i for i in range(6)] 221 | print(ans) 222 | 223 | # 產生 [0,2,4,6,8,10,12,14,16,18,20] 224 | res = [] 225 | for i in range(21): 226 | if i %2 == 0: 227 | res.append(i) 228 | 229 | res = [i for i in range(21) if i % 2 == 0] 230 | print(res) 231 | """ -------------------------------------------------------------------------------- /class03/main.py: -------------------------------------------------------------------------------- 1 | # 雙層串列 2 | """ 3 | matrix = [[32, 57, 89], [59,20,66], [66,78,82], [32,89,100], [70,100,30]] 4 | print(matrix[0]) 5 | print(matrix[2][1]) 6 | """ 7 | 8 | # 雙層迴圈 9 | """ 10 | for i in range(5): 11 | print(f"{i}: ",end="") 12 | for j in range(3): 13 | print(f"{j}",end=" ") 14 | print() 15 | """ 16 | 17 | # 雙層迴圈 (解答1) 18 | """ 19 | n = int(input()) 20 | for i in range(n): 21 | for j in range(i+1): 22 | print("*",end="") 23 | print() 24 | """ 25 | 26 | # 雙層迴圈 (解答2) 27 | """ 28 | n = int(input()) 29 | for i in range(n): 30 | for j in range(n-i): 31 | print("*",end="") 32 | print() 33 | """ 34 | 35 | # 雙層迴圈 (解答3) 36 | """ 37 | n = int(input()) 38 | for i in range(n): 39 | for j in range(n-i-1): 40 | print(" ",end="") 41 | for k in range(i+1): 42 | print("*",end="") 43 | print() 44 | """ 45 | 46 | # 雙層迴圈 + 雙層串列 47 | """ 48 | matrix = [[32, 57, 89], [59,20,66], [66,78,82], [32,89,100], [70,100,30]] 49 | row = len(matrix) 50 | col = len(matrix[0]) 51 | for i in range(row): 52 | for j in range(col): 53 | print(matrix[i][j],end=" ") 54 | print() 55 | """ 56 | 57 | # 雙層迴圈 + 雙層串列 (解答) 58 | """ 59 | matrix = [[32, 57, 89], [59,20,66], [66,78,82], [32,89,100], [70,100,30]] 60 | row = len(matrix) 61 | row_ans = [0 for i in range(row)] 62 | col = len(matrix[0]) 63 | col_ans = [0 for j in range(col)] 64 | 65 | for i in range(row): 66 | for j in range(col): 67 | row_ans[i] += matrix[i][j] 68 | col_ans[j] += matrix[i][j] 69 | print(f"row 總和: {row_ans}") 70 | print(f"col 總和: {col_ans}") 71 | """ 72 | 73 | # 函式 74 | """ 75 | def show(): 76 | print("Welcome!!") 77 | 78 | def say_hello(name): 79 | print(f"Hello {name}") 80 | 81 | def add_numbers(num1, num2): 82 | print(num1 + num2) 83 | 84 | show() 85 | say_hello(name = "Thousand") # say_hello("Thousand") 86 | add_numbers(num2 = 9, num1 = 3) # add_numbers(3, 9) 87 | """ 88 | 89 | # 函式生命週期 90 | """ 91 | def show(): 92 | number = 3 93 | print(f"This is show function: {number}") 94 | 95 | show() 96 | print(number) # 由於函式的生命週期結束,在此函式內部產生的變數都會消失 97 | """ 98 | 99 | # 操作全域變數 100 | """ 101 | total = 0 102 | 103 | def change_number(): 104 | print(total) # 可以看到區域變數 105 | total += 1 # 不能操作全域變數 106 | 107 | change_number() 108 | """ 109 | 110 | # 全域變數與區域變數同名 111 | """ 112 | total = 3 113 | 114 | def change_number(): 115 | total = 5 116 | total += 3 117 | print(f"This is change_number function: {total}") 118 | 119 | change_number() 120 | print(f"This is main function: {total}") 121 | """ 122 | 123 | # call by reference 124 | """ 125 | num = 3 126 | 127 | def change_number(num): 128 | print(id(num)) 129 | num += 2 130 | print(id(num)) 131 | 132 | print(f"Before change_number function: {num}") 133 | print(id(num)) 134 | change_number(num = num) 135 | print(f"After change_number function: {num}") 136 | """ 137 | 138 | # call by reference (list) 139 | """ 140 | numbers = [3,2,8,10,15,18] 141 | 142 | def change_numbers(numbers): 143 | numbers.append(10) 144 | 145 | print(f"Before change_numbers function: {numbers}") 146 | change_numbers(numbers = numbers) 147 | print(f"After change_numbers function: {numbers}") 148 | """ 149 | 150 | # return 151 | """ 152 | def get_mean(numbers): 153 | total = 0 154 | for v in numbers: 155 | total += v 156 | return total / len(numbers) 157 | 158 | numbers = [85, 95, 96] 159 | ans = get_mean(numbers = numbers) 160 | print(ans) 161 | """ 162 | 163 | # import 164 | """ 165 | import random 166 | # import random as r 167 | # from random import randint 168 | sample = random.randint(1,100) 169 | print(sample) 170 | """ 171 | 172 | # random 函數 (解答) 173 | """ 174 | import random 175 | n = int(input()) 176 | for i in range(n): 177 | print(random.randint(1,100), end=" ") 178 | """ 179 | 180 | # lambda 181 | """ 182 | add = lambda x: x+3 183 | print(add(3)) 184 | print((lambda x: x+3)(3)) 185 | 186 | mul = lambda x,y: x*y 187 | print(mul(3,5)) 188 | """ 189 | 190 | # filter, map, sorted 191 | """ 192 | numbers = [3, 50, 2, 80, 49, 10, 6] 193 | print(list(filter(lambda x: x > 10, numbers))) 194 | print(list(map(lambda x: x + 3, numbers))) 195 | scores = [["Harry", 32], ["Berry", 31], ["Thousand", 21]] 196 | print(sorted(scores, key = lambda x:x[1])) 197 | """ 198 | 199 | # module 200 | """ 201 | import utils 202 | numbers = [30, 60, 50, 80, 100, 57, 90] 203 | utils.say_hello(guest="Thousand") 204 | utils.introduce(name="Thousand", age=30, gender="Male") 205 | 206 | print(utils.get_max(numbers=numbers)) 207 | print(utils.get_distance(point1=[3,5], point2=[6,1])) 208 | 209 | print(f"This is logistic_regression.py: {__name__}") 210 | """ 211 | 212 | # package 213 | import helper.show as show 214 | import helper.calculate as calculate 215 | 216 | numbers = [30, 60, 50, 80, 100, 57, 90] 217 | show.say_hello(guest="Thousand") 218 | show.introduce(name="Thousand", age=30, gender="Male") 219 | 220 | print(calculate.get_max(numbers=numbers)) 221 | print(calculate.get_distance(point1=[3,5], point2=[6,1])) -------------------------------------------------------------------------------- /class09/gender_submission.csv: -------------------------------------------------------------------------------- 1 | PassengerId,Survived 2 | 892,0 3 | 893,1 4 | 894,0 5 | 895,0 6 | 896,1 7 | 897,0 8 | 898,1 9 | 899,0 10 | 900,1 11 | 901,0 12 | 902,0 13 | 903,0 14 | 904,1 15 | 905,0 16 | 906,1 17 | 907,1 18 | 908,0 19 | 909,0 20 | 910,1 21 | 911,1 22 | 912,0 23 | 913,0 24 | 914,1 25 | 915,0 26 | 916,1 27 | 917,0 28 | 918,1 29 | 919,0 30 | 920,0 31 | 921,0 32 | 922,0 33 | 923,0 34 | 924,1 35 | 925,1 36 | 926,0 37 | 927,0 38 | 928,1 39 | 929,1 40 | 930,0 41 | 931,0 42 | 932,0 43 | 933,0 44 | 934,0 45 | 935,1 46 | 936,1 47 | 937,0 48 | 938,0 49 | 939,0 50 | 940,1 51 | 941,1 52 | 942,0 53 | 943,0 54 | 944,1 55 | 945,1 56 | 946,0 57 | 947,0 58 | 948,0 59 | 949,0 60 | 950,0 61 | 951,1 62 | 952,0 63 | 953,0 64 | 954,0 65 | 955,1 66 | 956,0 67 | 957,1 68 | 958,1 69 | 959,0 70 | 960,0 71 | 961,1 72 | 962,1 73 | 963,0 74 | 964,1 75 | 965,0 76 | 966,1 77 | 967,0 78 | 968,0 79 | 969,1 80 | 970,0 81 | 971,1 82 | 972,0 83 | 973,0 84 | 974,0 85 | 975,0 86 | 976,0 87 | 977,0 88 | 978,1 89 | 979,1 90 | 980,1 91 | 981,0 92 | 982,1 93 | 983,0 94 | 984,1 95 | 985,0 96 | 986,0 97 | 987,0 98 | 988,1 99 | 989,0 100 | 990,1 101 | 991,0 102 | 992,1 103 | 993,0 104 | 994,0 105 | 995,0 106 | 996,1 107 | 997,0 108 | 998,0 109 | 999,0 110 | 1000,0 111 | 1001,0 112 | 1002,0 113 | 1003,1 114 | 1004,1 115 | 1005,1 116 | 1006,1 117 | 1007,0 118 | 1008,0 119 | 1009,1 120 | 1010,0 121 | 1011,1 122 | 1012,1 123 | 1013,0 124 | 1014,1 125 | 1015,0 126 | 1016,0 127 | 1017,1 128 | 1018,0 129 | 1019,1 130 | 1020,0 131 | 1021,0 132 | 1022,0 133 | 1023,0 134 | 1024,1 135 | 1025,0 136 | 1026,0 137 | 1027,0 138 | 1028,0 139 | 1029,0 140 | 1030,1 141 | 1031,0 142 | 1032,1 143 | 1033,1 144 | 1034,0 145 | 1035,0 146 | 1036,0 147 | 1037,0 148 | 1038,0 149 | 1039,0 150 | 1040,0 151 | 1041,0 152 | 1042,1 153 | 1043,0 154 | 1044,0 155 | 1045,1 156 | 1046,0 157 | 1047,0 158 | 1048,1 159 | 1049,1 160 | 1050,0 161 | 1051,1 162 | 1052,1 163 | 1053,0 164 | 1054,1 165 | 1055,0 166 | 1056,0 167 | 1057,1 168 | 1058,0 169 | 1059,0 170 | 1060,1 171 | 1061,1 172 | 1062,0 173 | 1063,0 174 | 1064,0 175 | 1065,0 176 | 1066,0 177 | 1067,1 178 | 1068,1 179 | 1069,0 180 | 1070,1 181 | 1071,1 182 | 1072,0 183 | 1073,0 184 | 1074,1 185 | 1075,0 186 | 1076,1 187 | 1077,0 188 | 1078,1 189 | 1079,0 190 | 1080,1 191 | 1081,0 192 | 1082,0 193 | 1083,0 194 | 1084,0 195 | 1085,0 196 | 1086,0 197 | 1087,0 198 | 1088,0 199 | 1089,1 200 | 1090,0 201 | 1091,1 202 | 1092,1 203 | 1093,0 204 | 1094,0 205 | 1095,1 206 | 1096,0 207 | 1097,0 208 | 1098,1 209 | 1099,0 210 | 1100,1 211 | 1101,0 212 | 1102,0 213 | 1103,0 214 | 1104,0 215 | 1105,1 216 | 1106,1 217 | 1107,0 218 | 1108,1 219 | 1109,0 220 | 1110,1 221 | 1111,0 222 | 1112,1 223 | 1113,0 224 | 1114,1 225 | 1115,0 226 | 1116,1 227 | 1117,1 228 | 1118,0 229 | 1119,1 230 | 1120,0 231 | 1121,0 232 | 1122,0 233 | 1123,1 234 | 1124,0 235 | 1125,0 236 | 1126,0 237 | 1127,0 238 | 1128,0 239 | 1129,0 240 | 1130,1 241 | 1131,1 242 | 1132,1 243 | 1133,1 244 | 1134,0 245 | 1135,0 246 | 1136,0 247 | 1137,0 248 | 1138,1 249 | 1139,0 250 | 1140,1 251 | 1141,1 252 | 1142,1 253 | 1143,0 254 | 1144,0 255 | 1145,0 256 | 1146,0 257 | 1147,0 258 | 1148,0 259 | 1149,0 260 | 1150,1 261 | 1151,0 262 | 1152,0 263 | 1153,0 264 | 1154,1 265 | 1155,1 266 | 1156,0 267 | 1157,0 268 | 1158,0 269 | 1159,0 270 | 1160,1 271 | 1161,0 272 | 1162,0 273 | 1163,0 274 | 1164,1 275 | 1165,1 276 | 1166,0 277 | 1167,1 278 | 1168,0 279 | 1169,0 280 | 1170,0 281 | 1171,0 282 | 1172,1 283 | 1173,0 284 | 1174,1 285 | 1175,1 286 | 1176,1 287 | 1177,0 288 | 1178,0 289 | 1179,0 290 | 1180,0 291 | 1181,0 292 | 1182,0 293 | 1183,1 294 | 1184,0 295 | 1185,0 296 | 1186,0 297 | 1187,0 298 | 1188,1 299 | 1189,0 300 | 1190,0 301 | 1191,0 302 | 1192,0 303 | 1193,0 304 | 1194,0 305 | 1195,0 306 | 1196,1 307 | 1197,1 308 | 1198,0 309 | 1199,0 310 | 1200,0 311 | 1201,1 312 | 1202,0 313 | 1203,0 314 | 1204,0 315 | 1205,1 316 | 1206,1 317 | 1207,1 318 | 1208,0 319 | 1209,0 320 | 1210,0 321 | 1211,0 322 | 1212,0 323 | 1213,0 324 | 1214,0 325 | 1215,0 326 | 1216,1 327 | 1217,0 328 | 1218,1 329 | 1219,0 330 | 1220,0 331 | 1221,0 332 | 1222,1 333 | 1223,0 334 | 1224,0 335 | 1225,1 336 | 1226,0 337 | 1227,0 338 | 1228,0 339 | 1229,0 340 | 1230,0 341 | 1231,0 342 | 1232,0 343 | 1233,0 344 | 1234,0 345 | 1235,1 346 | 1236,0 347 | 1237,1 348 | 1238,0 349 | 1239,1 350 | 1240,0 351 | 1241,1 352 | 1242,1 353 | 1243,0 354 | 1244,0 355 | 1245,0 356 | 1246,1 357 | 1247,0 358 | 1248,1 359 | 1249,0 360 | 1250,0 361 | 1251,1 362 | 1252,0 363 | 1253,1 364 | 1254,1 365 | 1255,0 366 | 1256,1 367 | 1257,1 368 | 1258,0 369 | 1259,1 370 | 1260,1 371 | 1261,0 372 | 1262,0 373 | 1263,1 374 | 1264,0 375 | 1265,0 376 | 1266,1 377 | 1267,1 378 | 1268,1 379 | 1269,0 380 | 1270,0 381 | 1271,0 382 | 1272,0 383 | 1273,0 384 | 1274,1 385 | 1275,1 386 | 1276,0 387 | 1277,1 388 | 1278,0 389 | 1279,0 390 | 1280,0 391 | 1281,0 392 | 1282,0 393 | 1283,1 394 | 1284,0 395 | 1285,0 396 | 1286,0 397 | 1287,1 398 | 1288,0 399 | 1289,1 400 | 1290,0 401 | 1291,0 402 | 1292,1 403 | 1293,0 404 | 1294,1 405 | 1295,0 406 | 1296,0 407 | 1297,0 408 | 1298,0 409 | 1299,0 410 | 1300,1 411 | 1301,1 412 | 1302,1 413 | 1303,1 414 | 1304,1 415 | 1305,0 416 | 1306,1 417 | 1307,0 418 | 1308,0 419 | 1309,0 420 | -------------------------------------------------------------------------------- /class08/drug200.csv: -------------------------------------------------------------------------------- 1 | Age,Sex,BP,Cholesterol,Na_to_K,Drug 2 | 23,F,HIGH,HIGH,25.355,drugY 3 | 47,M,LOW,HIGH,13.093,drugC 4 | 47,M,LOW,HIGH,10.114,drugC 5 | 28,F,NORMAL,HIGH,7.798,drugX 6 | 61,F,LOW,HIGH,18.043,drugY 7 | 22,F,NORMAL,HIGH,8.607,drugX 8 | 49,F,NORMAL,HIGH,16.275,drugY 9 | 41,M,LOW,HIGH,11.037,drugC 10 | 60,M,NORMAL,HIGH,15.171,drugY 11 | 43,M,LOW,NORMAL,19.368,drugY 12 | 47,F,LOW,HIGH,11.767,drugC 13 | 34,F,HIGH,NORMAL,19.199,drugY 14 | 43,M,LOW,HIGH,15.376,drugY 15 | 74,F,LOW,HIGH,20.942,drugY 16 | 50,F,NORMAL,HIGH,12.703,drugX 17 | 16,F,HIGH,NORMAL,15.516,drugY 18 | 69,M,LOW,NORMAL,11.455,drugX 19 | 43,M,HIGH,HIGH,13.972,drugA 20 | 23,M,LOW,HIGH,7.298,drugC 21 | 32,F,HIGH,NORMAL,25.974,drugY 22 | 57,M,LOW,NORMAL,19.128,drugY 23 | 63,M,NORMAL,HIGH,25.917,drugY 24 | 47,M,LOW,NORMAL,30.568,drugY 25 | 48,F,LOW,HIGH,15.036,drugY 26 | 33,F,LOW,HIGH,33.486,drugY 27 | 28,F,HIGH,NORMAL,18.809,drugY 28 | 31,M,HIGH,HIGH,30.366,drugY 29 | 49,F,NORMAL,NORMAL,9.381,drugX 30 | 39,F,LOW,NORMAL,22.697,drugY 31 | 45,M,LOW,HIGH,17.951,drugY 32 | 18,F,NORMAL,NORMAL,8.75,drugX 33 | 74,M,HIGH,HIGH,9.567,drugB 34 | 49,M,LOW,NORMAL,11.014,drugX 35 | 65,F,HIGH,NORMAL,31.876,drugY 36 | 53,M,NORMAL,HIGH,14.133,drugX 37 | 46,M,NORMAL,NORMAL,7.285,drugX 38 | 32,M,HIGH,NORMAL,9.445,drugA 39 | 39,M,LOW,NORMAL,13.938,drugX 40 | 39,F,NORMAL,NORMAL,9.709,drugX 41 | 15,M,NORMAL,HIGH,9.084,drugX 42 | 73,F,NORMAL,HIGH,19.221,drugY 43 | 58,F,HIGH,NORMAL,14.239,drugB 44 | 50,M,NORMAL,NORMAL,15.79,drugY 45 | 23,M,NORMAL,HIGH,12.26,drugX 46 | 50,F,NORMAL,NORMAL,12.295,drugX 47 | 66,F,NORMAL,NORMAL,8.107,drugX 48 | 37,F,HIGH,HIGH,13.091,drugA 49 | 68,M,LOW,HIGH,10.291,drugC 50 | 23,M,NORMAL,HIGH,31.686,drugY 51 | 28,F,LOW,HIGH,19.796,drugY 52 | 58,F,HIGH,HIGH,19.416,drugY 53 | 67,M,NORMAL,NORMAL,10.898,drugX 54 | 62,M,LOW,NORMAL,27.183,drugY 55 | 24,F,HIGH,NORMAL,18.457,drugY 56 | 68,F,HIGH,NORMAL,10.189,drugB 57 | 26,F,LOW,HIGH,14.16,drugC 58 | 65,M,HIGH,NORMAL,11.34,drugB 59 | 40,M,HIGH,HIGH,27.826,drugY 60 | 60,M,NORMAL,NORMAL,10.091,drugX 61 | 34,M,HIGH,HIGH,18.703,drugY 62 | 38,F,LOW,NORMAL,29.875,drugY 63 | 24,M,HIGH,NORMAL,9.475,drugA 64 | 67,M,LOW,NORMAL,20.693,drugY 65 | 45,M,LOW,NORMAL,8.37,drugX 66 | 60,F,HIGH,HIGH,13.303,drugB 67 | 68,F,NORMAL,NORMAL,27.05,drugY 68 | 29,M,HIGH,HIGH,12.856,drugA 69 | 17,M,NORMAL,NORMAL,10.832,drugX 70 | 54,M,NORMAL,HIGH,24.658,drugY 71 | 18,F,HIGH,NORMAL,24.276,drugY 72 | 70,M,HIGH,HIGH,13.967,drugB 73 | 28,F,NORMAL,HIGH,19.675,drugY 74 | 24,F,NORMAL,HIGH,10.605,drugX 75 | 41,F,NORMAL,NORMAL,22.905,drugY 76 | 31,M,HIGH,NORMAL,17.069,drugY 77 | 26,M,LOW,NORMAL,20.909,drugY 78 | 36,F,HIGH,HIGH,11.198,drugA 79 | 26,F,HIGH,NORMAL,19.161,drugY 80 | 19,F,HIGH,HIGH,13.313,drugA 81 | 32,F,LOW,NORMAL,10.84,drugX 82 | 60,M,HIGH,HIGH,13.934,drugB 83 | 64,M,NORMAL,HIGH,7.761,drugX 84 | 32,F,LOW,HIGH,9.712,drugC 85 | 38,F,HIGH,NORMAL,11.326,drugA 86 | 47,F,LOW,HIGH,10.067,drugC 87 | 59,M,HIGH,HIGH,13.935,drugB 88 | 51,F,NORMAL,HIGH,13.597,drugX 89 | 69,M,LOW,HIGH,15.478,drugY 90 | 37,F,HIGH,NORMAL,23.091,drugY 91 | 50,F,NORMAL,NORMAL,17.211,drugY 92 | 62,M,NORMAL,HIGH,16.594,drugY 93 | 41,M,HIGH,NORMAL,15.156,drugY 94 | 29,F,HIGH,HIGH,29.45,drugY 95 | 42,F,LOW,NORMAL,29.271,drugY 96 | 56,M,LOW,HIGH,15.015,drugY 97 | 36,M,LOW,NORMAL,11.424,drugX 98 | 58,F,LOW,HIGH,38.247,drugY 99 | 56,F,HIGH,HIGH,25.395,drugY 100 | 20,M,HIGH,NORMAL,35.639,drugY 101 | 15,F,HIGH,NORMAL,16.725,drugY 102 | 31,M,HIGH,NORMAL,11.871,drugA 103 | 45,F,HIGH,HIGH,12.854,drugA 104 | 28,F,LOW,HIGH,13.127,drugC 105 | 56,M,NORMAL,HIGH,8.966,drugX 106 | 22,M,HIGH,NORMAL,28.294,drugY 107 | 37,M,LOW,NORMAL,8.968,drugX 108 | 22,M,NORMAL,HIGH,11.953,drugX 109 | 42,M,LOW,HIGH,20.013,drugY 110 | 72,M,HIGH,NORMAL,9.677,drugB 111 | 23,M,NORMAL,HIGH,16.85,drugY 112 | 50,M,HIGH,HIGH,7.49,drugA 113 | 47,F,NORMAL,NORMAL,6.683,drugX 114 | 35,M,LOW,NORMAL,9.17,drugX 115 | 65,F,LOW,NORMAL,13.769,drugX 116 | 20,F,NORMAL,NORMAL,9.281,drugX 117 | 51,M,HIGH,HIGH,18.295,drugY 118 | 67,M,NORMAL,NORMAL,9.514,drugX 119 | 40,F,NORMAL,HIGH,10.103,drugX 120 | 32,F,HIGH,NORMAL,10.292,drugA 121 | 61,F,HIGH,HIGH,25.475,drugY 122 | 28,M,NORMAL,HIGH,27.064,drugY 123 | 15,M,HIGH,NORMAL,17.206,drugY 124 | 34,M,NORMAL,HIGH,22.456,drugY 125 | 36,F,NORMAL,HIGH,16.753,drugY 126 | 53,F,HIGH,NORMAL,12.495,drugB 127 | 19,F,HIGH,NORMAL,25.969,drugY 128 | 66,M,HIGH,HIGH,16.347,drugY 129 | 35,M,NORMAL,NORMAL,7.845,drugX 130 | 47,M,LOW,NORMAL,33.542,drugY 131 | 32,F,NORMAL,HIGH,7.477,drugX 132 | 70,F,NORMAL,HIGH,20.489,drugY 133 | 52,M,LOW,NORMAL,32.922,drugY 134 | 49,M,LOW,NORMAL,13.598,drugX 135 | 24,M,NORMAL,HIGH,25.786,drugY 136 | 42,F,HIGH,HIGH,21.036,drugY 137 | 74,M,LOW,NORMAL,11.939,drugX 138 | 55,F,HIGH,HIGH,10.977,drugB 139 | 35,F,HIGH,HIGH,12.894,drugA 140 | 51,M,HIGH,NORMAL,11.343,drugB 141 | 69,F,NORMAL,HIGH,10.065,drugX 142 | 49,M,HIGH,NORMAL,6.269,drugA 143 | 64,F,LOW,NORMAL,25.741,drugY 144 | 60,M,HIGH,NORMAL,8.621,drugB 145 | 74,M,HIGH,NORMAL,15.436,drugY 146 | 39,M,HIGH,HIGH,9.664,drugA 147 | 61,M,NORMAL,HIGH,9.443,drugX 148 | 37,F,LOW,NORMAL,12.006,drugX 149 | 26,F,HIGH,NORMAL,12.307,drugA 150 | 61,F,LOW,NORMAL,7.34,drugX 151 | 22,M,LOW,HIGH,8.151,drugC 152 | 49,M,HIGH,NORMAL,8.7,drugA 153 | 68,M,HIGH,HIGH,11.009,drugB 154 | 55,M,NORMAL,NORMAL,7.261,drugX 155 | 72,F,LOW,NORMAL,14.642,drugX 156 | 37,M,LOW,NORMAL,16.724,drugY 157 | 49,M,LOW,HIGH,10.537,drugC 158 | 31,M,HIGH,NORMAL,11.227,drugA 159 | 53,M,LOW,HIGH,22.963,drugY 160 | 59,F,LOW,HIGH,10.444,drugC 161 | 34,F,LOW,NORMAL,12.923,drugX 162 | 30,F,NORMAL,HIGH,10.443,drugX 163 | 57,F,HIGH,NORMAL,9.945,drugB 164 | 43,M,NORMAL,NORMAL,12.859,drugX 165 | 21,F,HIGH,NORMAL,28.632,drugY 166 | 16,M,HIGH,NORMAL,19.007,drugY 167 | 38,M,LOW,HIGH,18.295,drugY 168 | 58,F,LOW,HIGH,26.645,drugY 169 | 57,F,NORMAL,HIGH,14.216,drugX 170 | 51,F,LOW,NORMAL,23.003,drugY 171 | 20,F,HIGH,HIGH,11.262,drugA 172 | 28,F,NORMAL,HIGH,12.879,drugX 173 | 45,M,LOW,NORMAL,10.017,drugX 174 | 39,F,NORMAL,NORMAL,17.225,drugY 175 | 41,F,LOW,NORMAL,18.739,drugY 176 | 42,M,HIGH,NORMAL,12.766,drugA 177 | 73,F,HIGH,HIGH,18.348,drugY 178 | 48,M,HIGH,NORMAL,10.446,drugA 179 | 25,M,NORMAL,HIGH,19.011,drugY 180 | 39,M,NORMAL,HIGH,15.969,drugY 181 | 67,F,NORMAL,HIGH,15.891,drugY 182 | 22,F,HIGH,NORMAL,22.818,drugY 183 | 59,F,NORMAL,HIGH,13.884,drugX 184 | 20,F,LOW,NORMAL,11.686,drugX 185 | 36,F,HIGH,NORMAL,15.49,drugY 186 | 18,F,HIGH,HIGH,37.188,drugY 187 | 57,F,NORMAL,NORMAL,25.893,drugY 188 | 70,M,HIGH,HIGH,9.849,drugB 189 | 47,M,HIGH,HIGH,10.403,drugA 190 | 65,M,HIGH,NORMAL,34.997,drugY 191 | 64,M,HIGH,NORMAL,20.932,drugY 192 | 58,M,HIGH,HIGH,18.991,drugY 193 | 23,M,HIGH,HIGH,8.011,drugA 194 | 72,M,LOW,HIGH,16.31,drugY 195 | 72,M,LOW,HIGH,6.769,drugC 196 | 46,F,HIGH,HIGH,34.686,drugY 197 | 56,F,LOW,HIGH,11.567,drugC 198 | 16,M,LOW,HIGH,12.006,drugC 199 | 52,M,NORMAL,HIGH,9.894,drugX 200 | 23,M,NORMAL,NORMAL,14.02,drugX 201 | 40,F,LOW,NORMAL,11.349,drugX -------------------------------------------------------------------------------- /class04/main.py: -------------------------------------------------------------------------------- 1 | # 函式 2 | """ 3 | def get_sum(course,*args): 4 | scores = sum(args) 5 | print(f"{course} 總分為: {scores}") 6 | 7 | get_sum("Math",30,20,60,80,100,90,70,98) 8 | 9 | def get_sports(sports, **kwargs): 10 | print(sports) 11 | print(kwargs) 12 | for k,v in kwargs.items(): 13 | print(f"{k}: {v}") 14 | 15 | get_sports( "basketball",curry=[15,10,5,10], thompson= [20,10,10,5] ) 16 | """ 17 | 18 | # dictionary 19 | """ 20 | dic = {"sports":["basketball", "football"], "name": ["Allie", "Thousand"]} 21 | print(dic["sports"]) 22 | print(dic["sports"][0]) 23 | 24 | # 新增 key 25 | dic["scores"] = [70, 80, 90, 100] # 跟 list 新增方式不一樣,更為簡單 26 | dic["hobby"] = "Reading" # value 也可以只有一個人 27 | print(dic) 28 | 29 | # 迴圈 + 字典 30 | 31 | for key in dic.keys(): 32 | print(f"key is: {key}") 33 | 34 | for value in dic.values(): 35 | print(f"value is: {value}") 36 | 37 | for key, value in dic.items(): 38 | print(f"key is: {key}, and value is: {value}") 39 | """ 40 | 41 | # 迴圈 + 字典 (解答) 42 | """ 43 | n = int(input()) 44 | dic = {} 45 | for i in range(n): 46 | tem = input().split() 47 | if tem[0] not in dic: 48 | dic[tem[0]] = [int(tem[1])] 49 | else: 50 | dic[tem[0]] += [int(tem[1])] 51 | 52 | print(dic) 53 | """ 54 | 55 | # sorted + 字典 (解答) 56 | """ 57 | dic = {"Harry":32,"Berry":31,"Thousand":21,"Becky":50,"Allie":37} 58 | sorted_tuple = sorted(dic.items(), key=lambda item: item[1]) 59 | sorted_dic = {key: value for key, value in sorted_tuple} 60 | print(sorted_dic) 61 | """ 62 | 63 | # 物件導向建構子 (Warrior) 64 | """ 65 | class Warrior: 66 | def __init__(self, name, gender, weapon="bat"): 67 | self.lv = 1 68 | self.exp = 0 69 | self.n = name 70 | self.g = gender 71 | self.w = weapon 72 | self.sp = 100 73 | print("This is Warrior class.") 74 | 75 | def __str__(self): 76 | return f"Name: {self.n}, Gender: {self.g}, Weapon: {self.w}, Level: {self.lv}, Exp: {self.exp}" 77 | 78 | def attack(self, enemy): 79 | self.exp += 40 80 | enemy.hp -= 1 81 | self.level_up() 82 | print(f"{self.n} attacked! Level: {self.lv}, Exp: {self.exp}, Enemy Hp: {enemy.hp}") 83 | 84 | def level_up(self): 85 | if self.exp >= 100: 86 | self.lv += 1 87 | self.exp -= 100 88 | 89 | 90 | class Enemy: 91 | def __init__(self): 92 | self.name = "Monster" 93 | self.hp = 100 94 | 95 | warrior1 = Warrior(name = "Thousand", gender = "Male", weapon = "Sword") 96 | warrior2 = Warrior(name = "Allie", gender = "Female", weapon = "Longbow") 97 | e1 = Enemy() 98 | print(f"Warrior: {warrior1}") 99 | 100 | for i in range(5): 101 | warrior1.attack(e1) 102 | """ 103 | 104 | # Magician 105 | """ 106 | class Magician: 107 | def __init__(self, name, gender, weapon="bat"): 108 | self.lv = 1 109 | self.exp = 0 110 | self.n = name 111 | self.g = gender 112 | self.w = weapon 113 | self.mp = 100 114 | print("This is Magician class.") 115 | 116 | def __str__(self): 117 | return f"Name: {self.n}, Gender: {self.g}, Weapon: {self.w}, Level: {self.lv}, Exp: {self.exp}" 118 | 119 | def attack(self, enemy): 120 | self.exp += 40 121 | enemy.hp -= 1 122 | self.level_up() 123 | print(f"{self.n} attacked! Level: {self.lv}, Exp: {self.exp}, Enemy Hp: {enemy.hp}") 124 | 125 | def level_up(self): 126 | if self.exp >= 100: 127 | self.lv += 1 128 | self.exp -= 100 129 | """ 130 | 131 | # inheritance 132 | """ 133 | class Character: 134 | def __init__(self, name, gender, weapon="bat"): 135 | self.lv = 1 136 | self.exp = 0 137 | self.n = name 138 | self.g = gender 139 | self.w = weapon 140 | print("This is Character class.") 141 | def __str__(self): 142 | return f"Name: {self.n}, Gender: {self.g}, Weapon: {self.w}, Level: {self.lv}, Exp: {self.exp}" 143 | 144 | def attack(self, enemy): 145 | self.exp += 40 146 | enemy.hp -= 1 147 | self.level_up() 148 | print(f"{self.n} attacked! Level: {self.lv}, Exp: {self.exp}, Enemy Hp: {enemy.hp}", end = " ") 149 | 150 | def level_up(self): 151 | if self.exp >= 100: 152 | self.lv += 1 153 | self.exp -= 100 154 | 155 | class Warrior(Character): 156 | def __init__(self, name, gender, weapon="bat"): 157 | super().__init__(name, gender, weapon) 158 | self.sp = 100 159 | 160 | # override 161 | def attack(self,enemy): 162 | super().attack(enemy) 163 | #print(f"{self.n} attacked {enemy.n} with {self.w}") 164 | print(f"with {self.w}") 165 | 166 | def bash(self, enemy): 167 | if self.lv >= 5: 168 | print(f"{self.n} used bash.") 169 | enemy.hp -= 10 170 | else: 171 | print("等級5才能使用") 172 | 173 | class Magician(Character): 174 | def __init__(self, name, gender, weapon="bat"): 175 | super().__init__(name, gender, weapon) 176 | self.mp = 100 177 | 178 | def fireball(self,enemy): 179 | if self.lv >= 5: 180 | print(f"{self.n} used fireball.") 181 | enemy.hp -= 10 182 | else: 183 | print("等級5才能使用") 184 | 185 | class Enemy: 186 | def __init__(self): 187 | self.n = 'Monster' 188 | self.hp = 100 189 | 190 | warrior1 = Warrior(name="Thousand", gender="Male", weapon="Sword") 191 | magician1 = Magician(name="Allie", gender="Female", weapon="Wand") 192 | e1 = Enemy() 193 | 194 | print(warrior1) 195 | print(magician1) 196 | 197 | for i in range(10): 198 | warrior1.attack(enemy=e1) # override 199 | 200 | warrior1.bash(enemy=e1) 201 | magician1.fireball(enemy=e1) 202 | """ 203 | 204 | import numpy as np 205 | 206 | # numpy basic 207 | """ 208 | a = np.array([1,2,3]) 209 | b = np.array([[1.0,2.0,3.0],[3.2,5.7,8.2]]) 210 | print(f"a: {a}") 211 | print(f"a dimension: {a.ndim}") 212 | print(f"a shape: {a.shape}") 213 | print(f"a type: {a.dtype}") 214 | print(f"b: {b}") 215 | print(f"b dimension: {b.ndim}") 216 | print(f"b shape: {b.shape}") 217 | print(f"b type: {b.dtype}") 218 | """ 219 | 220 | # index/slice/2D 221 | """ 222 | a = np.array([[1,2,3,4,5,6],[7,8,9,10,11,12]]) 223 | print(a[1,2]) # 8 224 | print(a[0,:]) # [1,2,3,4,5] 225 | print(a[:,2]) # [3,8] 226 | print(a[0,1:5:2]) # [2,4] (start,stop,step) 227 | a[1,2] = 20 228 | print(a) 229 | a[:,2] = [7,8] 230 | print(a) 231 | """ 232 | 233 | # index/slice/3D 234 | """ 235 | a = np.array([[[1,2],[3,5],[7,8]], 236 | [[1,7],[-3,2],[10,2]], 237 | [[6,-2],[5,-3],[7,9]], 238 | [[8,5],[-2,2],[26,-2]], 239 | [[1,-7],[-3,2],[-5,-2]],]) 240 | 241 | print(a) 242 | print(a.shape) 243 | print(a[3,2,0]) 244 | print(a[:,1,:]) 245 | """ 246 | 247 | # initializing 248 | """ 249 | a = np.zeros((5,3,2)) 250 | b = np.ones((2,3)) 251 | c = np.ones((2,3), dtype=np.int32) 252 | d = np.full((2,3), 100, dtype=np.float32) 253 | print(a) 254 | print(b,b.dtype) 255 | print(c,c.dtype) 256 | print(d,d.dtype) 257 | """ 258 | 259 | # random 260 | """ 261 | x = np.random.rand(3,2) 262 | y = np.random.randint(low=10, high=100, size= (3,2)) 263 | print(x) 264 | print(y) 265 | """ 266 | 267 | # 基本運算 268 | """ 269 | a = np.array([[1,2,3],[4,5,6]]) 270 | print(a + 2) 271 | print(a - 2) 272 | print(a * 2) 273 | print(a / 2) 274 | print(a ** 2) 275 | """ 276 | 277 | # 運算 (list vs. array) 278 | """ 279 | a = [1,2,3] 280 | b = [4,5,6] 281 | c = [] 282 | for i in range(len(a)): 283 | c.append(a[i] + b[i]) 284 | print(c) 285 | print(a+b) # 相加是串列相加 286 | 287 | x = np.array([1,2,3]) 288 | y = np.array([4,5,6]) 289 | print(x+y) # 平行運算 290 | 291 | """ 292 | 293 | # 矩陣乘法 294 | """ 295 | a = np.array([[1,2],[3,4],[5,6]]) 296 | b = np.array([[2,3,1],[5,2,1]]) 297 | print(np.matmul(a,b)) 298 | """ 299 | 300 | # 乘法單位元素 301 | """ 302 | a = np.array([[1,2,3],[4,5,6],[7,8,9]]) 303 | identity = np.identity(3) 304 | print(np.matmul(a,identity)) 305 | """ 306 | 307 | # copy 308 | """ 309 | a = np.array([[1,2],[3,4]]) 310 | b = a 311 | b[0,0] = 3 312 | print(a) 313 | print(b) 314 | c = a.copy() 315 | c[0,0] = 5 316 | c[1,0] = -1 317 | print(a) 318 | print(b) 319 | print(c) 320 | """ 321 | 322 | # statistics 323 | a = np.array([[92,83,56,77,98],[81,53,64,76,60]]) 324 | print(np.max(a,axis=0)) 325 | print(np.max(a,axis=1)) 326 | print(np.sum(a,axis=0)) 327 | print(np.sum(a,axis=1)) -------------------------------------------------------------------------------- /class07/logistic_regression.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "logistic_regression.ipynb", 7 | "provenance": [], 8 | "mount_file_id": "1q4B3L_KzcXiLGeUZULfQ8f_WDoflM7JC", 9 | "authorship_tag": "ABX9TyPFZPI+TvFrHPFyiuoXWb8W", 10 | "include_colab_link": true 11 | }, 12 | "kernelspec": { 13 | "name": "python3", 14 | "display_name": "Python 3" 15 | }, 16 | "language_info": { 17 | "name": "python" 18 | } 19 | }, 20 | "cells": [ 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "id": "view-in-github", 25 | "colab_type": "text" 26 | }, 27 | "source": [ 28 | "\"Open" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "source": [ 34 | "# **Logistic Regression**" 35 | ], 36 | "metadata": { 37 | "id": "a4WSNbJMhqYo" 38 | } 39 | }, 40 | { 41 | "cell_type": "code", 42 | "source": [ 43 | "import numpy as np\n", 44 | "import pandas as pd" 45 | ], 46 | "metadata": { 47 | "id": "8nY0F3aKhufH" 48 | }, 49 | "execution_count": 1, 50 | "outputs": [] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "source": [ 55 | "## **讀取資料**" 56 | ], 57 | "metadata": { 58 | "id": "d2WIewwphxia" 59 | } 60 | }, 61 | { 62 | "cell_type": "code", 63 | "source": [ 64 | "data = pd.read_csv(\"https://raw.githubusercontent.com/ThousandAI/pycs4001/main/class07/advertising.csv\")\n", 65 | "data.head()" 66 | ], 67 | "metadata": { 68 | "id": "tSgJ5u0eiwJR", 69 | "colab": { 70 | "base_uri": "https://localhost:8080/", 71 | "height": 372 72 | }, 73 | "outputId": "97b9a252-60d2-4822-bbe7-f11f6b3eee65" 74 | }, 75 | "execution_count": 2, 76 | "outputs": [ 77 | { 78 | "output_type": "execute_result", 79 | "data": { 80 | "text/plain": [ 81 | " Daily Time Spent on Site Age Area Income Daily Internet Usage \\\n", 82 | "0 68.95 35 61833.90 256.09 \n", 83 | "1 80.23 31 68441.85 193.77 \n", 84 | "2 69.47 26 59785.94 236.50 \n", 85 | "3 74.15 29 54806.18 245.89 \n", 86 | "4 68.37 35 73889.99 225.58 \n", 87 | "\n", 88 | " Ad Topic Line City Male Country \\\n", 89 | "0 Cloned 5thgeneration orchestration Wrightburgh 0 Tunisia \n", 90 | "1 Monitored national standardization West Jodi 1 Nauru \n", 91 | "2 Organic bottom-line service-desk Davidton 0 San Marino \n", 92 | "3 Triple-buffered reciprocal time-frame West Terrifurt 1 Italy \n", 93 | "4 Robust logistical utilization South Manuel 0 Iceland \n", 94 | "\n", 95 | " Timestamp Clicked on Ad \n", 96 | "0 2016-03-27 00:53:11 0 \n", 97 | "1 2016-04-04 01:39:02 0 \n", 98 | "2 2016-03-13 20:35:42 0 \n", 99 | "3 2016-01-10 02:31:19 0 \n", 100 | "4 2016-06-03 03:36:18 0 " 101 | ], 102 | "text/html": [ 103 | "\n", 104 | "
\n", 105 | "
\n", 106 | "
\n", 107 | "\n", 120 | "\n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | "
Daily Time Spent on SiteAgeArea IncomeDaily Internet UsageAd Topic LineCityMaleCountryTimestampClicked on Ad
068.953561833.90256.09Cloned 5thgeneration orchestrationWrightburgh0Tunisia2016-03-27 00:53:110
180.233168441.85193.77Monitored national standardizationWest Jodi1Nauru2016-04-04 01:39:020
269.472659785.94236.50Organic bottom-line service-deskDavidton0San Marino2016-03-13 20:35:420
374.152954806.18245.89Triple-buffered reciprocal time-frameWest Terrifurt1Italy2016-01-10 02:31:190
468.373573889.99225.58Robust logistical utilizationSouth Manuel0Iceland2016-06-03 03:36:180
\n", 204 | "
\n", 205 | " \n", 215 | " \n", 216 | " \n", 253 | "\n", 254 | " \n", 278 | "
\n", 279 | "
\n", 280 | " " 281 | ] 282 | }, 283 | "metadata": {}, 284 | "execution_count": 2 285 | } 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "source": [ 291 | "from sklearn.model_selection import train_test_split\n", 292 | "X = np.array(data[[\"Daily Time Spent on Site\", \"Age\", \"Area Income\", \"Daily Internet Usage\", \"Male\"]])\n", 293 | "Y = np.array(data[\"Clicked on Ad\"])\n", 294 | "train_x, test_x, train_y, test_y = train_test_split(X, Y, test_size=0.2, random_state=10)" 295 | ], 296 | "metadata": { 297 | "id": "U7-XLIcCiBzE" 298 | }, 299 | "execution_count": 3, 300 | "outputs": [] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "source": [ 305 | "## **標準化數據**" 306 | ], 307 | "metadata": { 308 | "id": "BlKn4erYiHCr" 309 | } 310 | }, 311 | { 312 | "cell_type": "code", 313 | "source": [ 314 | "from sklearn.preprocessing import StandardScaler\n", 315 | "scaler_x = StandardScaler()\n", 316 | "sc_train_x = scaler_x.fit_transform(train_x)" 317 | ], 318 | "metadata": { 319 | "id": "UqT9idCyiKQK" 320 | }, 321 | "execution_count": 4, 322 | "outputs": [] 323 | }, 324 | { 325 | "cell_type": "markdown", 326 | "source": [ 327 | "## **搭建模型**" 328 | ], 329 | "metadata": { 330 | "id": "87ES28aTiQvg" 331 | } 332 | }, 333 | { 334 | "cell_type": "code", 335 | "source": [ 336 | "from sklearn.linear_model import LogisticRegression\n", 337 | "logistic = LogisticRegression()" 338 | ], 339 | "metadata": { 340 | "id": "Eib07yJilzoP" 341 | }, 342 | "execution_count": 5, 343 | "outputs": [] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "source": [ 348 | "## **訓練模型**" 349 | ], 350 | "metadata": { 351 | "id": "kEmUvSF3iWXL" 352 | } 353 | }, 354 | { 355 | "cell_type": "code", 356 | "source": [ 357 | "logistic.fit(train_x,train_y)" 358 | ], 359 | "metadata": { 360 | "colab": { 361 | "base_uri": "https://localhost:8080/" 362 | }, 363 | "id": "tdRKR7l3iZJQ", 364 | "outputId": "f3e67f17-9dd3-47ce-aa24-7e5283c5fa1d" 365 | }, 366 | "execution_count": 6, 367 | "outputs": [ 368 | { 369 | "output_type": "execute_result", 370 | "data": { 371 | "text/plain": [ 372 | "LogisticRegression()" 373 | ] 374 | }, 375 | "metadata": {}, 376 | "execution_count": 6 377 | } 378 | ] 379 | }, 380 | { 381 | "cell_type": "markdown", 382 | "source": [ 383 | "## **評估模型**" 384 | ], 385 | "metadata": { 386 | "id": "r8ee2OUnidON" 387 | } 388 | }, 389 | { 390 | "cell_type": "code", 391 | "source": [ 392 | "from sklearn.metrics import confusion_matrix" 393 | ], 394 | "metadata": { 395 | "id": "ZhlNdEvRl9aq" 396 | }, 397 | "execution_count": 7, 398 | "outputs": [] 399 | }, 400 | { 401 | "cell_type": "code", 402 | "source": [ 403 | "sc_test_x = scaler_x.transform(test_x)\n", 404 | "y_hat = logistic.predict(sc_test_x)\n", 405 | "print(confusion_matrix(test_y, y_hat))" 406 | ], 407 | "metadata": { 408 | "id": "qz4vHKO2mPk6", 409 | "colab": { 410 | "base_uri": "https://localhost:8080/" 411 | }, 412 | "outputId": "3d3fbce5-1431-4ece-c7ee-c6b450cdaa9a" 413 | }, 414 | "execution_count": 8, 415 | "outputs": [ 416 | { 417 | "output_type": "stream", 418 | "name": "stdout", 419 | "text": [ 420 | "[[83 13]\n", 421 | " [20 84]]\n" 422 | ] 423 | } 424 | ] 425 | } 426 | ] 427 | } -------------------------------------------------------------------------------- /class07/standardscaler.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "standardscaler.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyNRqr824JfSKqvexfU62rev", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": { 34 | "id": "UYmzZ4iuuErc" 35 | }, 36 | "outputs": [], 37 | "source": [ 38 | "import numpy as np\n", 39 | "from sklearn.preprocessing import StandardScaler" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "source": [ 45 | "x = np.array([1,2,5,1,7,8,10,12,5,6])" 46 | ], 47 | "metadata": { 48 | "id": "_GeHK65fuRJJ" 49 | }, 50 | "execution_count": 2, 51 | "outputs": [] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "source": [ 56 | "scaler = StandardScaler()" 57 | ], 58 | "metadata": { 59 | "id": "kCC53Ljoua6e" 60 | }, 61 | "execution_count": 3, 62 | "outputs": [] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "source": [ 67 | "scaler.fit_transform(x)" 68 | ], 69 | "metadata": { 70 | "colab": { 71 | "base_uri": "https://localhost:8080/", 72 | "height": 375 73 | }, 74 | "id": "jPxgncgdudZc", 75 | "outputId": "584449da-c4c1-4fc2-a97d-8542a557fd11" 76 | }, 77 | "execution_count": 4, 78 | "outputs": [ 79 | { 80 | "output_type": "error", 81 | "ename": "ValueError", 82 | "evalue": "ignored", 83 | "traceback": [ 84 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 85 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", 86 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mscaler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit_transform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 87 | "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/sklearn/base.py\u001b[0m in \u001b[0;36mfit_transform\u001b[0;34m(self, X, y, **fit_params)\u001b[0m\n\u001b[1;32m 850\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0my\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 851\u001b[0m \u001b[0;31m# fit method of arity 1 (unsupervised transformation)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 852\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfit_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 853\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 854\u001b[0m \u001b[0;31m# fit method of arity 2 (supervised transformation)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 88 | "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/sklearn/preprocessing/_data.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y, sample_weight)\u001b[0m\n\u001b[1;32m 804\u001b[0m \u001b[0;31m# Reset internal state before fitting\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 805\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_reset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 806\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpartial_fit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 807\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 808\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mpartial_fit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 89 | "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/sklearn/preprocessing/_data.py\u001b[0m in \u001b[0;36mpartial_fit\u001b[0;34m(self, X, y, sample_weight)\u001b[0m\n\u001b[1;32m 845\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mFLOAT_DTYPES\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 846\u001b[0m \u001b[0mforce_all_finite\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"allow-nan\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 847\u001b[0;31m \u001b[0mreset\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfirst_call\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 848\u001b[0m )\n\u001b[1;32m 849\u001b[0m \u001b[0mn_features\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 90 | "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/sklearn/base.py\u001b[0m in \u001b[0;36m_validate_data\u001b[0;34m(self, X, y, reset, validate_separately, **check_params)\u001b[0m\n\u001b[1;32m 564\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Validation should be done on X, y or both.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 565\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mno_val_X\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mno_val_y\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 566\u001b[0;31m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcheck_array\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mcheck_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 567\u001b[0m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 568\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mno_val_X\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mno_val_y\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 91 | "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[0;34m(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator)\u001b[0m\n\u001b[1;32m 771\u001b[0m \u001b[0;34m\"Reshape your data either using array.reshape(-1, 1) if \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 772\u001b[0m \u001b[0;34m\"your data has a single feature or array.reshape(1, -1) \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 773\u001b[0;31m \u001b[0;34m\"if it contains a single sample.\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 774\u001b[0m )\n\u001b[1;32m 775\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 92 | "\u001b[0;31mValueError\u001b[0m: Expected 2D array, got 1D array instead:\narray=[ 1. 2. 5. 1. 7. 8. 10. 12. 5. 6.].\nReshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample." 93 | ] 94 | } 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "source": [ 100 | "## **Shape**" 101 | ], 102 | "metadata": { 103 | "id": "NzU4siaQuqM7" 104 | } 105 | }, 106 | { 107 | "cell_type": "code", 108 | "source": [ 109 | "print(x.shape)" 110 | ], 111 | "metadata": { 112 | "colab": { 113 | "base_uri": "https://localhost:8080/" 114 | }, 115 | "id": "s0LIjex8uhzV", 116 | "outputId": "d53b04b9-87a7-44f7-a19c-20e6ac7248e8" 117 | }, 118 | "execution_count": 5, 119 | "outputs": [ 120 | { 121 | "output_type": "stream", 122 | "name": "stdout", 123 | "text": [ 124 | "(10,)\n" 125 | ] 126 | } 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "source": [ 132 | "x = x.reshape(-1, 1)\n", 133 | "print(x)" 134 | ], 135 | "metadata": { 136 | "colab": { 137 | "base_uri": "https://localhost:8080/" 138 | }, 139 | "id": "tKBBVT11uuc2", 140 | "outputId": "d521c2a4-a655-4dbf-ad6f-b3af5e3b5634" 141 | }, 142 | "execution_count": 6, 143 | "outputs": [ 144 | { 145 | "output_type": "stream", 146 | "name": "stdout", 147 | "text": [ 148 | "[[ 1]\n", 149 | " [ 2]\n", 150 | " [ 5]\n", 151 | " [ 1]\n", 152 | " [ 7]\n", 153 | " [ 8]\n", 154 | " [10]\n", 155 | " [12]\n", 156 | " [ 5]\n", 157 | " [ 6]]\n" 158 | ] 159 | } 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "source": [ 165 | "## **fit**" 166 | ], 167 | "metadata": { 168 | "id": "Lwju3TXgwXUO" 169 | } 170 | }, 171 | { 172 | "cell_type": "code", 173 | "source": [ 174 | "scaler.fit(x)" 175 | ], 176 | "metadata": { 177 | "colab": { 178 | "base_uri": "https://localhost:8080/" 179 | }, 180 | "id": "XklP9liXvFox", 181 | "outputId": "04c062aa-6698-41e7-ed35-aed0b3061026" 182 | }, 183 | "execution_count": 7, 184 | "outputs": [ 185 | { 186 | "output_type": "execute_result", 187 | "data": { 188 | "text/plain": [ 189 | "StandardScaler()" 190 | ] 191 | }, 192 | "metadata": {}, 193 | "execution_count": 7 194 | } 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "source": [ 200 | "sc_x = scaler.transform(x)\n", 201 | "print(sc_x)" 202 | ], 203 | "metadata": { 204 | "colab": { 205 | "base_uri": "https://localhost:8080/" 206 | }, 207 | "id": "9ONdk4IOwnbM", 208 | "outputId": "c122c757-5837-414e-d0f8-287a08a7c6cb" 209 | }, 210 | "execution_count": 8, 211 | "outputs": [ 212 | { 213 | "output_type": "stream", 214 | "name": "stdout", 215 | "text": [ 216 | "[[-1.33417245]\n", 217 | " [-1.05030597]\n", 218 | " [-0.19870653]\n", 219 | " [-1.33417245]\n", 220 | " [ 0.36902642]\n", 221 | " [ 0.6528929 ]\n", 222 | " [ 1.22062585]\n", 223 | " [ 1.78835881]\n", 224 | " [-0.19870653]\n", 225 | " [ 0.08515994]]\n" 226 | ] 227 | } 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "source": [ 233 | "print(sc_x[:, 0].mean())\n", 234 | "print(sc_x[:, 0].std())" 235 | ], 236 | "metadata": { 237 | "colab": { 238 | "base_uri": "https://localhost:8080/" 239 | }, 240 | "id": "EwUcyqEIva9Q", 241 | "outputId": "c2d23f58-e03b-451e-f54c-a20ac56a69e9" 242 | }, 243 | "execution_count": 9, 244 | "outputs": [ 245 | { 246 | "output_type": "stream", 247 | "name": "stdout", 248 | "text": [ 249 | "-5.967448757360216e-17\n", 250 | "1.0\n" 251 | ] 252 | } 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "source": [ 258 | "test_x = np.array([1,2,3,5,1,6,8,2])\n", 259 | "test_x = test_x.reshape(-1,1)\n", 260 | "sc_test_x = scaler.transform(test_x)\n", 261 | "print(sc_test_x)" 262 | ], 263 | "metadata": { 264 | "colab": { 265 | "base_uri": "https://localhost:8080/" 266 | }, 267 | "id": "PWx2tF7kwIKM", 268 | "outputId": "2f9c34f3-5d28-499b-b611-398b9d8ce771" 269 | }, 270 | "execution_count": 10, 271 | "outputs": [ 272 | { 273 | "output_type": "stream", 274 | "name": "stdout", 275 | "text": [ 276 | "[[-1.33417245]\n", 277 | " [-1.05030597]\n", 278 | " [-0.76643949]\n", 279 | " [-0.19870653]\n", 280 | " [-1.33417245]\n", 281 | " [ 0.08515994]\n", 282 | " [ 0.6528929 ]\n", 283 | " [-1.05030597]]\n" 284 | ] 285 | } 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "source": [ 291 | "# **2D Array**" 292 | ], 293 | "metadata": { 294 | "id": "4zCm6UWA01HR" 295 | } 296 | }, 297 | { 298 | "cell_type": "code", 299 | "source": [ 300 | "x_2D = np.array([[1,5,2],[7,0,5],[12,3,8], [10,5,3]])\n", 301 | "sc_x_2D = scaler.fit_transform(x_2D)\n", 302 | "print(sc_x_2D)" 303 | ], 304 | "metadata": { 305 | "colab": { 306 | "base_uri": "https://localhost:8080/" 307 | }, 308 | "id": "wnyXlubGyBo4", 309 | "outputId": "3783a0e2-d4e7-445b-a86e-0414479f8a96" 310 | }, 311 | "execution_count": 11, 312 | "outputs": [ 313 | { 314 | "output_type": "stream", 315 | "name": "stdout", 316 | "text": [ 317 | "[[-1.56501609 0.85518611 -1.09108945]\n", 318 | " [-0.12038585 -1.58820278 0.21821789]\n", 319 | " [ 1.08347268 -0.12216944 1.52752523]\n", 320 | " [ 0.60192927 0.85518611 -0.65465367]]\n" 321 | ] 322 | } 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "source": [ 328 | "print(sc_x_2D[:,0].mean())\n", 329 | "print(sc_x_2D[:,0].std())" 330 | ], 331 | "metadata": { 332 | "colab": { 333 | "base_uri": "https://localhost:8080/" 334 | }, 335 | "id": "t0WVIRwY2Jm6", 336 | "outputId": "2c0deae6-351c-4f0d-d423-f10699ce6612" 337 | }, 338 | "execution_count": 12, 339 | "outputs": [ 340 | { 341 | "output_type": "stream", 342 | "name": "stdout", 343 | "text": [ 344 | "0.0\n", 345 | "1.0\n" 346 | ] 347 | } 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "source": [ 353 | "print(sc_x_2D[:,1].mean())\n", 354 | "print(sc_x_2D[:,1].std())" 355 | ], 356 | "metadata": { 357 | "colab": { 358 | "base_uri": "https://localhost:8080/" 359 | }, 360 | "id": "sU4Kj9M32TZY", 361 | "outputId": "88839ab6-f044-42f3-c823-19bca78bc7bc" 362 | }, 363 | "execution_count": 13, 364 | "outputs": [ 365 | { 366 | "output_type": "stream", 367 | "name": "stdout", 368 | "text": [ 369 | "0.0\n", 370 | "0.9999999999999999\n" 371 | ] 372 | } 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "source": [ 378 | "print(sc_x_2D[:,2].mean())\n", 379 | "print(sc_x_2D[:,2].std())" 380 | ], 381 | "metadata": { 382 | "colab": { 383 | "base_uri": "https://localhost:8080/" 384 | }, 385 | "id": "jOJi2_7r2VS3", 386 | "outputId": "18e76b11-12e4-4da7-f46d-e5371abc9b09" 387 | }, 388 | "execution_count": 14, 389 | "outputs": [ 390 | { 391 | "output_type": "stream", 392 | "name": "stdout", 393 | "text": [ 394 | "-2.7755575615628914e-17\n", 395 | "1.0\n" 396 | ] 397 | } 398 | ] 399 | } 400 | ] 401 | } -------------------------------------------------------------------------------- /class01/class01.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "class01.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyPz/SXu5TsMX23QyfELs4rE", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "# 變數 Variable" 34 | ], 35 | "metadata": { 36 | "id": "OazwBwMT5f0B" 37 | } 38 | }, 39 | { 40 | "cell_type": "code", 41 | "source": [ 42 | "x = 3 # assign 賦值\n", 43 | "y = 2.5\n", 44 | "z = \"Hello Python\"\n", 45 | "a = True\n", 46 | "b = False\n", 47 | "# 原生型態 Primitive type\n", 48 | "print(type(x))\n", 49 | "print(type(y))\n", 50 | "print(type(z))\n", 51 | "print(type(a))\n", 52 | "print(type(b))" 53 | ], 54 | "metadata": { 55 | "colab": { 56 | "base_uri": "https://localhost:8080/" 57 | }, 58 | "id": "-W5-n7lx5eeY", 59 | "outputId": "5e79f3ff-377f-4d88-c5d9-4aaf534c780c" 60 | }, 61 | "execution_count": null, 62 | "outputs": [ 63 | { 64 | "output_type": "stream", 65 | "name": "stdout", 66 | "text": [ 67 | "\n", 68 | "\n", 69 | "\n", 70 | "\n", 71 | "\n" 72 | ] 73 | } 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "source": [ 79 | "# Pass by Reference" 80 | ], 81 | "metadata": { 82 | "id": "dDcIRKDc5oNR" 83 | } 84 | }, 85 | { 86 | "cell_type": "code", 87 | "source": [ 88 | "x = 3\n", 89 | "y = x\n", 90 | "print(id(x), id(y))\n", 91 | "x = x + 1\n", 92 | "print(id(x), id(y))\n", 93 | "z = 4\n", 94 | "print(id(z))" 95 | ], 96 | "metadata": { 97 | "colab": { 98 | "base_uri": "https://localhost:8080/" 99 | }, 100 | "id": "-J4pINDC5j5g", 101 | "outputId": "284b07dd-9578-4dbe-9dd3-53f0040cc2c8" 102 | }, 103 | "execution_count": null, 104 | "outputs": [ 105 | { 106 | "output_type": "stream", 107 | "name": "stdout", 108 | "text": [ 109 | "11256128 11256128\n", 110 | "11256160 11256128\n", 111 | "11256160\n" 112 | ] 113 | } 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "source": [ 119 | "# print" 120 | ], 121 | "metadata": { 122 | "id": "dJVbasVi5tj-" 123 | } 124 | }, 125 | { 126 | "cell_type": "code", 127 | "source": [ 128 | "print(\"Hello\") # 自動換行\n", 129 | "print(\"Python\")\n", 130 | "print(\"Hello\", end=\" \")\n", 131 | "print(\"Python\")\n", 132 | "print(\"Hello\", end=\",\")\n", 133 | "print(\"Python\")\n", 134 | "print(\"Hello, Python.\\nI'm Thousand.\")" 135 | ], 136 | "metadata": { 137 | "colab": { 138 | "base_uri": "https://localhost:8080/" 139 | }, 140 | "id": "3Od9ResK5u-H", 141 | "outputId": "ddb82297-fec9-43ec-f999-95f32f64bdd3" 142 | }, 143 | "execution_count": null, 144 | "outputs": [ 145 | { 146 | "output_type": "stream", 147 | "name": "stdout", 148 | "text": [ 149 | "Hello\n", 150 | "Python\n", 151 | "Hello Python\n", 152 | "Hello,Python\n", 153 | "Hello, Python.\n", 154 | "I'm Thousand.\n" 155 | ] 156 | } 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "source": [ 162 | "# 輸出格式 (format)\n", 163 | "guest = \"Allie\"\n", 164 | "host = \"Thousand\"\n", 165 | "print(\"Hello, \" + guest + \". My name is \" + host + \".\")\n", 166 | "print(f\"Hello, {guest}. My name is {host}.\")\n", 167 | "print(\"Hello, {}. My name is {}.\".format(guest, host))\n", 168 | "pi = 3.14159265\n", 169 | "print(f\"Pi is {pi:.3f}\")\n", 170 | "print(\"Pi is {:.3f}\".format(pi))" 171 | ], 172 | "metadata": { 173 | "colab": { 174 | "base_uri": "https://localhost:8080/" 175 | }, 176 | "id": "us-uQvVh5vdh", 177 | "outputId": "302d52f1-8a81-4042-d905-f8756be6d7dd" 178 | }, 179 | "execution_count": null, 180 | "outputs": [ 181 | { 182 | "output_type": "stream", 183 | "name": "stdout", 184 | "text": [ 185 | "Hello, Allie. My name is Thousand.\n", 186 | "Hello, Allie. My name is Thousand.\n", 187 | "Hello, Allie. My name is Thousand.\n", 188 | "Pi is 3.142\n", 189 | "Pi is 3.142\n" 190 | ] 191 | } 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "source": [ 197 | "# 資料型態不同導致運算結果不同\n", 198 | "a = \"123\"\n", 199 | "b = \"456\"\n", 200 | "c = 123\n", 201 | "d = 456\n", 202 | "print(a+b)\n", 203 | "print(c+d)" 204 | ], 205 | "metadata": { 206 | "colab": { 207 | "base_uri": "https://localhost:8080/" 208 | }, 209 | "id": "DLUZotED5zCq", 210 | "outputId": "2492206c-94fd-4d7c-f8cc-4faaab84168a" 211 | }, 212 | "execution_count": null, 213 | "outputs": [ 214 | { 215 | "output_type": "stream", 216 | "name": "stdout", 217 | "text": [ 218 | "123456\n", 219 | "579\n" 220 | ] 221 | } 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "source": [ 227 | "# 輸入" 228 | ], 229 | "metadata": { 230 | "id": "BajwTWVX56-l" 231 | } 232 | }, 233 | { 234 | "cell_type": "code", 235 | "source": [ 236 | "number = input(\"\")\n", 237 | "print(f\"Your number is {number}\")\n", 238 | "print(type(number)) # string\n", 239 | "number = int(number)\n", 240 | "print(type(number))" 241 | ], 242 | "metadata": { 243 | "colab": { 244 | "base_uri": "https://localhost:8080/" 245 | }, 246 | "id": "zTXSU8rx588v", 247 | "outputId": "b59ba9d8-6bfb-4175-ae22-b941af3f21d0" 248 | }, 249 | "execution_count": null, 250 | "outputs": [ 251 | { 252 | "output_type": "stream", 253 | "name": "stdout", 254 | "text": [ 255 | "327\n", 256 | "Your number is 327\n", 257 | "\n", 258 | "\n" 259 | ] 260 | } 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "source": [ 266 | "number = int(input(\"Enter a number: \"))\n", 267 | "print(f\"Your number is {number}\")\n", 268 | "print(type(number))" 269 | ], 270 | "metadata": { 271 | "colab": { 272 | "base_uri": "https://localhost:8080/" 273 | }, 274 | "id": "hwg_-uCJ59U7", 275 | "outputId": "3fac467b-b282-4c70-9262-a7e3d8336360" 276 | }, 277 | "execution_count": null, 278 | "outputs": [ 279 | { 280 | "output_type": "stream", 281 | "name": "stdout", 282 | "text": [ 283 | "Enter a number: 268\n", 284 | "Your number is 268\n", 285 | "\n" 286 | ] 287 | } 288 | ] 289 | }, 290 | { 291 | "cell_type": "markdown", 292 | "source": [ 293 | "# try except" 294 | ], 295 | "metadata": { 296 | "id": "pTBguSkA6Gd-" 297 | } 298 | }, 299 | { 300 | "cell_type": "code", 301 | "source": [ 302 | "try:\n", 303 | " number = int(input(\"Enter a number: \"))\n", 304 | " print(f\"Your number is: {number}\")\n", 305 | "except ValueError:\n", 306 | " print(\"輸入格式錯誤,請輸入數字\")" 307 | ], 308 | "metadata": { 309 | "colab": { 310 | "base_uri": "https://localhost:8080/" 311 | }, 312 | "id": "WCMrNUYa6B93", 313 | "outputId": "7bf8f541-dfc1-4210-bc55-6c37d50d86ab" 314 | }, 315 | "execution_count": null, 316 | "outputs": [ 317 | { 318 | "output_type": "stream", 319 | "name": "stdout", 320 | "text": [ 321 | "Enter a number: qfjis112\n", 322 | "輸入格式錯誤,請輸入數字\n" 323 | ] 324 | } 325 | ] 326 | }, 327 | { 328 | "cell_type": "markdown", 329 | "source": [ 330 | "# operator" 331 | ], 332 | "metadata": { 333 | "id": "JcJT7nMB6sN1" 334 | } 335 | }, 336 | { 337 | "cell_type": "code", 338 | "source": [ 339 | "x = 5\n", 340 | "y = 3\n", 341 | "print(f\"x+y={x+y}\")\n", 342 | "print(f\"x-y={x-y}\")\n", 343 | "print(f\"x*y={x*y}\")\n", 344 | "print(f\"x/y={x/y}\") # 小數點除法\n", 345 | "print(f\"x/y={x//y}\") # 整數除法\n", 346 | "print(f\"x*x*x={x**3}\")\n", 347 | "print(f\"x%y={x%y}\")" 348 | ], 349 | "metadata": { 350 | "colab": { 351 | "base_uri": "https://localhost:8080/" 352 | }, 353 | "id": "c2dQaDIU6tcL", 354 | "outputId": "27fd651c-f90a-482c-b498-aaf169450a17" 355 | }, 356 | "execution_count": null, 357 | "outputs": [ 358 | { 359 | "output_type": "stream", 360 | "name": "stdout", 361 | "text": [ 362 | "x+y=8\n", 363 | "x-y=2\n", 364 | "x*y=15\n", 365 | "x/y=1.6666666666666667\n", 366 | "x/y=1\n", 367 | "x*x*x=125\n", 368 | "x%y=2\n" 369 | ] 370 | } 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "source": [ 376 | "# 餘數應用\n", 377 | "num = int(input(\"Enter a number: \"))\n", 378 | "print(f\"百位數字: {num//100}\")\n", 379 | "print(f\"十位數字: {(num//10)%10}\")\n", 380 | "print(f\"個位數字: {num%10}\")" 381 | ], 382 | "metadata": { 383 | "colab": { 384 | "base_uri": "https://localhost:8080/" 385 | }, 386 | "id": "qiij61m96uWk", 387 | "outputId": "867c9a4f-0dc8-45bb-f4cf-3954adf1de7f" 388 | }, 389 | "execution_count": null, 390 | "outputs": [ 391 | { 392 | "output_type": "stream", 393 | "name": "stdout", 394 | "text": [ 395 | "Enter a number: 368\n", 396 | "百位數字: 3\n", 397 | "十位數字: 6\n", 398 | "個位數字: 8\n" 399 | ] 400 | } 401 | ] 402 | }, 403 | { 404 | "cell_type": "code", 405 | "source": [ 406 | "# 交換數值\n", 407 | "x = int(input(\"x: \"))\n", 408 | "y = int(input(\"y: \"))\n", 409 | "#tem = x\n", 410 | "# x = y\n", 411 | "# y = tem\n", 412 | "x,y = y,x\n", 413 | "print(f\"x: {x}, y:{y}\")" 414 | ], 415 | "metadata": { 416 | "colab": { 417 | "base_uri": "https://localhost:8080/" 418 | }, 419 | "id": "qxfJAsL06xQF", 420 | "outputId": "f668e44c-4b65-491a-92f8-bd6ff304ae98" 421 | }, 422 | "execution_count": null, 423 | "outputs": [ 424 | { 425 | "output_type": "stream", 426 | "name": "stdout", 427 | "text": [ 428 | "x: 3\n", 429 | "y: 5\n", 430 | "x: 5, y:3\n" 431 | ] 432 | } 433 | ] 434 | }, 435 | { 436 | "cell_type": "markdown", 437 | "source": [ 438 | "# 控制流程" 439 | ], 440 | "metadata": { 441 | "id": "dGyHYkLD6-zs" 442 | } 443 | }, 444 | { 445 | "cell_type": "code", 446 | "source": [ 447 | "num = int(input())\n", 448 | "if num > 200:\n", 449 | " print(f\"{num} > 200\")\n", 450 | "else:\n", 451 | " print(f\"{num} <= 200\")" 452 | ], 453 | "metadata": { 454 | "colab": { 455 | "base_uri": "https://localhost:8080/" 456 | }, 457 | "id": "Hcp3xHwf6_qg", 458 | "outputId": "89240aeb-2662-4ede-d643-1d860e2f7779" 459 | }, 460 | "execution_count": null, 461 | "outputs": [ 462 | { 463 | "output_type": "stream", 464 | "name": "stdout", 465 | "text": [ 466 | "170\n", 467 | "170 <= 200\n" 468 | ] 469 | } 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "source": [ 475 | "# 非 0 是 True,0 是 False\n", 476 | "if 0:\n", 477 | " print(\"This is Ture\")\n", 478 | "else:\n", 479 | " print(\"This is False\")" 480 | ], 481 | "metadata": { 482 | "colab": { 483 | "base_uri": "https://localhost:8080/" 484 | }, 485 | "id": "KhtkpVrY7Brp", 486 | "outputId": "d6b2e7cd-2afd-4619-e95a-1b4661e79e3f" 487 | }, 488 | "execution_count": null, 489 | "outputs": [ 490 | { 491 | "output_type": "stream", 492 | "name": "stdout", 493 | "text": [ 494 | "This is False\n" 495 | ] 496 | } 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "source": [ 502 | "# if/elif/else\n", 503 | "num = int(input())\n", 504 | "if num > 200:\n", 505 | " print(f\"{num} > 200\")\n", 506 | "elif 100 <= num <= 200:\n", 507 | " print(f\"100 <= {num} <= 200\")\n", 508 | "else:\n", 509 | " print(f\"{num} < 100\")" 510 | ], 511 | "metadata": { 512 | "colab": { 513 | "base_uri": "https://localhost:8080/" 514 | }, 515 | "id": "cNJinCpr7FPR", 516 | "outputId": "b407d3f4-ae6c-4214-a6e1-1235ce35f12c" 517 | }, 518 | "execution_count": null, 519 | "outputs": [ 520 | { 521 | "output_type": "stream", 522 | "name": "stdout", 523 | "text": [ 524 | "170\n", 525 | "100 <= 170 <= 200\n" 526 | ] 527 | } 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "source": [ 533 | "# if/elif/else vs. 多個 if\n", 534 | "num = 3\n", 535 | "if num >= 2:\n", 536 | " print(f\"{num} >= 2\")\n", 537 | "elif num >= 1:\n", 538 | " print(f\"{num} >= 1\")\n", 539 | "else:\n", 540 | " print(f\"{num} >= 0\")\n", 541 | "\n", 542 | " \n", 543 | "if num >= 2:\n", 544 | " print(f\"{num} >= 2\")\n", 545 | "if num >= 1:\n", 546 | " print(f\"{num} >= 1\")\n", 547 | "if num >= 0:\n", 548 | " print(f\"{num} >= 2\")" 549 | ], 550 | "metadata": { 551 | "colab": { 552 | "base_uri": "https://localhost:8080/" 553 | }, 554 | "id": "ZzG_HKUl7Haw", 555 | "outputId": "12dcd828-9d0b-441b-be4b-f840bbaa09fa" 556 | }, 557 | "execution_count": null, 558 | "outputs": [ 559 | { 560 | "output_type": "stream", 561 | "name": "stdout", 562 | "text": [ 563 | "3 >= 2\n", 564 | "3 >= 2\n", 565 | "3 >= 1\n", 566 | "3 >= 2\n" 567 | ] 568 | } 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "source": [ 574 | "# if/else 解答\n", 575 | "x = int(input())\n", 576 | "y = int(input())\n", 577 | "z = int(input())\n", 578 | "if x > y:\n", 579 | " ans = x\n", 580 | "else:\n", 581 | " ans = y\n", 582 | "if z > ans:\n", 583 | " ans = z\n", 584 | "print(f\"最大值: {ans}\")" 585 | ], 586 | "metadata": { 587 | "colab": { 588 | "base_uri": "https://localhost:8080/" 589 | }, 590 | "id": "3dlihjph7NHF", 591 | "outputId": "e2128c94-679b-40ce-b2f1-4df8f75a6a34" 592 | }, 593 | "execution_count": null, 594 | "outputs": [ 595 | { 596 | "output_type": "stream", 597 | "name": "stdout", 598 | "text": [ 599 | "3\n", 600 | "5\n", 601 | "2\n", 602 | "最大值: 5\n" 603 | ] 604 | } 605 | ] 606 | }, 607 | { 608 | "cell_type": "code", 609 | "source": [ 610 | "# Nested if\n", 611 | "n = int(input(\"Enter a number: \"))\n", 612 | "if n % 2 == 1:\n", 613 | " print(\"Weird\")\n", 614 | "elif n % 2 == 0:\n", 615 | " if 2 <= n <= 5:\n", 616 | " print(\"Not Weird\")\n", 617 | " elif 6 <= n <= 20:\n", 618 | " print(\"Weird\")\n", 619 | " elif n > 20:\n", 620 | " print(\"Not Weird\")" 621 | ], 622 | "metadata": { 623 | "colab": { 624 | "base_uri": "https://localhost:8080/" 625 | }, 626 | "id": "Z6GcwuLZ7P6Z", 627 | "outputId": "8d4028c7-c9f0-464f-c770-74c874696ba6" 628 | }, 629 | "execution_count": null, 630 | "outputs": [ 631 | { 632 | "output_type": "stream", 633 | "name": "stdout", 634 | "text": [ 635 | "Enter a number: 6\n", 636 | "Weird\n" 637 | ] 638 | } 639 | ] 640 | }, 641 | { 642 | "cell_type": "code", 643 | "source": [ 644 | "# while 迴圈\n", 645 | "i = 0\n", 646 | "while i < 10:\n", 647 | " print(i)\n", 648 | " i += 1" 649 | ], 650 | "metadata": { 651 | "colab": { 652 | "base_uri": "https://localhost:8080/" 653 | }, 654 | "id": "E0u1ncjj7UCc", 655 | "outputId": "08bf7f55-2403-4153-99f0-94008fa7fb90" 656 | }, 657 | "execution_count": null, 658 | "outputs": [ 659 | { 660 | "output_type": "stream", 661 | "name": "stdout", 662 | "text": [ 663 | "0\n", 664 | "1\n", 665 | "2\n", 666 | "3\n", 667 | "4\n", 668 | "5\n", 669 | "6\n", 670 | "7\n", 671 | "8\n", 672 | "9\n" 673 | ] 674 | } 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "source": [ 680 | "# while 迴圈\n", 681 | "n = int(input())\n", 682 | "i = 1\n", 683 | "total = 0\n", 684 | "while i <= n:\n", 685 | " if i == n:\n", 686 | " print(i,end= \"=\")\n", 687 | " else:\n", 688 | " print(i,end= \"+\")\n", 689 | " total = total + i\n", 690 | " i += 1\n", 691 | "print(total)" 692 | ], 693 | "metadata": { 694 | "colab": { 695 | "base_uri": "https://localhost:8080/" 696 | }, 697 | "id": "f2_oLEH2kHp5", 698 | "outputId": "de830b44-92a8-468b-e8af-15c53ce7a4b0" 699 | }, 700 | "execution_count": null, 701 | "outputs": [ 702 | { 703 | "output_type": "stream", 704 | "name": "stdout", 705 | "text": [ 706 | "20\n", 707 | "1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20=210\n" 708 | ] 709 | } 710 | ] 711 | } 712 | ] 713 | } -------------------------------------------------------------------------------- /class03/class03.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "class03.ipynb", 7 | "provenance": [], 8 | "mount_file_id": "1H1a7_g2cGWurohmkcyiSSl9amVHcGKLh", 9 | "authorship_tag": "ABX9TyNyOrAhsxN/IBgr2z61UJDY", 10 | "include_colab_link": true 11 | }, 12 | "kernelspec": { 13 | "name": "python3", 14 | "display_name": "Python 3" 15 | }, 16 | "language_info": { 17 | "name": "python" 18 | } 19 | }, 20 | "cells": [ 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "id": "view-in-github", 25 | "colab_type": "text" 26 | }, 27 | "source": [ 28 | "\"Open" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "source": [ 34 | "# **雙層串列 & 雙層迴圈**" 35 | ], 36 | "metadata": { 37 | "id": "BcZXPkTLXj4J" 38 | } 39 | }, 40 | { 41 | "cell_type": "code", 42 | "source": [ 43 | "# 雙層串列\n", 44 | "matrix = [[32, 57, 89], [59,20,66], [66,78,82], [32,89,100], [70,100,30]]\n", 45 | "print(matrix[0])\n", 46 | "print(matrix[2][1])" 47 | ], 48 | "metadata": { 49 | "colab": { 50 | "base_uri": "https://localhost:8080/" 51 | }, 52 | "id": "xjty3sehXohQ", 53 | "outputId": "e2a2cdc5-2b0c-4310-8d8e-b0b844057ce7" 54 | }, 55 | "execution_count": 1, 56 | "outputs": [ 57 | { 58 | "output_type": "stream", 59 | "name": "stdout", 60 | "text": [ 61 | "[32, 57, 89]\n", 62 | "78\n" 63 | ] 64 | } 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "source": [ 70 | "# 雙層迴圈\n", 71 | "for i in range(5):\n", 72 | " print(f\"{i}: \",end=\"\")\n", 73 | " for j in range(3):\n", 74 | " print(f\"{j}\",end=\" \")\n", 75 | " print()" 76 | ], 77 | "metadata": { 78 | "colab": { 79 | "base_uri": "https://localhost:8080/" 80 | }, 81 | "id": "3QTOafLGXqrA", 82 | "outputId": "abfac50d-580c-4a20-d143-a4d70805b0d9" 83 | }, 84 | "execution_count": 2, 85 | "outputs": [ 86 | { 87 | "output_type": "stream", 88 | "name": "stdout", 89 | "text": [ 90 | "0: 0 1 2 \n", 91 | "1: 0 1 2 \n", 92 | "2: 0 1 2 \n", 93 | "3: 0 1 2 \n", 94 | "4: 0 1 2 \n" 95 | ] 96 | } 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "source": [ 102 | "# 雙層迴圈 (解答1)\n", 103 | "n = int(input())\n", 104 | "for i in range(n):\n", 105 | " for j in range(i+1):\n", 106 | " print(\"*\",end=\"\")\n", 107 | " print()" 108 | ], 109 | "metadata": { 110 | "colab": { 111 | "base_uri": "https://localhost:8080/" 112 | }, 113 | "id": "j7lCRQPaX2X8", 114 | "outputId": "a8110154-343f-4247-f7ca-645bcf12b163" 115 | }, 116 | "execution_count": 3, 117 | "outputs": [ 118 | { 119 | "output_type": "stream", 120 | "name": "stdout", 121 | "text": [ 122 | "5\n", 123 | "*\n", 124 | "**\n", 125 | "***\n", 126 | "****\n", 127 | "*****\n" 128 | ] 129 | } 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "source": [ 135 | "# 雙層迴圈 (解答2)\n", 136 | "n = int(input())\n", 137 | "for i in range(n):\n", 138 | " for j in range(n-i):\n", 139 | " print(\"*\",end=\"\")\n", 140 | " print()" 141 | ], 142 | "metadata": { 143 | "colab": { 144 | "base_uri": "https://localhost:8080/" 145 | }, 146 | "id": "GFsB47ybX5fa", 147 | "outputId": "ae090ce6-cd03-4956-a219-afad82a170cb" 148 | }, 149 | "execution_count": 4, 150 | "outputs": [ 151 | { 152 | "output_type": "stream", 153 | "name": "stdout", 154 | "text": [ 155 | "5\n", 156 | "*****\n", 157 | "****\n", 158 | "***\n", 159 | "**\n", 160 | "*\n" 161 | ] 162 | } 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "source": [ 168 | "# 雙層迴圈 (解答3)\n", 169 | "n = int(input())\n", 170 | "for i in range(n):\n", 171 | " for j in range(n-i-1):\n", 172 | " print(\" \",end=\"\")\n", 173 | " for k in range(i+1):\n", 174 | " print(\"*\",end=\"\")\n", 175 | " print()" 176 | ], 177 | "metadata": { 178 | "colab": { 179 | "base_uri": "https://localhost:8080/" 180 | }, 181 | "id": "OBMaD_0SX5jU", 182 | "outputId": "28df8e1c-2c74-44d1-ceba-6666bed3cd74" 183 | }, 184 | "execution_count": 5, 185 | "outputs": [ 186 | { 187 | "output_type": "stream", 188 | "name": "stdout", 189 | "text": [ 190 | "5\n", 191 | " *\n", 192 | " **\n", 193 | " ***\n", 194 | " ****\n", 195 | "*****\n" 196 | ] 197 | } 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "source": [ 203 | "# 雙層迴圈 + 雙層串列\n", 204 | "matrix = [[32, 57, 89], [59,20,66], [66,78,82], [32,89,100], [70,100,30]]\n", 205 | "row = len(matrix)\n", 206 | "col = len(matrix[0])\n", 207 | "for i in range(row):\n", 208 | " for j in range(col):\n", 209 | " print(matrix[i][j],end=\" \")\n", 210 | " print()" 211 | ], 212 | "metadata": { 213 | "colab": { 214 | "base_uri": "https://localhost:8080/" 215 | }, 216 | "id": "rtNVAMz3X5mL", 217 | "outputId": "9951a3e3-a69f-4e8e-ad1f-e18a6d4f0bdd" 218 | }, 219 | "execution_count": 6, 220 | "outputs": [ 221 | { 222 | "output_type": "stream", 223 | "name": "stdout", 224 | "text": [ 225 | "32 57 89 \n", 226 | "59 20 66 \n", 227 | "66 78 82 \n", 228 | "32 89 100 \n", 229 | "70 100 30 \n" 230 | ] 231 | } 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "source": [ 237 | "# 雙層迴圈 + 雙層串列 (解答)\n", 238 | "matrix = [[32, 57, 89], [59,20,66], [66,78,82], [32,89,100], [70,100,30]]\n", 239 | "row = len(matrix)\n", 240 | "row_ans = [0 for i in range(row)]\n", 241 | "col = len(matrix[0])\n", 242 | "col_ans = [0 for j in range(col)]\n", 243 | "for i in range(row):\n", 244 | " for j in range(col):\n", 245 | " row_ans[i] += matrix[i][j]\n", 246 | " col_ans[j] += matrix[i][j]\n", 247 | "print(f\"row 總和: {row_ans}\")\n", 248 | "print(f\"col 總和: {col_ans}\")" 249 | ], 250 | "metadata": { 251 | "colab": { 252 | "base_uri": "https://localhost:8080/" 253 | }, 254 | "id": "7NHkyHoDYElk", 255 | "outputId": "03a48d94-3f3a-45bc-978b-cf683ac11429" 256 | }, 257 | "execution_count": 7, 258 | "outputs": [ 259 | { 260 | "output_type": "stream", 261 | "name": "stdout", 262 | "text": [ 263 | "row 總和: [178, 145, 226, 221, 200]\n", 264 | "col 總和: [259, 344, 367]\n" 265 | ] 266 | } 267 | ] 268 | }, 269 | { 270 | "cell_type": "markdown", 271 | "source": [ 272 | "# **函式**" 273 | ], 274 | "metadata": { 275 | "id": "nJJy1pA2qDbH" 276 | } 277 | }, 278 | { 279 | "cell_type": "markdown", 280 | "source": [ 281 | "" 282 | ], 283 | "metadata": { 284 | "id": "7VYXB2sOXivO" 285 | } 286 | }, 287 | { 288 | "cell_type": "code", 289 | "source": [ 290 | "def show():\n", 291 | " print(\"Welcome!!\")\n", 292 | "def say_hello(name):\n", 293 | " print(f\"Hello {name}\")\n", 294 | "def add_numbers(num1, num2):\n", 295 | " print(num1)\n", 296 | " print(num2)\n", 297 | " print(num1 + num2)" 298 | ], 299 | "metadata": { 300 | "id": "HQ0wqPzbqChC" 301 | }, 302 | "execution_count": 8, 303 | "outputs": [] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "source": [ 308 | "show()\n", 309 | "say_hello(name = \"Thousand\") # say_hello(\"Thousand\")\n", 310 | "add_numbers(num2 = 9, num1 = 3) # add_numbers(3, 9)" 311 | ], 312 | "metadata": { 313 | "colab": { 314 | "base_uri": "https://localhost:8080/" 315 | }, 316 | "id": "9YN30kGLqCjY", 317 | "outputId": "8a8d5993-353d-4dd4-b3c8-0af057e0b620" 318 | }, 319 | "execution_count": 9, 320 | "outputs": [ 321 | { 322 | "output_type": "stream", 323 | "name": "stdout", 324 | "text": [ 325 | "Welcome!!\n", 326 | "Hello Thousand\n", 327 | "3\n", 328 | "9\n", 329 | "12\n" 330 | ] 331 | } 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "source": [ 337 | "# 函式生命週期\n", 338 | "def show():\n", 339 | " number = 3\n", 340 | " print(f\"This is show function: {number}\")\n", 341 | "show()\n", 342 | "print(number) # 由於函式的生命週期結束,在此函式內部產生的變數都會消失" 343 | ], 344 | "metadata": { 345 | "id": "4YYEfYUVqCHR", 346 | "colab": { 347 | "base_uri": "https://localhost:8080/", 348 | "height": 226 349 | }, 350 | "outputId": "03015609-5058-4185-e927-cb084c71290f" 351 | }, 352 | "execution_count": 10, 353 | "outputs": [ 354 | { 355 | "output_type": "stream", 356 | "name": "stdout", 357 | "text": [ 358 | "This is show function: 3\n" 359 | ] 360 | }, 361 | { 362 | "output_type": "error", 363 | "ename": "NameError", 364 | "evalue": "ignored", 365 | "traceback": [ 366 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 367 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 368 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"This is show function: {number}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# 由於函式的生命週期結束,在此函式內部產生的變數都會消失\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 369 | "\u001b[0;31mNameError\u001b[0m: name 'number' is not defined" 370 | ] 371 | } 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "source": [ 377 | "# 操作全域變數\n", 378 | "total = 0\n", 379 | "def change_number():\n", 380 | " print(total) # 可以看到區域變數\n", 381 | " # total += 1 # 不能操作全域變數\n", 382 | "change_number()" 383 | ], 384 | "metadata": { 385 | "colab": { 386 | "base_uri": "https://localhost:8080/" 387 | }, 388 | "id": "tC66KjppqCJm", 389 | "outputId": "84148f0b-3242-40c0-eb71-2df8e4257768" 390 | }, 391 | "execution_count": 11, 392 | "outputs": [ 393 | { 394 | "output_type": "stream", 395 | "name": "stdout", 396 | "text": [ 397 | "0\n" 398 | ] 399 | } 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "source": [ 405 | "# 全域變數與區域變數同名\n", 406 | "total = 3\n", 407 | "def change_number():\n", 408 | " total = 5\n", 409 | " total += 3\n", 410 | " print(f\"This is change_number function: {total}\")\n", 411 | "change_number()\n", 412 | "print(f\"This is main function: {total}\")" 413 | ], 414 | "metadata": { 415 | "colab": { 416 | "base_uri": "https://localhost:8080/" 417 | }, 418 | "id": "8Zs0qDy9YevN", 419 | "outputId": "71d7dc14-03db-4d46-e83b-fc642d2b743d" 420 | }, 421 | "execution_count": 12, 422 | "outputs": [ 423 | { 424 | "output_type": "stream", 425 | "name": "stdout", 426 | "text": [ 427 | "This is change_number function: 8\n", 428 | "This is main function: 3\n" 429 | ] 430 | } 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "source": [ 436 | "# call by reference\n", 437 | "num = 3\n", 438 | "def change_number(num):\n", 439 | " print(id(num))\n", 440 | " num += 2\n", 441 | " print(id(num))\n", 442 | "print(f\"Before change_number function: {num}\")\n", 443 | "print(id(num))\n", 444 | "change_number(num = num)\n", 445 | "print(f\"After change_number function: {num}\")" 446 | ], 447 | "metadata": { 448 | "colab": { 449 | "base_uri": "https://localhost:8080/" 450 | }, 451 | "id": "-nETWIYrqCL-", 452 | "outputId": "ba8d6b13-3b4e-492f-a58d-0c7d71715359" 453 | }, 454 | "execution_count": 13, 455 | "outputs": [ 456 | { 457 | "output_type": "stream", 458 | "name": "stdout", 459 | "text": [ 460 | "Before change_number function: 3\n", 461 | "11256128\n", 462 | "11256128\n", 463 | "11256192\n", 464 | "After change_number function: 3\n" 465 | ] 466 | } 467 | ] 468 | }, 469 | { 470 | "cell_type": "code", 471 | "source": [ 472 | "# call by reference (list)\n", 473 | "numbers = [3,2,8,10,15,18]\n", 474 | "def change_numbers(numbers):\n", 475 | " numbers.append(10)\n", 476 | "print(f\"Before change_numbers function: {numbers}\")\n", 477 | "change_numbers(numbers = numbers)\n", 478 | "print(f\"After change_numbers function: {numbers}\")" 479 | ], 480 | "metadata": { 481 | "colab": { 482 | "base_uri": "https://localhost:8080/" 483 | }, 484 | "id": "0j7D2vARYl-d", 485 | "outputId": "99fd3e6e-7f6d-4584-fb04-68c1edf7750e" 486 | }, 487 | "execution_count": 14, 488 | "outputs": [ 489 | { 490 | "output_type": "stream", 491 | "name": "stdout", 492 | "text": [ 493 | "Before change_numbers function: [3, 2, 8, 10, 15, 18]\n", 494 | "After change_numbers function: [3, 2, 8, 10, 15, 18, 10]\n" 495 | ] 496 | } 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "source": [ 502 | "# return\n", 503 | "def get_mean(numbers):\n", 504 | " total = 0\n", 505 | " for v in numbers:\n", 506 | " total += v\n", 507 | " return total / len(numbers)\n", 508 | "numbers = [85, 95, 96]\n", 509 | "ans = get_mean(numbers = numbers)\n", 510 | "print(ans)" 511 | ], 512 | "metadata": { 513 | "colab": { 514 | "base_uri": "https://localhost:8080/" 515 | }, 516 | "id": "-KpUkGjBYmAi", 517 | "outputId": "507e02e1-3772-4cc6-f878-ed2ab38ce27a" 518 | }, 519 | "execution_count": 15, 520 | "outputs": [ 521 | { 522 | "output_type": "stream", 523 | "name": "stdout", 524 | "text": [ 525 | "92.0\n" 526 | ] 527 | } 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "source": [ 533 | "# import\n", 534 | "import random\n", 535 | "# import random as r\n", 536 | "# from random import randint\n", 537 | "sample = random.randint(1,100)\n", 538 | "print(sample)" 539 | ], 540 | "metadata": { 541 | "colab": { 542 | "base_uri": "https://localhost:8080/" 543 | }, 544 | "id": "RkVPB4wVYu7G", 545 | "outputId": "c8f39a00-e47c-4718-d9f1-ee1e82b7568c" 546 | }, 547 | "execution_count": 16, 548 | "outputs": [ 549 | { 550 | "output_type": "stream", 551 | "name": "stdout", 552 | "text": [ 553 | "8\n" 554 | ] 555 | } 556 | ] 557 | }, 558 | { 559 | "cell_type": "code", 560 | "source": [ 561 | "# random 函數 (解答)\n", 562 | "import random\n", 563 | "n = int(input())\n", 564 | "for i in range(n):\n", 565 | " print(random.randint(1,100), end=\" \")" 566 | ], 567 | "metadata": { 568 | "colab": { 569 | "base_uri": "https://localhost:8080/" 570 | }, 571 | "id": "NtghYeRuYu9d", 572 | "outputId": "6c287ea6-d914-4be9-90dc-9e589c01b4fd" 573 | }, 574 | "execution_count": 17, 575 | "outputs": [ 576 | { 577 | "output_type": "stream", 578 | "name": "stdout", 579 | "text": [ 580 | "10\n", 581 | "43 84 52 7 12 59 65 85 99 48 " 582 | ] 583 | } 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "source": [ 589 | "# lambda\n", 590 | "add = lambda x: x+3\n", 591 | "print(add(3))\n", 592 | "print((lambda x: x+3)(3))\n", 593 | "mul = lambda x,y: x*y\n", 594 | "print(mul(3,5))" 595 | ], 596 | "metadata": { 597 | "colab": { 598 | "base_uri": "https://localhost:8080/" 599 | }, 600 | "id": "N-R-GsEHYu_h", 601 | "outputId": "fd82fad1-fe7b-497b-b4a9-6278b85c0b1e" 602 | }, 603 | "execution_count": 18, 604 | "outputs": [ 605 | { 606 | "output_type": "stream", 607 | "name": "stdout", 608 | "text": [ 609 | "6\n", 610 | "6\n", 611 | "15\n" 612 | ] 613 | } 614 | ] 615 | }, 616 | { 617 | "cell_type": "code", 618 | "source": [ 619 | "# filter, map, sorted\n", 620 | "numbers = [3, 50, 2, 80, 49, 10, 6]\n", 621 | "print(list(filter(lambda x: x > 10, numbers)))\n", 622 | "print(list(map(lambda x: x + 3, numbers)))\n", 623 | "scores = [[\"Harry\", 32], [\"Berry\", 31], [\"Thousand\", 21]]\n", 624 | "print(sorted(scores, key = lambda x:x[1]))" 625 | ], 626 | "metadata": { 627 | "colab": { 628 | "base_uri": "https://localhost:8080/" 629 | }, 630 | "id": "kh_B-HnVYvBm", 631 | "outputId": "21e76a37-3a53-4168-85a9-af273624ec64" 632 | }, 633 | "execution_count": 19, 634 | "outputs": [ 635 | { 636 | "output_type": "stream", 637 | "name": "stdout", 638 | "text": [ 639 | "[50, 80, 49]\n", 640 | "[6, 53, 5, 83, 52, 13, 9]\n", 641 | "[['Thousand', 21], ['Berry', 31], ['Harry', 32]]\n" 642 | ] 643 | } 644 | ] 645 | }, 646 | { 647 | "cell_type": "code", 648 | "source": [ 649 | "# 補充\n", 650 | "numbers = input().split()\n", 651 | "print(list(map(lambda x: int(x), numbers)))" 652 | ], 653 | "metadata": { 654 | "colab": { 655 | "base_uri": "https://localhost:8080/" 656 | }, 657 | "id": "p_xpClm1ZOP-", 658 | "outputId": "71dca7e8-0460-484a-a9ea-7adb0d81ae24" 659 | }, 660 | "execution_count": 20, 661 | "outputs": [ 662 | { 663 | "output_type": "stream", 664 | "name": "stdout", 665 | "text": [ 666 | "23 52 87 98 96 100\n", 667 | "[23, 52, 87, 98, 96, 100]\n" 668 | ] 669 | } 670 | ] 671 | }, 672 | { 673 | "cell_type": "code", 674 | "source": [ 675 | "# 補充 *args\n", 676 | "def add(name, gender, *args):\n", 677 | " print(name)\n", 678 | " print(gender)\n", 679 | " print(sum(args))\n", 680 | "\n", 681 | "add(\"Thousand\", \"Male\", 1,2,3,4,5,6)" 682 | ], 683 | "metadata": { 684 | "colab": { 685 | "base_uri": "https://localhost:8080/" 686 | }, 687 | "id": "p_xN_PlbZXbu", 688 | "outputId": "89df41be-fc65-4898-e89b-2faee8a5acff" 689 | }, 690 | "execution_count": 21, 691 | "outputs": [ 692 | { 693 | "output_type": "stream", 694 | "name": "stdout", 695 | "text": [ 696 | "Thousand\n", 697 | "Male\n", 698 | "21\n" 699 | ] 700 | } 701 | ] 702 | }, 703 | { 704 | "cell_type": "code", 705 | "source": [ 706 | "# 補充 **kwargs\n", 707 | "def add(name, gender, **kwargs):\n", 708 | " print(name)\n", 709 | " print(gender)\n", 710 | " print(kwargs)\n", 711 | "\n", 712 | "add(\"Thousand\", \"Male\", math=100, english=98, physics= 97)" 713 | ], 714 | "metadata": { 715 | "colab": { 716 | "base_uri": "https://localhost:8080/" 717 | }, 718 | "id": "2D0uLHt3Zb3T", 719 | "outputId": "98eca67d-1f7d-44f4-b58b-da3d8c3e735a" 720 | }, 721 | "execution_count": 22, 722 | "outputs": [ 723 | { 724 | "output_type": "stream", 725 | "name": "stdout", 726 | "text": [ 727 | "Thousand\n", 728 | "Male\n", 729 | "{'math': 100, 'english': 98, 'physics': 97}\n" 730 | ] 731 | } 732 | ] 733 | }, 734 | { 735 | "cell_type": "code", 736 | "source": [ 737 | "# module & package 必須使用 .py 檔才能 import" 738 | ], 739 | "metadata": { 740 | "id": "s3hIb8VRYvDr" 741 | }, 742 | "execution_count": 23, 743 | "outputs": [] 744 | } 745 | ] 746 | } -------------------------------------------------------------------------------- /class02/class02.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "class02.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyOjBvObO0CW1wKxxzjKOW8A", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "# **迴圈 for**" 34 | ], 35 | "metadata": { 36 | "id": "QHxjZyNvN_JL" 37 | } 38 | }, 39 | { 40 | "cell_type": "code", 41 | "source": [ 42 | "# for 迴圈\n", 43 | "for i in range(0,10,1):\n", 44 | " print(i, end= \" \")\n", 45 | "print()\n", 46 | "for i in range(10):\n", 47 | " print(i, end= \" \")\n" 48 | ], 49 | "metadata": { 50 | "colab": { 51 | "base_uri": "https://localhost:8080/" 52 | }, 53 | "id": "QdWAIJj8OFsp", 54 | "outputId": "8d4b9d8c-9f0a-4b97-cb53-768e83af75e6" 55 | }, 56 | "execution_count": 1, 57 | "outputs": [ 58 | { 59 | "output_type": "stream", 60 | "name": "stdout", 61 | "text": [ 62 | "0 1 2 3 4 5 6 7 8 9 \n", 63 | "0 1 2 3 4 5 6 7 8 9 " 64 | ] 65 | } 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "source": [ 71 | "# for 迴圈解答 (1)\n", 72 | "n = int(input())\n", 73 | "for i in range(1,n+1,1):\n", 74 | " print(i)" 75 | ], 76 | "metadata": { 77 | "colab": { 78 | "base_uri": "https://localhost:8080/" 79 | }, 80 | "id": "jrpMHJmROTAl", 81 | "outputId": "a453bf4d-2bc7-4026-d227-e877f720bd7d" 82 | }, 83 | "execution_count": 2, 84 | "outputs": [ 85 | { 86 | "output_type": "stream", 87 | "name": "stdout", 88 | "text": [ 89 | "10\n", 90 | "1\n", 91 | "2\n", 92 | "3\n", 93 | "4\n", 94 | "5\n", 95 | "6\n", 96 | "7\n", 97 | "8\n", 98 | "9\n", 99 | "10\n" 100 | ] 101 | } 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "source": [ 107 | "# for 迴圈解答 (2)\n", 108 | "n = int(input())\n", 109 | "for i in range(n,-1,-1):\n", 110 | " print(i)" 111 | ], 112 | "metadata": { 113 | "colab": { 114 | "base_uri": "https://localhost:8080/" 115 | }, 116 | "id": "uWmh8tddPBRR", 117 | "outputId": "6ce9a4d7-0733-49d6-ec64-e00867d92e3d" 118 | }, 119 | "execution_count": 3, 120 | "outputs": [ 121 | { 122 | "output_type": "stream", 123 | "name": "stdout", 124 | "text": [ 125 | "5\n", 126 | "5\n", 127 | "4\n", 128 | "3\n", 129 | "2\n", 130 | "1\n", 131 | "0\n" 132 | ] 133 | } 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "source": [ 139 | "# for 迴圈解答 (3)\n", 140 | "n = int(input())\n", 141 | "ans = 0\n", 142 | "for i in range(1,n+1,1):\n", 143 | " ans = ans + i # ans += i\n", 144 | "print(ans)\n" 145 | ], 146 | "metadata": { 147 | "colab": { 148 | "base_uri": "https://localhost:8080/" 149 | }, 150 | "id": "yLnnBbxgPQ5-", 151 | "outputId": "5e77d023-6018-4dd2-a3a0-381094a90db5" 152 | }, 153 | "execution_count": 4, 154 | "outputs": [ 155 | { 156 | "output_type": "stream", 157 | "name": "stdout", 158 | "text": [ 159 | "10\n", 160 | "55\n" 161 | ] 162 | } 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "source": [ 168 | "# for 迴圈解答 (4)\n", 169 | "n = int(input())\n", 170 | "ans = 0\n", 171 | "for i in range(n):\n", 172 | " temp = int(input()) # temporary\n", 173 | " ans += temp\n", 174 | "print(ans)" 175 | ], 176 | "metadata": { 177 | "colab": { 178 | "base_uri": "https://localhost:8080/" 179 | }, 180 | "id": "YwnZCaXmPpIW", 181 | "outputId": "377aea5d-9046-4918-f0e5-b2b7e22cf809" 182 | }, 183 | "execution_count": 5, 184 | "outputs": [ 185 | { 186 | "output_type": "stream", 187 | "name": "stdout", 188 | "text": [ 189 | "5\n", 190 | "30\n", 191 | "80\n", 192 | "100\n", 193 | "20\n", 194 | "75\n", 195 | "305\n" 196 | ] 197 | } 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "source": [ 203 | "# **無窮迴圈**" 204 | ], 205 | "metadata": { 206 | "id": "1e3ixMAGQ7N2" 207 | } 208 | }, 209 | { 210 | "cell_type": "code", 211 | "source": [ 212 | "# break\n", 213 | "while True:\n", 214 | " x = input()\n", 215 | " if x == \"Q\":\n", 216 | " break\n", 217 | " print(x)" 218 | ], 219 | "metadata": { 220 | "colab": { 221 | "base_uri": "https://localhost:8080/" 222 | }, 223 | "id": "N4NJFHIVQ-DG", 224 | "outputId": "b57dd9e2-e5e0-4036-f4eb-963ef82d2ec9" 225 | }, 226 | "execution_count": 7, 227 | "outputs": [ 228 | { 229 | "name": "stdout", 230 | "output_type": "stream", 231 | "text": [ 232 | "2\n", 233 | "2\n", 234 | "4\n", 235 | "4\n", 236 | "8\n", 237 | "8\n", 238 | "Q\n" 239 | ] 240 | } 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "source": [ 246 | "# break\n", 247 | "x = 0\n", 248 | "while x <= 10:\n", 249 | " x += 1\n", 250 | " if x == 3:\n", 251 | " break\n", 252 | " print(x)" 253 | ], 254 | "metadata": { 255 | "colab": { 256 | "base_uri": "https://localhost:8080/" 257 | }, 258 | "id": "Uj75YiyUQ-Mf", 259 | "outputId": "5bdd1cf1-3f01-478e-a332-f29f76748973" 260 | }, 261 | "execution_count": 8, 262 | "outputs": [ 263 | { 264 | "output_type": "stream", 265 | "name": "stdout", 266 | "text": [ 267 | "1\n", 268 | "2\n" 269 | ] 270 | } 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "source": [ 276 | "# continue\n", 277 | "x = 0\n", 278 | "while x <= 10:\n", 279 | " x += 1\n", 280 | " if x == 3:\n", 281 | " continue\n", 282 | " print(x)" 283 | ], 284 | "metadata": { 285 | "colab": { 286 | "base_uri": "https://localhost:8080/" 287 | }, 288 | "id": "-A3kQhN_Q-PD", 289 | "outputId": "149d95ac-11e1-4ecb-bcc5-958add3ef240" 290 | }, 291 | "execution_count": 9, 292 | "outputs": [ 293 | { 294 | "output_type": "stream", 295 | "name": "stdout", 296 | "text": [ 297 | "1\n", 298 | "2\n", 299 | "4\n", 300 | "5\n", 301 | "6\n", 302 | "7\n", 303 | "8\n", 304 | "9\n", 305 | "10\n", 306 | "11\n" 307 | ] 308 | } 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "source": [ 314 | "" 315 | ], 316 | "metadata": { 317 | "id": "L28KGiO6Tgsz" 318 | }, 319 | "execution_count": null, 320 | "outputs": [] 321 | }, 322 | { 323 | "cell_type": "markdown", 324 | "source": [ 325 | "# **串列**" 326 | ], 327 | "metadata": { 328 | "id": "xlPVq3OjUvgR" 329 | } 330 | }, 331 | { 332 | "cell_type": "code", 333 | "source": [ 334 | "# 串列 list\n", 335 | "numbers = [3, 5, 6, 10, 2, 8]\n", 336 | "cat = [\"cookie\", 2, 3.2]\n", 337 | "print(numbers)\n", 338 | "print(cat)" 339 | ], 340 | "metadata": { 341 | "colab": { 342 | "base_uri": "https://localhost:8080/" 343 | }, 344 | "id": "kioLxBLFUx_-", 345 | "outputId": "a36315ba-be58-4600-ef37-86aaf9284cf3" 346 | }, 347 | "execution_count": 11, 348 | "outputs": [ 349 | { 350 | "output_type": "stream", 351 | "name": "stdout", 352 | "text": [ 353 | "[3, 5, 6, 10, 2, 8]\n", 354 | "['cookie', 2, 3.2]\n" 355 | ] 356 | } 357 | ] 358 | }, 359 | { 360 | "cell_type": "code", 361 | "source": [ 362 | "# index && slice\n", 363 | "numbers = [3, 5, 6, 10, 2, 8]\n", 364 | "print(numbers[0])\n", 365 | "print(numbers[2])\n", 366 | "print(numbers[-1])\n", 367 | "print(numbers[-3])\n", 368 | "print(len(numbers))\n", 369 | "print(numbers[1:3])\n", 370 | "print(numbers[:3])\n", 371 | "print(numbers[3:])\n", 372 | "print(numbers[2:-1])\n", 373 | "print(numbers[-1:-4])\n", 374 | "print(numbers[-3:])\n", 375 | "print(numbers[:])" 376 | ], 377 | "metadata": { 378 | "colab": { 379 | "base_uri": "https://localhost:8080/" 380 | }, 381 | "id": "mlP9NNVNU1jj", 382 | "outputId": "2e35b557-c95b-47f9-ca5a-6d20cee23a78" 383 | }, 384 | "execution_count": 12, 385 | "outputs": [ 386 | { 387 | "output_type": "stream", 388 | "name": "stdout", 389 | "text": [ 390 | "3\n", 391 | "6\n", 392 | "8\n", 393 | "10\n", 394 | "6\n", 395 | "[5, 6]\n", 396 | "[3, 5, 6]\n", 397 | "[10, 2, 8]\n", 398 | "[6, 10, 2]\n", 399 | "[]\n", 400 | "[10, 2, 8]\n", 401 | "[3, 5, 6, 10, 2, 8]\n" 402 | ] 403 | } 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "source": [ 409 | "# 串列 methods\n", 410 | "numbers = [5, 3, 6]\n", 411 | "numbers.insert(2, 8)\n", 412 | "print(f\"After insert: {numbers}\")\n", 413 | "numbers.append(8)\n", 414 | "print(f\"After append: {numbers}\")\n", 415 | "numbers.remove(8)\n", 416 | "print(f\"After remove: {numbers}\") # 移走第一個\n", 417 | "numbers.sort() # 由小到大\n", 418 | "print(f\"After sort: {numbers}\")\n", 419 | "numbers.reverse()\n", 420 | "print(f\"After reverse: {numbers}\")\n", 421 | "numbers.pop()\n", 422 | "print(f\"After pop: {numbers}\")" 423 | ], 424 | "metadata": { 425 | "colab": { 426 | "base_uri": "https://localhost:8080/" 427 | }, 428 | "id": "tntlmqocV9A2", 429 | "outputId": "515090c2-5e7f-4669-cb19-44c05667474d" 430 | }, 431 | "execution_count": 13, 432 | "outputs": [ 433 | { 434 | "output_type": "stream", 435 | "name": "stdout", 436 | "text": [ 437 | "After insert: [5, 3, 8, 6]\n", 438 | "After append: [5, 3, 8, 6, 8]\n", 439 | "After remove: [5, 3, 6, 8]\n", 440 | "After sort: [3, 5, 6, 8]\n", 441 | "After reverse: [8, 6, 5, 3]\n", 442 | "After pop: [8, 6, 5]\n" 443 | ] 444 | } 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "source": [ 450 | "# 串列 assign 記憶體問題\n", 451 | "num1 = [1, 2, 3, 4, 5]\n", 452 | "num2 = num1\n", 453 | "num1.append(6)\n", 454 | "print(f\"num1: {num1}, num2: {num2}\")\n", 455 | "num3 = num1[:]\n", 456 | "num4 = num1.copy()\n", 457 | "num1.append(7)\n", 458 | "num3.append(8)\n", 459 | "print(f\"num1: {num1}, num2: {num2}, num3: {num3}, num4: {num4}\" )" 460 | ], 461 | "metadata": { 462 | "colab": { 463 | "base_uri": "https://localhost:8080/" 464 | }, 465 | "id": "sbXeH1YqYvAA", 466 | "outputId": "eb3ac9fc-4d5c-4c02-8856-35eac5b89381" 467 | }, 468 | "execution_count": 15, 469 | "outputs": [ 470 | { 471 | "output_type": "stream", 472 | "name": "stdout", 473 | "text": [ 474 | "num1: [1, 2, 3, 4, 5, 6], num2: [1, 2, 3, 4, 5, 6]\n", 475 | "num1: [1, 2, 3, 4, 5, 6, 7], num2: [1, 2, 3, 4, 5, 6, 7], num3: [1, 2, 3, 4, 5, 6, 8], num4: [1, 2, 3, 4, 5, 6]\n" 476 | ] 477 | } 478 | ] 479 | }, 480 | { 481 | "cell_type": "markdown", 482 | "source": [ 483 | "# **串列 + 迴圈**" 484 | ], 485 | "metadata": { 486 | "id": "R1bXXy9bcjX3" 487 | } 488 | }, 489 | { 490 | "cell_type": "code", 491 | "source": [ 492 | "numbers = [3, 5, 6, 10, 2, 8]\n", 493 | "for i in range(len(numbers)):\n", 494 | " print(numbers[i], end = \" \")\n", 495 | "print() # 換行\n", 496 | "# 由右到左\n", 497 | "for i in range(len(numbers)-1,-1,-1):\n", 498 | " print(numbers[i], end = \" \")" 499 | ], 500 | "metadata": { 501 | "colab": { 502 | "base_uri": "https://localhost:8080/" 503 | }, 504 | "id": "s4Q4Uo8Pcmvg", 505 | "outputId": "2bd4478e-47b8-4785-ae26-58e681ca02bc" 506 | }, 507 | "execution_count": 17, 508 | "outputs": [ 509 | { 510 | "output_type": "stream", 511 | "name": "stdout", 512 | "text": [ 513 | "3 5 6 10 2 8 \n", 514 | "8 2 10 6 5 3 " 515 | ] 516 | } 517 | ] 518 | }, 519 | { 520 | "cell_type": "code", 521 | "source": [ 522 | "# python 風格寫法\n", 523 | "numbers = [3, 5, 6, 10, 2, 8]\n", 524 | "for v in numbers:\n", 525 | " print(v, end=\" \")\n", 526 | "print()" 527 | ], 528 | "metadata": { 529 | "colab": { 530 | "base_uri": "https://localhost:8080/" 531 | }, 532 | "id": "6MMdcCC5dKwf", 533 | "outputId": "dd15ac48-c5b2-43f9-df3d-25465f924a1a" 534 | }, 535 | "execution_count": 18, 536 | "outputs": [ 537 | { 538 | "output_type": "stream", 539 | "name": "stdout", 540 | "text": [ 541 | "3 5 6 10 2 8 \n" 542 | ] 543 | } 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "source": [ 549 | "# enumerate\n", 550 | "for i, v in enumerate(numbers):\n", 551 | " print(f\"index: {i}, value: {v}\")" 552 | ], 553 | "metadata": { 554 | "colab": { 555 | "base_uri": "https://localhost:8080/" 556 | }, 557 | "id": "CP_vAEmaeV3Y", 558 | "outputId": "2960803f-f594-4304-c8f7-3bab0c8d65e2" 559 | }, 560 | "execution_count": 19, 561 | "outputs": [ 562 | { 563 | "output_type": "stream", 564 | "name": "stdout", 565 | "text": [ 566 | "index: 0, value: 3\n", 567 | "index: 1, value: 5\n", 568 | "index: 2, value: 6\n", 569 | "index: 3, value: 10\n", 570 | "index: 4, value: 2\n", 571 | "index: 5, value: 8\n" 572 | ] 573 | } 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "source": [ 579 | "# 迴圈 + 串列 (解答)\n", 580 | "n = int(input())\n", 581 | "ans = []\n", 582 | "for i in range(n):\n", 583 | " temp = int(input())\n", 584 | " ans.append(temp)\n", 585 | "print(f\"總和: {sum(ans)}, 最小值: {min(ans)}, 最大值: {max(ans)}\")" 586 | ], 587 | "metadata": { 588 | "colab": { 589 | "base_uri": "https://localhost:8080/" 590 | }, 591 | "id": "T1mUMXTPe1-K", 592 | "outputId": "42bd6c53-b44e-40f4-9156-e9007695e2c1" 593 | }, 594 | "execution_count": 20, 595 | "outputs": [ 596 | { 597 | "output_type": "stream", 598 | "name": "stdout", 599 | "text": [ 600 | "5\n", 601 | "32\n", 602 | "31\n", 603 | "65\n", 604 | "32\n", 605 | "100\n", 606 | "總和: 260, 最小值: 31, 最大值: 100\n" 607 | ] 608 | } 609 | ] 610 | }, 611 | { 612 | "cell_type": "markdown", 613 | "source": [ 614 | "# **字串**" 615 | ], 616 | "metadata": { 617 | "id": "5cMne55EhRnm" 618 | } 619 | }, 620 | { 621 | "cell_type": "code", 622 | "source": [ 623 | "name = \"Thousand\"\n", 624 | "print(name[0])\n", 625 | "print(len(name))" 626 | ], 627 | "metadata": { 628 | "colab": { 629 | "base_uri": "https://localhost:8080/" 630 | }, 631 | "id": "pJItorUphT_1", 632 | "outputId": "d6278558-1b43-4fd4-bca7-3cdb4a4479bc" 633 | }, 634 | "execution_count": 21, 635 | "outputs": [ 636 | { 637 | "output_type": "stream", 638 | "name": "stdout", 639 | "text": [ 640 | "T\n", 641 | "8\n" 642 | ] 643 | } 644 | ] 645 | }, 646 | { 647 | "cell_type": "code", 648 | "source": [ 649 | "name = name.lower() # 記得 assign 回去\n", 650 | "print(name)\n", 651 | "name = name.upper()\n", 652 | "print(name)\n", 653 | "print(name[0].islower())\n", 654 | "print(name[0].isupper())" 655 | ], 656 | "metadata": { 657 | "colab": { 658 | "base_uri": "https://localhost:8080/" 659 | }, 660 | "id": "cv23_y_vhwfg", 661 | "outputId": "06e68272-a8de-4095-efa3-ec4cde574b2b" 662 | }, 663 | "execution_count": 22, 664 | "outputs": [ 665 | { 666 | "output_type": "stream", 667 | "name": "stdout", 668 | "text": [ 669 | "thousand\n", 670 | "THOUSAND\n", 671 | "False\n", 672 | "True\n" 673 | ] 674 | } 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "source": [ 680 | "s = input(\"\")" 681 | ], 682 | "metadata": { 683 | "colab": { 684 | "base_uri": "https://localhost:8080/" 685 | }, 686 | "id": "-a_jmskeiBKS", 687 | "outputId": "b495a1af-f99a-40d4-d666-42568e2074ef" 688 | }, 689 | "execution_count": 27, 690 | "outputs": [ 691 | { 692 | "name": "stdout", 693 | "output_type": "stream", 694 | "text": [ 695 | "3 2 5 7 8\n" 696 | ] 697 | } 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "source": [ 703 | "s.split()" 704 | ], 705 | "metadata": { 706 | "colab": { 707 | "base_uri": "https://localhost:8080/" 708 | }, 709 | "id": "O7yl6hBFi-q6", 710 | "outputId": "362d58b6-1da8-4a43-c03a-71d303a98c5f" 711 | }, 712 | "execution_count": 28, 713 | "outputs": [ 714 | { 715 | "output_type": "execute_result", 716 | "data": { 717 | "text/plain": [ 718 | "['3', '2', '5', '7', '8']" 719 | ] 720 | }, 721 | "metadata": {}, 722 | "execution_count": 28 723 | } 724 | ] 725 | }, 726 | { 727 | "cell_type": "code", 728 | "source": [ 729 | "s = input(\"\")" 730 | ], 731 | "metadata": { 732 | "colab": { 733 | "base_uri": "https://localhost:8080/" 734 | }, 735 | "id": "uMLT1UnSjBgm", 736 | "outputId": "56507025-d396-4282-84ae-dc61b9f529f5" 737 | }, 738 | "execution_count": 30, 739 | "outputs": [ 740 | { 741 | "name": "stdout", 742 | "output_type": "stream", 743 | "text": [ 744 | "3,2,5,7,8\n" 745 | ] 746 | } 747 | ] 748 | }, 749 | { 750 | "cell_type": "code", 751 | "source": [ 752 | "s.split(\",\")" 753 | ], 754 | "metadata": { 755 | "colab": { 756 | "base_uri": "https://localhost:8080/" 757 | }, 758 | "id": "GF39gkdnjPhy", 759 | "outputId": "d7056a30-e256-4dd4-ac80-ec9ca4160ef8" 760 | }, 761 | "execution_count": 31, 762 | "outputs": [ 763 | { 764 | "output_type": "execute_result", 765 | "data": { 766 | "text/plain": [ 767 | "['3', '2', '5', '7', '8']" 768 | ] 769 | }, 770 | "metadata": {}, 771 | "execution_count": 31 772 | } 773 | ] 774 | }, 775 | { 776 | "cell_type": "code", 777 | "source": [ 778 | "# 迴圈 + 字串 (解答1)\n", 779 | "s = input()\n", 780 | "s = s.split()\n", 781 | "ans = []\n", 782 | "for v in s:\n", 783 | " ans.append(int(v))\n", 784 | "print(ans)" 785 | ], 786 | "metadata": { 787 | "colab": { 788 | "base_uri": "https://localhost:8080/" 789 | }, 790 | "id": "vIpVqr76jUQh", 791 | "outputId": "c65e5cce-d385-44bd-9c6d-988c31f8ee06" 792 | }, 793 | "execution_count": 32, 794 | "outputs": [ 795 | { 796 | "output_type": "stream", 797 | "name": "stdout", 798 | "text": [ 799 | "3 2 5 7 8\n", 800 | "[3, 2, 5, 7, 8]\n" 801 | ] 802 | } 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "source": [ 808 | "# 迴圈 + 字串 (解答2)\n", 809 | "s = input()\n", 810 | "count = 0\n", 811 | "for v in s:\n", 812 | " if v == \"a\":\n", 813 | " count += 1\n", 814 | "print(count)" 815 | ], 816 | "metadata": { 817 | "colab": { 818 | "base_uri": "https://localhost:8080/" 819 | }, 820 | "id": "LF1bktXEksgb", 821 | "outputId": "4dc47d23-cf7f-41fc-fde2-ec4dddac2960" 822 | }, 823 | "execution_count": 33, 824 | "outputs": [ 825 | { 826 | "output_type": "stream", 827 | "name": "stdout", 828 | "text": [ 829 | "abijvkgigjekgjbaafigjnaa\n", 830 | "5\n" 831 | ] 832 | } 833 | ] 834 | }, 835 | { 836 | "cell_type": "code", 837 | "source": [ 838 | "n = int(input())\n", 839 | "# ans = []\n", 840 | "# for i in range(n):\n", 841 | "# if i % 2 == 0:\n", 842 | "# ans.append(i)\n", 843 | "\n", 844 | "ans = [i for i in range(n) if i % 2 == 0]\n", 845 | "print(ans)" 846 | ], 847 | "metadata": { 848 | "colab": { 849 | "base_uri": "https://localhost:8080/" 850 | }, 851 | "id": "DBd5vowVlXlX", 852 | "outputId": "30879431-223c-465e-e0cf-f2bdf6f10011" 853 | }, 854 | "execution_count": 36, 855 | "outputs": [ 856 | { 857 | "output_type": "stream", 858 | "name": "stdout", 859 | "text": [ 860 | "10\n", 861 | "[0, 2, 4, 6, 8]\n" 862 | ] 863 | } 864 | ] 865 | } 866 | ] 867 | } -------------------------------------------------------------------------------- /class08/hw5_solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "hw5_solution.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyPa5lLtAmcOwBHYMjQimgX/", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "# **hw5 solution**" 34 | ], 35 | "metadata": { 36 | "id": "N33Tsd3Rg6h7" 37 | } 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 1, 42 | "metadata": { 43 | "id": "T6XKnpSNtrxv" 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "import numpy as np\n", 48 | "import matplotlib.pyplot as plt\n", 49 | "import pandas as pd" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "source": [ 55 | "## **讀取資料**" 56 | ], 57 | "metadata": { 58 | "id": "MfezaGdkg2fX" 59 | } 60 | }, 61 | { 62 | "cell_type": "code", 63 | "source": [ 64 | "data = pd.read_csv(\"https://raw.githubusercontent.com/ThousandAI/pycs4001/main/class06/Salary_Data.csv\")\n", 65 | "data.head()" 66 | ], 67 | "metadata": { 68 | "colab": { 69 | "base_uri": "https://localhost:8080/", 70 | "height": 206 71 | }, 72 | "id": "9_qjwI40tt8L", 73 | "outputId": "54e585d6-9f6d-4f96-fe17-019249dbe26c" 74 | }, 75 | "execution_count": 2, 76 | "outputs": [ 77 | { 78 | "output_type": "execute_result", 79 | "data": { 80 | "text/plain": [ 81 | " YearsExperience Salary\n", 82 | "0 1.1 39343.0\n", 83 | "1 1.3 46205.0\n", 84 | "2 1.5 37731.0\n", 85 | "3 2.0 43525.0\n", 86 | "4 2.2 39891.0" 87 | ], 88 | "text/html": [ 89 | "\n", 90 | "
\n", 91 | "
\n", 92 | "
\n", 93 | "\n", 106 | "\n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | "
YearsExperienceSalary
01.139343.0
11.346205.0
21.537731.0
32.043525.0
42.239891.0
\n", 142 | "
\n", 143 | " \n", 153 | " \n", 154 | " \n", 191 | "\n", 192 | " \n", 216 | "
\n", 217 | "
\n", 218 | " " 219 | ] 220 | }, 221 | "metadata": {}, 222 | "execution_count": 2 223 | } 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "source": [ 229 | "from sklearn.model_selection import train_test_split\n", 230 | "X = np.array(data[\"YearsExperience\"]).reshape(-1,1)\n", 231 | "Y = np.array(data[\"Salary\"]).reshape(-1,1)\n", 232 | "train_x, test_x, train_y, test_y = train_test_split(X, Y, test_size=0.2, random_state=10)" 233 | ], 234 | "metadata": { 235 | "id": "0W0pDL27tz-Z" 236 | }, 237 | "execution_count": 3, 238 | "outputs": [] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "source": [ 243 | "## **標準化數據**" 244 | ], 245 | "metadata": { 246 | "id": "ubswWiebhC06" 247 | } 248 | }, 249 | { 250 | "cell_type": "code", 251 | "source": [ 252 | "from sklearn.preprocessing import StandardScaler\n", 253 | "scaler_x = StandardScaler()\n", 254 | "scaler_y = StandardScaler()\n", 255 | "\n", 256 | "sc_train_x = scaler_x.fit_transform(train_x)\n", 257 | "sc_train_y = scaler_y.fit_transform(train_y)" 258 | ], 259 | "metadata": { 260 | "id": "43A7xhgRhBuX" 261 | }, 262 | "execution_count": 4, 263 | "outputs": [] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "source": [ 268 | "## **搭建模型**" 269 | ], 270 | "metadata": { 271 | "id": "9Agk6qThhb2m" 272 | } 273 | }, 274 | { 275 | "cell_type": "code", 276 | "source": [ 277 | "from sklearn.linear_model import LinearRegression\n", 278 | "regression = LinearRegression()" 279 | ], 280 | "metadata": { 281 | "id": "Z4MsSkqzuCKL" 282 | }, 283 | "execution_count": 5, 284 | "outputs": [] 285 | }, 286 | { 287 | "cell_type": "markdown", 288 | "source": [ 289 | "## **訓練模型**" 290 | ], 291 | "metadata": { 292 | "id": "wzeKV3C_hgpH" 293 | } 294 | }, 295 | { 296 | "cell_type": "code", 297 | "source": [ 298 | "regression.fit(sc_train_x, sc_train_y)" 299 | ], 300 | "metadata": { 301 | "colab": { 302 | "base_uri": "https://localhost:8080/" 303 | }, 304 | "id": "molap077uQF_", 305 | "outputId": "644480cf-fc69-4cba-fa66-b72c533ff065" 306 | }, 307 | "execution_count": 6, 308 | "outputs": [ 309 | { 310 | "output_type": "execute_result", 311 | "data": { 312 | "text/plain": [ 313 | "LinearRegression()" 314 | ] 315 | }, 316 | "metadata": {}, 317 | "execution_count": 6 318 | } 319 | ] 320 | }, 321 | { 322 | "cell_type": "markdown", 323 | "source": [ 324 | "## **評估模型**" 325 | ], 326 | "metadata": { 327 | "id": "YyeFuJNvisOJ" 328 | } 329 | }, 330 | { 331 | "cell_type": "code", 332 | "source": [ 333 | "from sklearn.metrics import mean_squared_error\n", 334 | "sc_test_x = scaler_x.transform(test_x)\n", 335 | "sc_test_y = scaler_y.transform(test_y)\n", 336 | "y_hat = regression.predict(sc_test_x)\n", 337 | "print(f\"evaluation MSE: {mean_squared_error(sc_test_y, y_hat)}\")" 338 | ], 339 | "metadata": { 340 | "colab": { 341 | "base_uri": "https://localhost:8080/" 342 | }, 343 | "id": "xIrmlLZfubD7", 344 | "outputId": "96bcc727-3363-4183-b6da-ee0741f5ded8" 345 | }, 346 | "execution_count": 7, 347 | "outputs": [ 348 | { 349 | "output_type": "stream", 350 | "name": "stdout", 351 | "text": [ 352 | "evaluation MSE: 0.013446201443205819\n" 353 | ] 354 | } 355 | ] 356 | }, 357 | { 358 | "cell_type": "markdown", 359 | "source": [ 360 | "## **畫圖**" 361 | ], 362 | "metadata": { 363 | "id": "gGPkrwfrmMIS" 364 | } 365 | }, 366 | { 367 | "cell_type": "code", 368 | "source": [ 369 | "Y_hat = regression.predict(scaler_x.transform(X))\n", 370 | "Y_inv_hat = scaler_y.inverse_transform(Y_hat)\n", 371 | "plt.scatter(X, Y, s =3)\n", 372 | "plt.plot(X, Y_inv_hat, color=\"red\")\n", 373 | "plt.show()" 374 | ], 375 | "metadata": { 376 | "id": "weywhahzvJNJ", 377 | "outputId": "363e720c-044d-477b-e5cd-b29c5b1721c3", 378 | "colab": { 379 | "base_uri": "https://localhost:8080/", 380 | "height": 265 381 | } 382 | }, 383 | "execution_count": 8, 384 | "outputs": [ 385 | { 386 | "output_type": "display_data", 387 | "data": { 388 | "text/plain": [ 389 | "
" 390 | ], 391 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAD4CAYAAAAZ1BptAAAABHN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+cMW6nZTlERCQh1SRERCQhJQkREUlISUJERBJSkhARkYSUJEREJCElCRERSUhJQkREEvp/vdFfO7veRa0AAAAASUVORK5CYII=\n" 392 | }, 393 | "metadata": { 394 | "needs_background": "light" 395 | } 396 | } 397 | ] 398 | } 399 | ] 400 | } -------------------------------------------------------------------------------- /class09/test.csv: -------------------------------------------------------------------------------- 1 | PassengerId,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked 2 | 892,3,"Kelly, Mr. James",male,34.5,0,0,330911,7.8292,,Q 3 | 893,3,"Wilkes, Mrs. James (Ellen Needs)",female,47,1,0,363272,7,,S 4 | 894,2,"Myles, Mr. Thomas Francis",male,62,0,0,240276,9.6875,,Q 5 | 895,3,"Wirz, Mr. Albert",male,27,0,0,315154,8.6625,,S 6 | 896,3,"Hirvonen, Mrs. Alexander (Helga E Lindqvist)",female,22,1,1,3101298,12.2875,,S 7 | 897,3,"Svensson, Mr. Johan Cervin",male,14,0,0,7538,9.225,,S 8 | 898,3,"Connolly, Miss. Kate",female,30,0,0,330972,7.6292,,Q 9 | 899,2,"Caldwell, Mr. Albert Francis",male,26,1,1,248738,29,,S 10 | 900,3,"Abrahim, Mrs. Joseph (Sophie Halaut Easu)",female,18,0,0,2657,7.2292,,C 11 | 901,3,"Davies, Mr. John Samuel",male,21,2,0,A/4 48871,24.15,,S 12 | 902,3,"Ilieff, Mr. Ylio",male,,0,0,349220,7.8958,,S 13 | 903,1,"Jones, Mr. Charles Cresson",male,46,0,0,694,26,,S 14 | 904,1,"Snyder, Mrs. John Pillsbury (Nelle Stevenson)",female,23,1,0,21228,82.2667,B45,S 15 | 905,2,"Howard, Mr. Benjamin",male,63,1,0,24065,26,,S 16 | 906,1,"Chaffee, Mrs. Herbert Fuller (Carrie Constance Toogood)",female,47,1,0,W.E.P. 5734,61.175,E31,S 17 | 907,2,"del Carlo, Mrs. Sebastiano (Argenia Genovesi)",female,24,1,0,SC/PARIS 2167,27.7208,,C 18 | 908,2,"Keane, Mr. Daniel",male,35,0,0,233734,12.35,,Q 19 | 909,3,"Assaf, Mr. Gerios",male,21,0,0,2692,7.225,,C 20 | 910,3,"Ilmakangas, Miss. Ida Livija",female,27,1,0,STON/O2. 3101270,7.925,,S 21 | 911,3,"Assaf Khalil, Mrs. Mariana (Miriam"")""",female,45,0,0,2696,7.225,,C 22 | 912,1,"Rothschild, Mr. Martin",male,55,1,0,PC 17603,59.4,,C 23 | 913,3,"Olsen, Master. Artur Karl",male,9,0,1,C 17368,3.1708,,S 24 | 914,1,"Flegenheim, Mrs. Alfred (Antoinette)",female,,0,0,PC 17598,31.6833,,S 25 | 915,1,"Williams, Mr. Richard Norris II",male,21,0,1,PC 17597,61.3792,,C 26 | 916,1,"Ryerson, Mrs. Arthur Larned (Emily Maria Borie)",female,48,1,3,PC 17608,262.375,B57 B59 B63 B66,C 27 | 917,3,"Robins, Mr. Alexander A",male,50,1,0,A/5. 3337,14.5,,S 28 | 918,1,"Ostby, Miss. Helene Ragnhild",female,22,0,1,113509,61.9792,B36,C 29 | 919,3,"Daher, Mr. Shedid",male,22.5,0,0,2698,7.225,,C 30 | 920,1,"Brady, Mr. John Bertram",male,41,0,0,113054,30.5,A21,S 31 | 921,3,"Samaan, Mr. Elias",male,,2,0,2662,21.6792,,C 32 | 922,2,"Louch, Mr. Charles Alexander",male,50,1,0,SC/AH 3085,26,,S 33 | 923,2,"Jefferys, Mr. Clifford Thomas",male,24,2,0,C.A. 31029,31.5,,S 34 | 924,3,"Dean, Mrs. Bertram (Eva Georgetta Light)",female,33,1,2,C.A. 2315,20.575,,S 35 | 925,3,"Johnston, Mrs. Andrew G (Elizabeth Lily"" Watson)""",female,,1,2,W./C. 6607,23.45,,S 36 | 926,1,"Mock, Mr. Philipp Edmund",male,30,1,0,13236,57.75,C78,C 37 | 927,3,"Katavelas, Mr. Vassilios (Catavelas Vassilios"")""",male,18.5,0,0,2682,7.2292,,C 38 | 928,3,"Roth, Miss. Sarah A",female,,0,0,342712,8.05,,S 39 | 929,3,"Cacic, Miss. Manda",female,21,0,0,315087,8.6625,,S 40 | 930,3,"Sap, Mr. Julius",male,25,0,0,345768,9.5,,S 41 | 931,3,"Hee, Mr. Ling",male,,0,0,1601,56.4958,,S 42 | 932,3,"Karun, Mr. Franz",male,39,0,1,349256,13.4167,,C 43 | 933,1,"Franklin, Mr. Thomas Parham",male,,0,0,113778,26.55,D34,S 44 | 934,3,"Goldsmith, Mr. Nathan",male,41,0,0,SOTON/O.Q. 3101263,7.85,,S 45 | 935,2,"Corbett, Mrs. Walter H (Irene Colvin)",female,30,0,0,237249,13,,S 46 | 936,1,"Kimball, Mrs. Edwin Nelson Jr (Gertrude Parsons)",female,45,1,0,11753,52.5542,D19,S 47 | 937,3,"Peltomaki, Mr. Nikolai Johannes",male,25,0,0,STON/O 2. 3101291,7.925,,S 48 | 938,1,"Chevre, Mr. Paul Romaine",male,45,0,0,PC 17594,29.7,A9,C 49 | 939,3,"Shaughnessy, Mr. Patrick",male,,0,0,370374,7.75,,Q 50 | 940,1,"Bucknell, Mrs. William Robert (Emma Eliza Ward)",female,60,0,0,11813,76.2917,D15,C 51 | 941,3,"Coutts, Mrs. William (Winnie Minnie"" Treanor)""",female,36,0,2,C.A. 37671,15.9,,S 52 | 942,1,"Smith, Mr. Lucien Philip",male,24,1,0,13695,60,C31,S 53 | 943,2,"Pulbaum, Mr. Franz",male,27,0,0,SC/PARIS 2168,15.0333,,C 54 | 944,2,"Hocking, Miss. Ellen Nellie""""",female,20,2,1,29105,23,,S 55 | 945,1,"Fortune, Miss. Ethel Flora",female,28,3,2,19950,263,C23 C25 C27,S 56 | 946,2,"Mangiavacchi, Mr. Serafino Emilio",male,,0,0,SC/A.3 2861,15.5792,,C 57 | 947,3,"Rice, Master. Albert",male,10,4,1,382652,29.125,,Q 58 | 948,3,"Cor, Mr. Bartol",male,35,0,0,349230,7.8958,,S 59 | 949,3,"Abelseth, Mr. Olaus Jorgensen",male,25,0,0,348122,7.65,F G63,S 60 | 950,3,"Davison, Mr. Thomas Henry",male,,1,0,386525,16.1,,S 61 | 951,1,"Chaudanson, Miss. Victorine",female,36,0,0,PC 17608,262.375,B61,C 62 | 952,3,"Dika, Mr. Mirko",male,17,0,0,349232,7.8958,,S 63 | 953,2,"McCrae, Mr. Arthur Gordon",male,32,0,0,237216,13.5,,S 64 | 954,3,"Bjorklund, Mr. Ernst Herbert",male,18,0,0,347090,7.75,,S 65 | 955,3,"Bradley, Miss. Bridget Delia",female,22,0,0,334914,7.725,,Q 66 | 956,1,"Ryerson, Master. John Borie",male,13,2,2,PC 17608,262.375,B57 B59 B63 B66,C 67 | 957,2,"Corey, Mrs. Percy C (Mary Phyllis Elizabeth Miller)",female,,0,0,F.C.C. 13534,21,,S 68 | 958,3,"Burns, Miss. Mary Delia",female,18,0,0,330963,7.8792,,Q 69 | 959,1,"Moore, Mr. Clarence Bloomfield",male,47,0,0,113796,42.4,,S 70 | 960,1,"Tucker, Mr. Gilbert Milligan Jr",male,31,0,0,2543,28.5375,C53,C 71 | 961,1,"Fortune, Mrs. Mark (Mary McDougald)",female,60,1,4,19950,263,C23 C25 C27,S 72 | 962,3,"Mulvihill, Miss. Bertha E",female,24,0,0,382653,7.75,,Q 73 | 963,3,"Minkoff, Mr. Lazar",male,21,0,0,349211,7.8958,,S 74 | 964,3,"Nieminen, Miss. Manta Josefina",female,29,0,0,3101297,7.925,,S 75 | 965,1,"Ovies y Rodriguez, Mr. Servando",male,28.5,0,0,PC 17562,27.7208,D43,C 76 | 966,1,"Geiger, Miss. Amalie",female,35,0,0,113503,211.5,C130,C 77 | 967,1,"Keeping, Mr. Edwin",male,32.5,0,0,113503,211.5,C132,C 78 | 968,3,"Miles, Mr. Frank",male,,0,0,359306,8.05,,S 79 | 969,1,"Cornell, Mrs. Robert Clifford (Malvina Helen Lamson)",female,55,2,0,11770,25.7,C101,S 80 | 970,2,"Aldworth, Mr. Charles Augustus",male,30,0,0,248744,13,,S 81 | 971,3,"Doyle, Miss. Elizabeth",female,24,0,0,368702,7.75,,Q 82 | 972,3,"Boulos, Master. Akar",male,6,1,1,2678,15.2458,,C 83 | 973,1,"Straus, Mr. Isidor",male,67,1,0,PC 17483,221.7792,C55 C57,S 84 | 974,1,"Case, Mr. Howard Brown",male,49,0,0,19924,26,,S 85 | 975,3,"Demetri, Mr. Marinko",male,,0,0,349238,7.8958,,S 86 | 976,2,"Lamb, Mr. John Joseph",male,,0,0,240261,10.7083,,Q 87 | 977,3,"Khalil, Mr. Betros",male,,1,0,2660,14.4542,,C 88 | 978,3,"Barry, Miss. Julia",female,27,0,0,330844,7.8792,,Q 89 | 979,3,"Badman, Miss. Emily Louisa",female,18,0,0,A/4 31416,8.05,,S 90 | 980,3,"O'Donoghue, Ms. Bridget",female,,0,0,364856,7.75,,Q 91 | 981,2,"Wells, Master. Ralph Lester",male,2,1,1,29103,23,,S 92 | 982,3,"Dyker, Mrs. Adolf Fredrik (Anna Elisabeth Judith Andersson)",female,22,1,0,347072,13.9,,S 93 | 983,3,"Pedersen, Mr. Olaf",male,,0,0,345498,7.775,,S 94 | 984,1,"Davidson, Mrs. Thornton (Orian Hays)",female,27,1,2,F.C. 12750,52,B71,S 95 | 985,3,"Guest, Mr. Robert",male,,0,0,376563,8.05,,S 96 | 986,1,"Birnbaum, Mr. Jakob",male,25,0,0,13905,26,,C 97 | 987,3,"Tenglin, Mr. Gunnar Isidor",male,25,0,0,350033,7.7958,,S 98 | 988,1,"Cavendish, Mrs. Tyrell William (Julia Florence Siegel)",female,76,1,0,19877,78.85,C46,S 99 | 989,3,"Makinen, Mr. Kalle Edvard",male,29,0,0,STON/O 2. 3101268,7.925,,S 100 | 990,3,"Braf, Miss. Elin Ester Maria",female,20,0,0,347471,7.8542,,S 101 | 991,3,"Nancarrow, Mr. William Henry",male,33,0,0,A./5. 3338,8.05,,S 102 | 992,1,"Stengel, Mrs. Charles Emil Henry (Annie May Morris)",female,43,1,0,11778,55.4417,C116,C 103 | 993,2,"Weisz, Mr. Leopold",male,27,1,0,228414,26,,S 104 | 994,3,"Foley, Mr. William",male,,0,0,365235,7.75,,Q 105 | 995,3,"Johansson Palmquist, Mr. Oskar Leander",male,26,0,0,347070,7.775,,S 106 | 996,3,"Thomas, Mrs. Alexander (Thamine Thelma"")""",female,16,1,1,2625,8.5167,,C 107 | 997,3,"Holthen, Mr. Johan Martin",male,28,0,0,C 4001,22.525,,S 108 | 998,3,"Buckley, Mr. Daniel",male,21,0,0,330920,7.8208,,Q 109 | 999,3,"Ryan, Mr. Edward",male,,0,0,383162,7.75,,Q 110 | 1000,3,"Willer, Mr. Aaron (Abi Weller"")""",male,,0,0,3410,8.7125,,S 111 | 1001,2,"Swane, Mr. George",male,18.5,0,0,248734,13,F,S 112 | 1002,2,"Stanton, Mr. Samuel Ward",male,41,0,0,237734,15.0458,,C 113 | 1003,3,"Shine, Miss. Ellen Natalia",female,,0,0,330968,7.7792,,Q 114 | 1004,1,"Evans, Miss. Edith Corse",female,36,0,0,PC 17531,31.6792,A29,C 115 | 1005,3,"Buckley, Miss. Katherine",female,18.5,0,0,329944,7.2833,,Q 116 | 1006,1,"Straus, Mrs. Isidor (Rosalie Ida Blun)",female,63,1,0,PC 17483,221.7792,C55 C57,S 117 | 1007,3,"Chronopoulos, Mr. Demetrios",male,18,1,0,2680,14.4542,,C 118 | 1008,3,"Thomas, Mr. John",male,,0,0,2681,6.4375,,C 119 | 1009,3,"Sandstrom, Miss. Beatrice Irene",female,1,1,1,PP 9549,16.7,G6,S 120 | 1010,1,"Beattie, Mr. Thomson",male,36,0,0,13050,75.2417,C6,C 121 | 1011,2,"Chapman, Mrs. John Henry (Sara Elizabeth Lawry)",female,29,1,0,SC/AH 29037,26,,S 122 | 1012,2,"Watt, Miss. Bertha J",female,12,0,0,C.A. 33595,15.75,,S 123 | 1013,3,"Kiernan, Mr. John",male,,1,0,367227,7.75,,Q 124 | 1014,1,"Schabert, Mrs. Paul (Emma Mock)",female,35,1,0,13236,57.75,C28,C 125 | 1015,3,"Carver, Mr. Alfred John",male,28,0,0,392095,7.25,,S 126 | 1016,3,"Kennedy, Mr. John",male,,0,0,368783,7.75,,Q 127 | 1017,3,"Cribb, Miss. Laura Alice",female,17,0,1,371362,16.1,,S 128 | 1018,3,"Brobeck, Mr. Karl Rudolf",male,22,0,0,350045,7.7958,,S 129 | 1019,3,"McCoy, Miss. Alicia",female,,2,0,367226,23.25,,Q 130 | 1020,2,"Bowenur, Mr. Solomon",male,42,0,0,211535,13,,S 131 | 1021,3,"Petersen, Mr. Marius",male,24,0,0,342441,8.05,,S 132 | 1022,3,"Spinner, Mr. Henry John",male,32,0,0,STON/OQ. 369943,8.05,,S 133 | 1023,1,"Gracie, Col. Archibald IV",male,53,0,0,113780,28.5,C51,C 134 | 1024,3,"Lefebre, Mrs. Frank (Frances)",female,,0,4,4133,25.4667,,S 135 | 1025,3,"Thomas, Mr. Charles P",male,,1,0,2621,6.4375,,C 136 | 1026,3,"Dintcheff, Mr. Valtcho",male,43,0,0,349226,7.8958,,S 137 | 1027,3,"Carlsson, Mr. Carl Robert",male,24,0,0,350409,7.8542,,S 138 | 1028,3,"Zakarian, Mr. Mapriededer",male,26.5,0,0,2656,7.225,,C 139 | 1029,2,"Schmidt, Mr. August",male,26,0,0,248659,13,,S 140 | 1030,3,"Drapkin, Miss. Jennie",female,23,0,0,SOTON/OQ 392083,8.05,,S 141 | 1031,3,"Goodwin, Mr. Charles Frederick",male,40,1,6,CA 2144,46.9,,S 142 | 1032,3,"Goodwin, Miss. Jessie Allis",female,10,5,2,CA 2144,46.9,,S 143 | 1033,1,"Daniels, Miss. Sarah",female,33,0,0,113781,151.55,,S 144 | 1034,1,"Ryerson, Mr. Arthur Larned",male,61,1,3,PC 17608,262.375,B57 B59 B63 B66,C 145 | 1035,2,"Beauchamp, Mr. Henry James",male,28,0,0,244358,26,,S 146 | 1036,1,"Lindeberg-Lind, Mr. Erik Gustaf (Mr Edward Lingrey"")""",male,42,0,0,17475,26.55,,S 147 | 1037,3,"Vander Planke, Mr. Julius",male,31,3,0,345763,18,,S 148 | 1038,1,"Hilliard, Mr. Herbert Henry",male,,0,0,17463,51.8625,E46,S 149 | 1039,3,"Davies, Mr. Evan",male,22,0,0,SC/A4 23568,8.05,,S 150 | 1040,1,"Crafton, Mr. John Bertram",male,,0,0,113791,26.55,,S 151 | 1041,2,"Lahtinen, Rev. William",male,30,1,1,250651,26,,S 152 | 1042,1,"Earnshaw, Mrs. Boulton (Olive Potter)",female,23,0,1,11767,83.1583,C54,C 153 | 1043,3,"Matinoff, Mr. Nicola",male,,0,0,349255,7.8958,,C 154 | 1044,3,"Storey, Mr. Thomas",male,60.5,0,0,3701,,,S 155 | 1045,3,"Klasen, Mrs. (Hulda Kristina Eugenia Lofqvist)",female,36,0,2,350405,12.1833,,S 156 | 1046,3,"Asplund, Master. Filip Oscar",male,13,4,2,347077,31.3875,,S 157 | 1047,3,"Duquemin, Mr. Joseph",male,24,0,0,S.O./P.P. 752,7.55,,S 158 | 1048,1,"Bird, Miss. Ellen",female,29,0,0,PC 17483,221.7792,C97,S 159 | 1049,3,"Lundin, Miss. Olga Elida",female,23,0,0,347469,7.8542,,S 160 | 1050,1,"Borebank, Mr. John James",male,42,0,0,110489,26.55,D22,S 161 | 1051,3,"Peacock, Mrs. Benjamin (Edith Nile)",female,26,0,2,SOTON/O.Q. 3101315,13.775,,S 162 | 1052,3,"Smyth, Miss. Julia",female,,0,0,335432,7.7333,,Q 163 | 1053,3,"Touma, Master. Georges Youssef",male,7,1,1,2650,15.2458,,C 164 | 1054,2,"Wright, Miss. Marion",female,26,0,0,220844,13.5,,S 165 | 1055,3,"Pearce, Mr. Ernest",male,,0,0,343271,7,,S 166 | 1056,2,"Peruschitz, Rev. Joseph Maria",male,41,0,0,237393,13,,S 167 | 1057,3,"Kink-Heilmann, Mrs. Anton (Luise Heilmann)",female,26,1,1,315153,22.025,,S 168 | 1058,1,"Brandeis, Mr. Emil",male,48,0,0,PC 17591,50.4958,B10,C 169 | 1059,3,"Ford, Mr. Edward Watson",male,18,2,2,W./C. 6608,34.375,,S 170 | 1060,1,"Cassebeer, Mrs. Henry Arthur Jr (Eleanor Genevieve Fosdick)",female,,0,0,17770,27.7208,,C 171 | 1061,3,"Hellstrom, Miss. Hilda Maria",female,22,0,0,7548,8.9625,,S 172 | 1062,3,"Lithman, Mr. Simon",male,,0,0,S.O./P.P. 251,7.55,,S 173 | 1063,3,"Zakarian, Mr. Ortin",male,27,0,0,2670,7.225,,C 174 | 1064,3,"Dyker, Mr. Adolf Fredrik",male,23,1,0,347072,13.9,,S 175 | 1065,3,"Torfa, Mr. Assad",male,,0,0,2673,7.2292,,C 176 | 1066,3,"Asplund, Mr. Carl Oscar Vilhelm Gustafsson",male,40,1,5,347077,31.3875,,S 177 | 1067,2,"Brown, Miss. Edith Eileen",female,15,0,2,29750,39,,S 178 | 1068,2,"Sincock, Miss. Maude",female,20,0,0,C.A. 33112,36.75,,S 179 | 1069,1,"Stengel, Mr. Charles Emil Henry",male,54,1,0,11778,55.4417,C116,C 180 | 1070,2,"Becker, Mrs. Allen Oliver (Nellie E Baumgardner)",female,36,0,3,230136,39,F4,S 181 | 1071,1,"Compton, Mrs. Alexander Taylor (Mary Eliza Ingersoll)",female,64,0,2,PC 17756,83.1583,E45,C 182 | 1072,2,"McCrie, Mr. James Matthew",male,30,0,0,233478,13,,S 183 | 1073,1,"Compton, Mr. Alexander Taylor Jr",male,37,1,1,PC 17756,83.1583,E52,C 184 | 1074,1,"Marvin, Mrs. Daniel Warner (Mary Graham Carmichael Farquarson)",female,18,1,0,113773,53.1,D30,S 185 | 1075,3,"Lane, Mr. Patrick",male,,0,0,7935,7.75,,Q 186 | 1076,1,"Douglas, Mrs. Frederick Charles (Mary Helene Baxter)",female,27,1,1,PC 17558,247.5208,B58 B60,C 187 | 1077,2,"Maybery, Mr. Frank Hubert",male,40,0,0,239059,16,,S 188 | 1078,2,"Phillips, Miss. Alice Frances Louisa",female,21,0,1,S.O./P.P. 2,21,,S 189 | 1079,3,"Davies, Mr. Joseph",male,17,2,0,A/4 48873,8.05,,S 190 | 1080,3,"Sage, Miss. Ada",female,,8,2,CA. 2343,69.55,,S 191 | 1081,2,"Veal, Mr. James",male,40,0,0,28221,13,,S 192 | 1082,2,"Angle, Mr. William A",male,34,1,0,226875,26,,S 193 | 1083,1,"Salomon, Mr. Abraham L",male,,0,0,111163,26,,S 194 | 1084,3,"van Billiard, Master. Walter John",male,11.5,1,1,A/5. 851,14.5,,S 195 | 1085,2,"Lingane, Mr. John",male,61,0,0,235509,12.35,,Q 196 | 1086,2,"Drew, Master. Marshall Brines",male,8,0,2,28220,32.5,,S 197 | 1087,3,"Karlsson, Mr. Julius Konrad Eugen",male,33,0,0,347465,7.8542,,S 198 | 1088,1,"Spedden, Master. Robert Douglas",male,6,0,2,16966,134.5,E34,C 199 | 1089,3,"Nilsson, Miss. Berta Olivia",female,18,0,0,347066,7.775,,S 200 | 1090,2,"Baimbrigge, Mr. Charles Robert",male,23,0,0,C.A. 31030,10.5,,S 201 | 1091,3,"Rasmussen, Mrs. (Lena Jacobsen Solvang)",female,,0,0,65305,8.1125,,S 202 | 1092,3,"Murphy, Miss. Nora",female,,0,0,36568,15.5,,Q 203 | 1093,3,"Danbom, Master. Gilbert Sigvard Emanuel",male,0.33,0,2,347080,14.4,,S 204 | 1094,1,"Astor, Col. John Jacob",male,47,1,0,PC 17757,227.525,C62 C64,C 205 | 1095,2,"Quick, Miss. Winifred Vera",female,8,1,1,26360,26,,S 206 | 1096,2,"Andrew, Mr. Frank Thomas",male,25,0,0,C.A. 34050,10.5,,S 207 | 1097,1,"Omont, Mr. Alfred Fernand",male,,0,0,F.C. 12998,25.7417,,C 208 | 1098,3,"McGowan, Miss. Katherine",female,35,0,0,9232,7.75,,Q 209 | 1099,2,"Collett, Mr. Sidney C Stuart",male,24,0,0,28034,10.5,,S 210 | 1100,1,"Rosenbaum, Miss. Edith Louise",female,33,0,0,PC 17613,27.7208,A11,C 211 | 1101,3,"Delalic, Mr. Redjo",male,25,0,0,349250,7.8958,,S 212 | 1102,3,"Andersen, Mr. Albert Karvin",male,32,0,0,C 4001,22.525,,S 213 | 1103,3,"Finoli, Mr. Luigi",male,,0,0,SOTON/O.Q. 3101308,7.05,,S 214 | 1104,2,"Deacon, Mr. Percy William",male,17,0,0,S.O.C. 14879,73.5,,S 215 | 1105,2,"Howard, Mrs. Benjamin (Ellen Truelove Arman)",female,60,1,0,24065,26,,S 216 | 1106,3,"Andersson, Miss. Ida Augusta Margareta",female,38,4,2,347091,7.775,,S 217 | 1107,1,"Head, Mr. Christopher",male,42,0,0,113038,42.5,B11,S 218 | 1108,3,"Mahon, Miss. Bridget Delia",female,,0,0,330924,7.8792,,Q 219 | 1109,1,"Wick, Mr. George Dennick",male,57,1,1,36928,164.8667,,S 220 | 1110,1,"Widener, Mrs. George Dunton (Eleanor Elkins)",female,50,1,1,113503,211.5,C80,C 221 | 1111,3,"Thomson, Mr. Alexander Morrison",male,,0,0,32302,8.05,,S 222 | 1112,2,"Duran y More, Miss. Florentina",female,30,1,0,SC/PARIS 2148,13.8583,,C 223 | 1113,3,"Reynolds, Mr. Harold J",male,21,0,0,342684,8.05,,S 224 | 1114,2,"Cook, Mrs. (Selena Rogers)",female,22,0,0,W./C. 14266,10.5,F33,S 225 | 1115,3,"Karlsson, Mr. Einar Gervasius",male,21,0,0,350053,7.7958,,S 226 | 1116,1,"Candee, Mrs. Edward (Helen Churchill Hungerford)",female,53,0,0,PC 17606,27.4458,,C 227 | 1117,3,"Moubarek, Mrs. George (Omine Amenia"" Alexander)""",female,,0,2,2661,15.2458,,C 228 | 1118,3,"Asplund, Mr. Johan Charles",male,23,0,0,350054,7.7958,,S 229 | 1119,3,"McNeill, Miss. Bridget",female,,0,0,370368,7.75,,Q 230 | 1120,3,"Everett, Mr. Thomas James",male,40.5,0,0,C.A. 6212,15.1,,S 231 | 1121,2,"Hocking, Mr. Samuel James Metcalfe",male,36,0,0,242963,13,,S 232 | 1122,2,"Sweet, Mr. George Frederick",male,14,0,0,220845,65,,S 233 | 1123,1,"Willard, Miss. Constance",female,21,0,0,113795,26.55,,S 234 | 1124,3,"Wiklund, Mr. Karl Johan",male,21,1,0,3101266,6.4958,,S 235 | 1125,3,"Linehan, Mr. Michael",male,,0,0,330971,7.8792,,Q 236 | 1126,1,"Cumings, Mr. John Bradley",male,39,1,0,PC 17599,71.2833,C85,C 237 | 1127,3,"Vendel, Mr. Olof Edvin",male,20,0,0,350416,7.8542,,S 238 | 1128,1,"Warren, Mr. Frank Manley",male,64,1,0,110813,75.25,D37,C 239 | 1129,3,"Baccos, Mr. Raffull",male,20,0,0,2679,7.225,,C 240 | 1130,2,"Hiltunen, Miss. Marta",female,18,1,1,250650,13,,S 241 | 1131,1,"Douglas, Mrs. Walter Donald (Mahala Dutton)",female,48,1,0,PC 17761,106.425,C86,C 242 | 1132,1,"Lindstrom, Mrs. Carl Johan (Sigrid Posse)",female,55,0,0,112377,27.7208,,C 243 | 1133,2,"Christy, Mrs. (Alice Frances)",female,45,0,2,237789,30,,S 244 | 1134,1,"Spedden, Mr. Frederic Oakley",male,45,1,1,16966,134.5,E34,C 245 | 1135,3,"Hyman, Mr. Abraham",male,,0,0,3470,7.8875,,S 246 | 1136,3,"Johnston, Master. William Arthur Willie""""",male,,1,2,W./C. 6607,23.45,,S 247 | 1137,1,"Kenyon, Mr. Frederick R",male,41,1,0,17464,51.8625,D21,S 248 | 1138,2,"Karnes, Mrs. J Frank (Claire Bennett)",female,22,0,0,F.C.C. 13534,21,,S 249 | 1139,2,"Drew, Mr. James Vivian",male,42,1,1,28220,32.5,,S 250 | 1140,2,"Hold, Mrs. Stephen (Annie Margaret Hill)",female,29,1,0,26707,26,,S 251 | 1141,3,"Khalil, Mrs. Betros (Zahie Maria"" Elias)""",female,,1,0,2660,14.4542,,C 252 | 1142,2,"West, Miss. Barbara J",female,0.92,1,2,C.A. 34651,27.75,,S 253 | 1143,3,"Abrahamsson, Mr. Abraham August Johannes",male,20,0,0,SOTON/O2 3101284,7.925,,S 254 | 1144,1,"Clark, Mr. Walter Miller",male,27,1,0,13508,136.7792,C89,C 255 | 1145,3,"Salander, Mr. Karl Johan",male,24,0,0,7266,9.325,,S 256 | 1146,3,"Wenzel, Mr. Linhart",male,32.5,0,0,345775,9.5,,S 257 | 1147,3,"MacKay, Mr. George William",male,,0,0,C.A. 42795,7.55,,S 258 | 1148,3,"Mahon, Mr. John",male,,0,0,AQ/4 3130,7.75,,Q 259 | 1149,3,"Niklasson, Mr. Samuel",male,28,0,0,363611,8.05,,S 260 | 1150,2,"Bentham, Miss. Lilian W",female,19,0,0,28404,13,,S 261 | 1151,3,"Midtsjo, Mr. Karl Albert",male,21,0,0,345501,7.775,,S 262 | 1152,3,"de Messemaeker, Mr. Guillaume Joseph",male,36.5,1,0,345572,17.4,,S 263 | 1153,3,"Nilsson, Mr. August Ferdinand",male,21,0,0,350410,7.8542,,S 264 | 1154,2,"Wells, Mrs. Arthur Henry (Addie"" Dart Trevaskis)""",female,29,0,2,29103,23,,S 265 | 1155,3,"Klasen, Miss. Gertrud Emilia",female,1,1,1,350405,12.1833,,S 266 | 1156,2,"Portaluppi, Mr. Emilio Ilario Giuseppe",male,30,0,0,C.A. 34644,12.7375,,C 267 | 1157,3,"Lyntakoff, Mr. Stanko",male,,0,0,349235,7.8958,,S 268 | 1158,1,"Chisholm, Mr. Roderick Robert Crispin",male,,0,0,112051,0,,S 269 | 1159,3,"Warren, Mr. Charles William",male,,0,0,C.A. 49867,7.55,,S 270 | 1160,3,"Howard, Miss. May Elizabeth",female,,0,0,A. 2. 39186,8.05,,S 271 | 1161,3,"Pokrnic, Mr. Mate",male,17,0,0,315095,8.6625,,S 272 | 1162,1,"McCaffry, Mr. Thomas Francis",male,46,0,0,13050,75.2417,C6,C 273 | 1163,3,"Fox, Mr. Patrick",male,,0,0,368573,7.75,,Q 274 | 1164,1,"Clark, Mrs. Walter Miller (Virginia McDowell)",female,26,1,0,13508,136.7792,C89,C 275 | 1165,3,"Lennon, Miss. Mary",female,,1,0,370371,15.5,,Q 276 | 1166,3,"Saade, Mr. Jean Nassr",male,,0,0,2676,7.225,,C 277 | 1167,2,"Bryhl, Miss. Dagmar Jenny Ingeborg ",female,20,1,0,236853,26,,S 278 | 1168,2,"Parker, Mr. Clifford Richard",male,28,0,0,SC 14888,10.5,,S 279 | 1169,2,"Faunthorpe, Mr. Harry",male,40,1,0,2926,26,,S 280 | 1170,2,"Ware, Mr. John James",male,30,1,0,CA 31352,21,,S 281 | 1171,2,"Oxenham, Mr. Percy Thomas",male,22,0,0,W./C. 14260,10.5,,S 282 | 1172,3,"Oreskovic, Miss. Jelka",female,23,0,0,315085,8.6625,,S 283 | 1173,3,"Peacock, Master. Alfred Edward",male,0.75,1,1,SOTON/O.Q. 3101315,13.775,,S 284 | 1174,3,"Fleming, Miss. Honora",female,,0,0,364859,7.75,,Q 285 | 1175,3,"Touma, Miss. Maria Youssef",female,9,1,1,2650,15.2458,,C 286 | 1176,3,"Rosblom, Miss. Salli Helena",female,2,1,1,370129,20.2125,,S 287 | 1177,3,"Dennis, Mr. William",male,36,0,0,A/5 21175,7.25,,S 288 | 1178,3,"Franklin, Mr. Charles (Charles Fardon)",male,,0,0,SOTON/O.Q. 3101314,7.25,,S 289 | 1179,1,"Snyder, Mr. John Pillsbury",male,24,1,0,21228,82.2667,B45,S 290 | 1180,3,"Mardirosian, Mr. Sarkis",male,,0,0,2655,7.2292,F E46,C 291 | 1181,3,"Ford, Mr. Arthur",male,,0,0,A/5 1478,8.05,,S 292 | 1182,1,"Rheims, Mr. George Alexander Lucien",male,,0,0,PC 17607,39.6,,S 293 | 1183,3,"Daly, Miss. Margaret Marcella Maggie""""",female,30,0,0,382650,6.95,,Q 294 | 1184,3,"Nasr, Mr. Mustafa",male,,0,0,2652,7.2292,,C 295 | 1185,1,"Dodge, Dr. Washington",male,53,1,1,33638,81.8583,A34,S 296 | 1186,3,"Wittevrongel, Mr. Camille",male,36,0,0,345771,9.5,,S 297 | 1187,3,"Angheloff, Mr. Minko",male,26,0,0,349202,7.8958,,S 298 | 1188,2,"Laroche, Miss. Louise",female,1,1,2,SC/Paris 2123,41.5792,,C 299 | 1189,3,"Samaan, Mr. Hanna",male,,2,0,2662,21.6792,,C 300 | 1190,1,"Loring, Mr. Joseph Holland",male,30,0,0,113801,45.5,,S 301 | 1191,3,"Johansson, Mr. Nils",male,29,0,0,347467,7.8542,,S 302 | 1192,3,"Olsson, Mr. Oscar Wilhelm",male,32,0,0,347079,7.775,,S 303 | 1193,2,"Malachard, Mr. Noel",male,,0,0,237735,15.0458,D,C 304 | 1194,2,"Phillips, Mr. Escott Robert",male,43,0,1,S.O./P.P. 2,21,,S 305 | 1195,3,"Pokrnic, Mr. Tome",male,24,0,0,315092,8.6625,,S 306 | 1196,3,"McCarthy, Miss. Catherine Katie""""",female,,0,0,383123,7.75,,Q 307 | 1197,1,"Crosby, Mrs. Edward Gifford (Catherine Elizabeth Halstead)",female,64,1,1,112901,26.55,B26,S 308 | 1198,1,"Allison, Mr. Hudson Joshua Creighton",male,30,1,2,113781,151.55,C22 C26,S 309 | 1199,3,"Aks, Master. Philip Frank",male,0.83,0,1,392091,9.35,,S 310 | 1200,1,"Hays, Mr. Charles Melville",male,55,1,1,12749,93.5,B69,S 311 | 1201,3,"Hansen, Mrs. Claus Peter (Jennie L Howard)",female,45,1,0,350026,14.1083,,S 312 | 1202,3,"Cacic, Mr. Jego Grga",male,18,0,0,315091,8.6625,,S 313 | 1203,3,"Vartanian, Mr. David",male,22,0,0,2658,7.225,,C 314 | 1204,3,"Sadowitz, Mr. Harry",male,,0,0,LP 1588,7.575,,S 315 | 1205,3,"Carr, Miss. Jeannie",female,37,0,0,368364,7.75,,Q 316 | 1206,1,"White, Mrs. John Stuart (Ella Holmes)",female,55,0,0,PC 17760,135.6333,C32,C 317 | 1207,3,"Hagardon, Miss. Kate",female,17,0,0,AQ/3. 30631,7.7333,,Q 318 | 1208,1,"Spencer, Mr. William Augustus",male,57,1,0,PC 17569,146.5208,B78,C 319 | 1209,2,"Rogers, Mr. Reginald Harry",male,19,0,0,28004,10.5,,S 320 | 1210,3,"Jonsson, Mr. Nils Hilding",male,27,0,0,350408,7.8542,,S 321 | 1211,2,"Jefferys, Mr. Ernest Wilfred",male,22,2,0,C.A. 31029,31.5,,S 322 | 1212,3,"Andersson, Mr. Johan Samuel",male,26,0,0,347075,7.775,,S 323 | 1213,3,"Krekorian, Mr. Neshan",male,25,0,0,2654,7.2292,F E57,C 324 | 1214,2,"Nesson, Mr. Israel",male,26,0,0,244368,13,F2,S 325 | 1215,1,"Rowe, Mr. Alfred G",male,33,0,0,113790,26.55,,S 326 | 1216,1,"Kreuchen, Miss. Emilie",female,39,0,0,24160,211.3375,,S 327 | 1217,3,"Assam, Mr. Ali",male,23,0,0,SOTON/O.Q. 3101309,7.05,,S 328 | 1218,2,"Becker, Miss. Ruth Elizabeth",female,12,2,1,230136,39,F4,S 329 | 1219,1,"Rosenshine, Mr. George (Mr George Thorne"")""",male,46,0,0,PC 17585,79.2,,C 330 | 1220,2,"Clarke, Mr. Charles Valentine",male,29,1,0,2003,26,,S 331 | 1221,2,"Enander, Mr. Ingvar",male,21,0,0,236854,13,,S 332 | 1222,2,"Davies, Mrs. John Morgan (Elizabeth Agnes Mary White) ",female,48,0,2,C.A. 33112,36.75,,S 333 | 1223,1,"Dulles, Mr. William Crothers",male,39,0,0,PC 17580,29.7,A18,C 334 | 1224,3,"Thomas, Mr. Tannous",male,,0,0,2684,7.225,,C 335 | 1225,3,"Nakid, Mrs. Said (Waika Mary"" Mowad)""",female,19,1,1,2653,15.7417,,C 336 | 1226,3,"Cor, Mr. Ivan",male,27,0,0,349229,7.8958,,S 337 | 1227,1,"Maguire, Mr. John Edward",male,30,0,0,110469,26,C106,S 338 | 1228,2,"de Brito, Mr. Jose Joaquim",male,32,0,0,244360,13,,S 339 | 1229,3,"Elias, Mr. Joseph",male,39,0,2,2675,7.2292,,C 340 | 1230,2,"Denbury, Mr. Herbert",male,25,0,0,C.A. 31029,31.5,,S 341 | 1231,3,"Betros, Master. Seman",male,,0,0,2622,7.2292,,C 342 | 1232,2,"Fillbrook, Mr. Joseph Charles",male,18,0,0,C.A. 15185,10.5,,S 343 | 1233,3,"Lundstrom, Mr. Thure Edvin",male,32,0,0,350403,7.5792,,S 344 | 1234,3,"Sage, Mr. John George",male,,1,9,CA. 2343,69.55,,S 345 | 1235,1,"Cardeza, Mrs. James Warburton Martinez (Charlotte Wardle Drake)",female,58,0,1,PC 17755,512.3292,B51 B53 B55,C 346 | 1236,3,"van Billiard, Master. James William",male,,1,1,A/5. 851,14.5,,S 347 | 1237,3,"Abelseth, Miss. Karen Marie",female,16,0,0,348125,7.65,,S 348 | 1238,2,"Botsford, Mr. William Hull",male,26,0,0,237670,13,,S 349 | 1239,3,"Whabee, Mrs. George Joseph (Shawneene Abi-Saab)",female,38,0,0,2688,7.2292,,C 350 | 1240,2,"Giles, Mr. Ralph",male,24,0,0,248726,13.5,,S 351 | 1241,2,"Walcroft, Miss. Nellie",female,31,0,0,F.C.C. 13528,21,,S 352 | 1242,1,"Greenfield, Mrs. Leo David (Blanche Strouse)",female,45,0,1,PC 17759,63.3583,D10 D12,C 353 | 1243,2,"Stokes, Mr. Philip Joseph",male,25,0,0,F.C.C. 13540,10.5,,S 354 | 1244,2,"Dibden, Mr. William",male,18,0,0,S.O.C. 14879,73.5,,S 355 | 1245,2,"Herman, Mr. Samuel",male,49,1,2,220845,65,,S 356 | 1246,3,"Dean, Miss. Elizabeth Gladys Millvina""""",female,0.17,1,2,C.A. 2315,20.575,,S 357 | 1247,1,"Julian, Mr. Henry Forbes",male,50,0,0,113044,26,E60,S 358 | 1248,1,"Brown, Mrs. John Murray (Caroline Lane Lamson)",female,59,2,0,11769,51.4792,C101,S 359 | 1249,3,"Lockyer, Mr. Edward",male,,0,0,1222,7.8792,,S 360 | 1250,3,"O'Keefe, Mr. Patrick",male,,0,0,368402,7.75,,Q 361 | 1251,3,"Lindell, Mrs. Edvard Bengtsson (Elin Gerda Persson)",female,30,1,0,349910,15.55,,S 362 | 1252,3,"Sage, Master. William Henry",male,14.5,8,2,CA. 2343,69.55,,S 363 | 1253,2,"Mallet, Mrs. Albert (Antoinette Magnin)",female,24,1,1,S.C./PARIS 2079,37.0042,,C 364 | 1254,2,"Ware, Mrs. John James (Florence Louise Long)",female,31,0,0,CA 31352,21,,S 365 | 1255,3,"Strilic, Mr. Ivan",male,27,0,0,315083,8.6625,,S 366 | 1256,1,"Harder, Mrs. George Achilles (Dorothy Annan)",female,25,1,0,11765,55.4417,E50,C 367 | 1257,3,"Sage, Mrs. John (Annie Bullen)",female,,1,9,CA. 2343,69.55,,S 368 | 1258,3,"Caram, Mr. Joseph",male,,1,0,2689,14.4583,,C 369 | 1259,3,"Riihivouri, Miss. Susanna Juhantytar Sanni""""",female,22,0,0,3101295,39.6875,,S 370 | 1260,1,"Gibson, Mrs. Leonard (Pauline C Boeson)",female,45,0,1,112378,59.4,,C 371 | 1261,2,"Pallas y Castello, Mr. Emilio",male,29,0,0,SC/PARIS 2147,13.8583,,C 372 | 1262,2,"Giles, Mr. Edgar",male,21,1,0,28133,11.5,,S 373 | 1263,1,"Wilson, Miss. Helen Alice",female,31,0,0,16966,134.5,E39 E41,C 374 | 1264,1,"Ismay, Mr. Joseph Bruce",male,49,0,0,112058,0,B52 B54 B56,S 375 | 1265,2,"Harbeck, Mr. William H",male,44,0,0,248746,13,,S 376 | 1266,1,"Dodge, Mrs. Washington (Ruth Vidaver)",female,54,1,1,33638,81.8583,A34,S 377 | 1267,1,"Bowen, Miss. Grace Scott",female,45,0,0,PC 17608,262.375,,C 378 | 1268,3,"Kink, Miss. Maria",female,22,2,0,315152,8.6625,,S 379 | 1269,2,"Cotterill, Mr. Henry Harry""""",male,21,0,0,29107,11.5,,S 380 | 1270,1,"Hipkins, Mr. William Edward",male,55,0,0,680,50,C39,S 381 | 1271,3,"Asplund, Master. Carl Edgar",male,5,4,2,347077,31.3875,,S 382 | 1272,3,"O'Connor, Mr. Patrick",male,,0,0,366713,7.75,,Q 383 | 1273,3,"Foley, Mr. Joseph",male,26,0,0,330910,7.8792,,Q 384 | 1274,3,"Risien, Mrs. Samuel (Emma)",female,,0,0,364498,14.5,,S 385 | 1275,3,"McNamee, Mrs. Neal (Eileen O'Leary)",female,19,1,0,376566,16.1,,S 386 | 1276,2,"Wheeler, Mr. Edwin Frederick""""",male,,0,0,SC/PARIS 2159,12.875,,S 387 | 1277,2,"Herman, Miss. Kate",female,24,1,2,220845,65,,S 388 | 1278,3,"Aronsson, Mr. Ernst Axel Algot",male,24,0,0,349911,7.775,,S 389 | 1279,2,"Ashby, Mr. John",male,57,0,0,244346,13,,S 390 | 1280,3,"Canavan, Mr. Patrick",male,21,0,0,364858,7.75,,Q 391 | 1281,3,"Palsson, Master. Paul Folke",male,6,3,1,349909,21.075,,S 392 | 1282,1,"Payne, Mr. Vivian Ponsonby",male,23,0,0,12749,93.5,B24,S 393 | 1283,1,"Lines, Mrs. Ernest H (Elizabeth Lindsey James)",female,51,0,1,PC 17592,39.4,D28,S 394 | 1284,3,"Abbott, Master. Eugene Joseph",male,13,0,2,C.A. 2673,20.25,,S 395 | 1285,2,"Gilbert, Mr. William",male,47,0,0,C.A. 30769,10.5,,S 396 | 1286,3,"Kink-Heilmann, Mr. Anton",male,29,3,1,315153,22.025,,S 397 | 1287,1,"Smith, Mrs. Lucien Philip (Mary Eloise Hughes)",female,18,1,0,13695,60,C31,S 398 | 1288,3,"Colbert, Mr. Patrick",male,24,0,0,371109,7.25,,Q 399 | 1289,1,"Frolicher-Stehli, Mrs. Maxmillian (Margaretha Emerentia Stehli)",female,48,1,1,13567,79.2,B41,C 400 | 1290,3,"Larsson-Rondberg, Mr. Edvard A",male,22,0,0,347065,7.775,,S 401 | 1291,3,"Conlon, Mr. Thomas Henry",male,31,0,0,21332,7.7333,,Q 402 | 1292,1,"Bonnell, Miss. Caroline",female,30,0,0,36928,164.8667,C7,S 403 | 1293,2,"Gale, Mr. Harry",male,38,1,0,28664,21,,S 404 | 1294,1,"Gibson, Miss. Dorothy Winifred",female,22,0,1,112378,59.4,,C 405 | 1295,1,"Carrau, Mr. Jose Pedro",male,17,0,0,113059,47.1,,S 406 | 1296,1,"Frauenthal, Mr. Isaac Gerald",male,43,1,0,17765,27.7208,D40,C 407 | 1297,2,"Nourney, Mr. Alfred (Baron von Drachstedt"")""",male,20,0,0,SC/PARIS 2166,13.8625,D38,C 408 | 1298,2,"Ware, Mr. William Jeffery",male,23,1,0,28666,10.5,,S 409 | 1299,1,"Widener, Mr. George Dunton",male,50,1,1,113503,211.5,C80,C 410 | 1300,3,"Riordan, Miss. Johanna Hannah""""",female,,0,0,334915,7.7208,,Q 411 | 1301,3,"Peacock, Miss. Treasteall",female,3,1,1,SOTON/O.Q. 3101315,13.775,,S 412 | 1302,3,"Naughton, Miss. Hannah",female,,0,0,365237,7.75,,Q 413 | 1303,1,"Minahan, Mrs. William Edward (Lillian E Thorpe)",female,37,1,0,19928,90,C78,Q 414 | 1304,3,"Henriksson, Miss. Jenny Lovisa",female,28,0,0,347086,7.775,,S 415 | 1305,3,"Spector, Mr. Woolf",male,,0,0,A.5. 3236,8.05,,S 416 | 1306,1,"Oliva y Ocana, Dona. Fermina",female,39,0,0,PC 17758,108.9,C105,C 417 | 1307,3,"Saether, Mr. Simon Sivertsen",male,38.5,0,0,SOTON/O.Q. 3101262,7.25,,S 418 | 1308,3,"Ware, Mr. Frederick",male,,0,0,359309,8.05,,S 419 | 1309,3,"Peter, Master. Michael J",male,,1,1,2668,22.3583,,C 420 | -------------------------------------------------------------------------------- /class08/kNN.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "kNN.ipynb", 7 | "provenance": [], 8 | "authorship_tag": "ABX9TyM4PxjbZLWM6YzLKCZfzD4b", 9 | "include_colab_link": true 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "language_info": { 16 | "name": "python" 17 | } 18 | }, 19 | "cells": [ 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "id": "view-in-github", 24 | "colab_type": "text" 25 | }, 26 | "source": [ 27 | "\"Open" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "source": [ 33 | "# **KNN**" 34 | ], 35 | "metadata": { 36 | "id": "SQ-0ZwdDtdbe" 37 | } 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 1, 42 | "metadata": { 43 | "id": "qJAYDi5jN31R" 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "import numpy as np\n", 48 | "import pandas as pd\n", 49 | "import matplotlib.pyplot as plt" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "source": [ 55 | "## **讀取資料**" 56 | ], 57 | "metadata": { 58 | "id": "Pz1UcHKGtZzc" 59 | } 60 | }, 61 | { 62 | "cell_type": "code", 63 | "source": [ 64 | "data = pd.read_csv(\"https://raw.githubusercontent.com/ThousandAI/pycs4001/main/class07/advertising.csv\")\n", 65 | "data.head()" 66 | ], 67 | "metadata": { 68 | "colab": { 69 | "base_uri": "https://localhost:8080/", 70 | "height": 337 71 | }, 72 | "id": "J2rfAEUeOL_M", 73 | "outputId": "50d9697f-46b3-4ca5-a5b3-239fbb2d53ff" 74 | }, 75 | "execution_count": 2, 76 | "outputs": [ 77 | { 78 | "output_type": "execute_result", 79 | "data": { 80 | "text/plain": [ 81 | " Daily Time Spent on Site Age Area Income Daily Internet Usage \\\n", 82 | "0 68.95 35 61833.90 256.09 \n", 83 | "1 80.23 31 68441.85 193.77 \n", 84 | "2 69.47 26 59785.94 236.50 \n", 85 | "3 74.15 29 54806.18 245.89 \n", 86 | "4 68.37 35 73889.99 225.58 \n", 87 | "\n", 88 | " Ad Topic Line City Male Country \\\n", 89 | "0 Cloned 5thgeneration orchestration Wrightburgh 0 Tunisia \n", 90 | "1 Monitored national standardization West Jodi 1 Nauru \n", 91 | "2 Organic bottom-line service-desk Davidton 0 San Marino \n", 92 | "3 Triple-buffered reciprocal time-frame West Terrifurt 1 Italy \n", 93 | "4 Robust logistical utilization South Manuel 0 Iceland \n", 94 | "\n", 95 | " Timestamp Clicked on Ad \n", 96 | "0 2016-03-27 00:53:11 0 \n", 97 | "1 2016-04-04 01:39:02 0 \n", 98 | "2 2016-03-13 20:35:42 0 \n", 99 | "3 2016-01-10 02:31:19 0 \n", 100 | "4 2016-06-03 03:36:18 0 " 101 | ], 102 | "text/html": [ 103 | "\n", 104 | "
\n", 105 | "
\n", 106 | "
\n", 107 | "\n", 120 | "\n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | "
Daily Time Spent on SiteAgeArea IncomeDaily Internet UsageAd Topic LineCityMaleCountryTimestampClicked on Ad
068.953561833.90256.09Cloned 5thgeneration orchestrationWrightburgh0Tunisia2016-03-27 00:53:110
180.233168441.85193.77Monitored national standardizationWest Jodi1Nauru2016-04-04 01:39:020
269.472659785.94236.50Organic bottom-line service-deskDavidton0San Marino2016-03-13 20:35:420
374.152954806.18245.89Triple-buffered reciprocal time-frameWest Terrifurt1Italy2016-01-10 02:31:190
468.373573889.99225.58Robust logistical utilizationSouth Manuel0Iceland2016-06-03 03:36:180
\n", 204 | "
\n", 205 | " \n", 215 | " \n", 216 | " \n", 253 | "\n", 254 | " \n", 278 | "
\n", 279 | "
\n", 280 | " " 281 | ] 282 | }, 283 | "metadata": {}, 284 | "execution_count": 2 285 | } 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "source": [ 291 | "from sklearn.model_selection import train_test_split\n", 292 | "X = np.array(data[[\"Daily Time Spent on Site\", \"Age\", \"Area Income\", \"Daily Internet Usage\", \"Male\"]])\n", 293 | "Y = np.array(data[\"Clicked on Ad\"])\n", 294 | "train_x, test_x, train_y, test_y = train_test_split(X, Y, test_size=0.2, random_state=10)" 295 | ], 296 | "metadata": { 297 | "id": "UjSjvoCXtiZu" 298 | }, 299 | "execution_count": 3, 300 | "outputs": [] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "source": [ 305 | "## **標準化數據**" 306 | ], 307 | "metadata": { 308 | "id": "BRoGGqmqtoUv" 309 | } 310 | }, 311 | { 312 | "cell_type": "code", 313 | "source": [ 314 | "from sklearn.preprocessing import StandardScaler\n", 315 | "scaler_x = StandardScaler()\n", 316 | "sc_train_x = scaler_x.fit_transform(train_x)" 317 | ], 318 | "metadata": { 319 | "id": "gMAPdlYwtmCh" 320 | }, 321 | "execution_count": 4, 322 | "outputs": [] 323 | }, 324 | { 325 | "cell_type": "markdown", 326 | "source": [ 327 | "## **搭建模型**" 328 | ], 329 | "metadata": { 330 | "id": "a99J5ZR9tuKC" 331 | } 332 | }, 333 | { 334 | "cell_type": "code", 335 | "source": [ 336 | "from sklearn.neighbors import KNeighborsClassifier\n", 337 | "knn = KNeighborsClassifier(n_neighbors=5)" 338 | ], 339 | "metadata": { 340 | "id": "BClC5BWMOOTX" 341 | }, 342 | "execution_count": 5, 343 | "outputs": [] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "source": [ 348 | "## **訓練模型**" 349 | ], 350 | "metadata": { 351 | "id": "Ps6O4kRit3Ab" 352 | } 353 | }, 354 | { 355 | "cell_type": "code", 356 | "source": [ 357 | "knn.fit(sc_train_x,train_y)" 358 | ], 359 | "metadata": { 360 | "colab": { 361 | "base_uri": "https://localhost:8080/" 362 | }, 363 | "id": "cG2cm3ILO8j5", 364 | "outputId": "be77f5fd-1fb3-413d-9b84-9abd76107c98" 365 | }, 366 | "execution_count": 6, 367 | "outputs": [ 368 | { 369 | "output_type": "execute_result", 370 | "data": { 371 | "text/plain": [ 372 | "KNeighborsClassifier()" 373 | ] 374 | }, 375 | "metadata": {}, 376 | "execution_count": 6 377 | } 378 | ] 379 | }, 380 | { 381 | "cell_type": "markdown", 382 | "source": [ 383 | "## **評估模型**" 384 | ], 385 | "metadata": { 386 | "id": "cLriWeKst-EA" 387 | } 388 | }, 389 | { 390 | "cell_type": "code", 391 | "source": [ 392 | "from sklearn.metrics import confusion_matrix\n", 393 | "sc_test_x = scaler_x.transform(test_x)\n", 394 | "y_hat = knn.predict(sc_test_x)\n", 395 | "print(confusion_matrix(test_y, y_hat))\n", 396 | "print(knn.score(sc_test_x, test_y))" 397 | ], 398 | "metadata": { 399 | "colab": { 400 | "base_uri": "https://localhost:8080/" 401 | }, 402 | "id": "wWmQ5_KfPKB2", 403 | "outputId": "c4e8a1e4-4270-497e-c895-83b41b920d1d" 404 | }, 405 | "execution_count": 7, 406 | "outputs": [ 407 | { 408 | "output_type": "stream", 409 | "name": "stdout", 410 | "text": [ 411 | "[[93 3]\n", 412 | " [ 9 95]]\n", 413 | "0.94\n" 414 | ] 415 | } 416 | ] 417 | }, 418 | { 419 | "cell_type": "code", 420 | "source": [ 421 | "train_score = []\n", 422 | "test_score = []\n", 423 | "for i in range(1,21):\n", 424 | " knn = KNeighborsClassifier(n_neighbors=i)\n", 425 | " knn.fit(sc_train_x, train_y)\n", 426 | " train_score.append(knn.score(sc_train_x, train_y))\n", 427 | " test_score.append(knn.score(sc_test_x, test_y))\n", 428 | "\n", 429 | "print(f\"train_score: {train_score}\")\n", 430 | "print(f\"test_score: {test_score}\")\n", 431 | "\n", 432 | "x_axis = np.arange(1,21,1)\n", 433 | "plt.scatter(x_axis, np.array(train_score), color=\"r\", label=\"train\")\n", 434 | "plt.scatter(x_axis, np.array(test_score), color=\"b\", label=\"test\")\n", 435 | "plt.title(\"KNN score\")\n", 436 | "plt.xlabel(\"N neighbors\")\n", 437 | "plt.ylabel(\"Accuracy\")\n", 438 | "plt.legend()\n", 439 | "plt.show()" 440 | ], 441 | "metadata": { 442 | "colab": { 443 | "base_uri": "https://localhost:8080/", 444 | "height": 351 445 | }, 446 | "id": "1cLrVMGAuESs", 447 | "outputId": "86e0e72c-a2dc-44e2-9b38-2d395a0fa63e" 448 | }, 449 | "execution_count": 8, 450 | "outputs": [ 451 | { 452 | "output_type": "stream", 453 | "name": "stdout", 454 | "text": [ 455 | "train_score: [1.0, 0.97, 0.97375, 0.97, 0.97125, 0.96625, 0.96875, 0.9675, 0.96875, 0.965, 0.9675, 0.96625, 0.96875, 0.96625, 0.9675, 0.965, 0.96625, 0.96625, 0.9675, 0.9675]\n", 456 | "test_score: [0.93, 0.955, 0.955, 0.95, 0.94, 0.945, 0.935, 0.935, 0.935, 0.945, 0.945, 0.945, 0.945, 0.95, 0.945, 0.945, 0.94, 0.95, 0.945, 0.945]\n" 457 | ] 458 | }, 459 | { 460 | "output_type": "display_data", 461 | "data": { 462 | "text/plain": [ 463 | "
" 464 | ], 465 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzA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wL4B0lD0/JVXYlH0l8reZ7Bf0u6UdJFJV//ybT9byQdV1I+Jl3eckmXlizvLyUtTaevpGWt6fdfT3IX7xhJP0rrPCKp4vqZ9WSXogMwK8i1wBJJ3+yh3vuAE0jG4l8m6TrgPcCngQ9FxFuSvgdMBa7vaiTpaODjwOHAMJJBBu8v+d5dImKikoflXEoytAMk4/kcCmwGFkv6GcmdtF8APkByp/uvJf0X8AJwMHB+RCySNAE4ICIOTWOoeKrLrCdOENaQIuKl9C/vPwdeq1D1ZxHxBvCGpGdJhlU+CZhA8gMOsDs7Dpb2IeDfI+J14HVJ/9Ftftega/cDrSXld0TERgBJ/8rvhlq4NSJeLSk/jmSYitWRPLcDkgfCHCTpu8DPgAU9bgizCpwgrJFdTfKX/T9VqPNGyfutJP9nBPw4Ii6uYdld39v1nV26j33T01g4r26rGPGCpMNJHhTzZZKH3fxRDTFag3MfhDWsiHge+AnJAHK9cRfwCUnvhG3PB27pVucXwMckDU/H8v9old/9kfT7did5StgvgHuBsyQ1pSOHnp2WbSft+xgSEf8CfI3kUZpmO81HENboriIZIbZqEfGYpK+RPE1sCMlIoBcAq0vqLJY0j2QUzmdIRi99sYqvv49k7P9mYE5EdABI+lE6D5LROh9U8oSxUgcA/1RyNVMtRzhmHs3VLC+S9oyIVyQ1AfcA7ZE+X9hsIPARhFl+ZkkaBwwn6bNwcrABxUcQZmaWyZ3UZmaWyQnCzMwyOUGYmVkmJwgzM8vkBGFmZpn+B3r6nU7Np1ThAAAAAElFTkSuQmCC\n" 466 | }, 467 | "metadata": { 468 | "needs_background": "light" 469 | } 470 | } 471 | ] 472 | } 473 | ] 474 | } --------------------------------------------------------------------------------