본문 바로가기

728x90
반응형
SMALL

파이썬

(10)
[Python] 23. PCA(차원축소),T-SNE from sklearn.datasets import load_iris, load_wine from mpl_toolkits.mplot3d import Axes3D # 3차원 시각화 가능 import matplotlib.pyplot as plt import pandas as pd import numpy as np from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler from sklearn.pipeline import make_pipeline import matplotlib.pyplot as plt import seaborn as sns PCA(차원축소) 3차원까지 시각화 가능하나 4차원 이상은 무리 -> 차..
[Python] 15. 이미지분류 : mnist, MLPClassifier import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import mglearn from sklearn.model_selection import train_test_split from sklearn.neural_network import MLPClassifier import sklearn.metrics as m from sklearn.datasets import fetch_openml import warnings warnings.simplefilter('ignore') from sklearn.datasets import fetch_openml mnist = fetch_openml('mnist_..
[Python] 14. NN : XOR문제, MLPClassifier import numpy as np import pandas as pd import seaborn as sb import matplotlib.pyplot as plt import mglearn from sklearn.model_selection import train_test_split from sklearn.neural_network import MLPClassifier from sklearn.linear_model import LogisticRegression import warnings warnings.simplefilter('ignore') x_data = np.array( [[0,0],[0,1],[1,0],[1,1]]) y_data = np.array( [[0],[1],[1],[0]]) Logis..
[Python] 13. KNN분류 from sklearn.datasets import make_classification, load_iris from sklearn.cluster import KMeans import numpy as np import pandas as pd import seaborn as sb import matplotlib.pyplot as plt import mglearn from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import GridSearchCV import warnings warnings.simplefilter('igno..
[Python] 11. softmax import numpy as np def fn(x): print(x/x.sum()) a = np.array([2.0,1.0,0.1]) fn(a) [OUT]: [0.64516129 0.32258065 0.03225806] -> 전체 합에서 차지하는 비율 Softmax def softmax(x): e = np.exp(x) print(e) print( e/np.sum(e)) a = np.array([2.0,1.0,0.1]) softmax(a) [OUT]: [7.3890561 2.71828183 1.10517092] [0.65900114 0.24243297 0.09856589] -> e^x를 하여 확률이 높은곳에 가중치를 더 주는 형식 review - 다중분류 시 사용되는 softmax
[Python] 8. Sigmoid & Logistic import numpy as np import pandas as pd import matplotlib.pyplot as plt import math x = np.array( [1., 2., 3., 4., 5., 6.] ) y = np.array( [ 5., 7., 9., 11., 13., 15.] ) w = 0 b = 0 n = len(x) epochs = 5000 learning_rate = 0.01 for i in range(epochs): hy = w*x + b # w=2, b=3 cost = np.sum((hy-y)**2)/n gradientW = np.sum(2*x*(w*x+b-y))/n gradientB = np.sum(2*1*(w*x+b-y))/n w=w-learning_rate*gradie..
[Python] 3. 다중선형회귀 import pandas as pd import numpy as np import seaborn as sns from sklearn.datasets import load_boston, load_iris from sklearn.datasets import fetch_california_housing from sklearn.linear_model import LinearRegression,Ridge, SGDRegressor from sklearn.neural_network import MLPRegressor from sklearn.model_selection import train_test_split from sklearn.model_selection import GridSearchCV from sklear..
[Python] 11. pandas DataFrame 인덱싱(Indexing), 슬라이싱(Slicing) 예제 import pandas as pd import numpy as np data = {'eng':[10,30,50,70], 'kor':[20,40,60,80], 'math':[90,50,20,70]} df = pd.DataFrame(data, index=['a','b','c','d'] ) df # df['a'] # df['컬럼명'] df['eng'] [OUT] : a 10 b 30 c 50 d 70 Name: eng, dtype: int64 df[['eng','math']] df['eng']['a':'c'] [OUT] : a 10 b 30 c 50 Name: eng, dtype: int64 df[['eng']] # df[슬라이싱(row)] df[1:3] df df['b':'c'] iloc 인덱싱 슬라이싱(..
[Python] 05. pandas Series 추가,수정,삭제,검색,정렬 : loc(),drop(),append(),inplace=True예제 import pandas as pd import numpy as np data = {'aa':10,'bb':20,'cc':30,'dd':40, 'ee':50} sr = pd.Series(data, name='국어점수') sr [OUT] : aa 10 bb 20 cc 30 dd 40 ee 50 Name: 국어점수, dtype: int64 CRUD Create : 생성 Read : 읽기 Update : 갱신 Delete : 삭제 추가 & 수정 sr[0] = 100 # sr['aa'] = 100 # sr.loc['aa'] = 100 # sr.iloc[0] = 100 sr[1:3] = [1,2] # sr.iloc[1:3] = [1,2] # sr['bb':'cc'] = [1,2] # sr.loc['bb':'cc'..
[Python] 04. pandas Series 연산 : 산술관계논리(element wise),isin(),between()예제 import pandas as pd import numpy as np data = {'aa':10,'bb':20,'cc':30,'dd':40, 'ee':50} sr = pd.Series(data, name='국어점수') sr [OUT] : aa 10 bb 20 cc 30 dd 40 ee 50 Name: 국어점수, dtype: int64 sr.index [OUT] : Index(['aa', 'bb', 'cc', 'dd', 'ee'], dtype='object') 산술관계논리(element wise) sr+1 [OUT] : aa 11 bb 21 cc 31 dd 41 ee 51 Name: 국어점수, dtype: int64 sr*2 [OUT] : aa 20 bb 40 cc 60 dd 80 ee 100 Name:..

728x90
반응형
LIST