목록Python/Machine Learning (13)
군침이 싹 도는 코딩
해당 데이터 프레임으로 구매여부를 예측하는 로지스틱 리그레이션을 만들어보자 로지스틱 리그레이션은 분류예측을 할때 사용되는 인공지능이다. 코딩방식은 리니어 리그레이션과 비슷하므로 다른점만 # 로 후술한다 1. nan 을 찾는다 df.isna().sum() >>> User ID 0 Gender 0 Age 0 EstimatedSalary 0 Purchased 0 dtype: int64 2.카테고리컬 데이터인 Purchased 데이터를 정렬해준다 df['Purchased'].unique() >>> array([0, 1], dtype=int64) 3.X,y를 나눈다 X = df.loc[:,'Age':'EstimatedSalary'] y = df['Purchased'] 4. 피쳐 스케일링을 한다 from sklea..
경력과 연봉이 있는 데이터 프레임을 리니어 리그레이션으로 모델링 해보자 1. nan 확인 df.isna().sum() >>> YearsExperience 0 Salary 0 dtype: int64 # nan 이 없는것을 확인했다 만약 있다면 값을 바꿔줘야한다 2. X와 y로 분리 X = df.loc[:,'YearsExperience'].to_frame() y = df['Salary'] # X는 경력 y는 연봉 3. 문자열 데이터를 숫자로 바꿔준다. # 위 데이터 프레임은 문자열이 없으므로 생략 4. 피쳐 스케일링 # 리니어 리그레이션은 자체적으로 피쳐스케일링을 해주기때문에 생략 5. Training / Test 셋으로 분리 from sklearn.model_selection import train_tes..
X >>> array([[1. , 0. , 0. , 0.73913043, 0.68571429], [0. , 0. , 1. , 0. , 0. ], [0. , 1. , 0. , 0.13043478, 0.17142857], [0. , 0. , 1. , 0.47826087, 0.37142857], [1. , 0. , 0. , 0.34782609, 0.28571429], [1. , 0. , 0. , 0.91304348, 0.88571429], [0. , 1. , 0. , 1. , 1. ], [1. , 0. , 0. , 0.43478261, 0.54285714]]) y >>> array([0, 1, 0, 0, 1, 1, 0, 1]) X와 y를 트레이닝용과 테스트용으로 나눠보겠다 from sklearn.model_s..
표준편차와 평균값으로 구하는 표준화(Standardisation)와 최대값 최소값으로 구하는 정규화(Normalisation)가있다 앞서 숫자로 모두 변환한 X,y를 가지고 피쳐 스케일링을 해보자 X array([[1.0e+00, 0.0e+00, 0.0e+00, 4.4e+01, 7.2e+04], [0.0e+00, 0.0e+00, 1.0e+00, 2.7e+01, 4.8e+04], [0.0e+00, 1.0e+00, 0.0e+00, 3.0e+01, 5.4e+04], [0.0e+00, 0.0e+00, 1.0e+00, 3.8e+01, 6.1e+04], [1.0e+00, 0.0e+00, 0.0e+00, 3.5e+01, 5.8e+04], [1.0e+00, 0.0e+00, 0.0e+00, 4.8e+01, 7.9e+04..
머신러닝으로 학습 시키기 위해서는 방정식에 대입이 되어야 하는데 방정식은 수학식이므로 데이터를 모두 숫자로 변환하여하 한다 따라서 문자열이 있다면 그것을 레이블 인코딩 또는 원핫 인코딩으로 숫자로 변환시켜주어야 한다. X를 Country, Age, Salary y를 Purchased라고 할때 카테고리컬 데이터인 Country, Purchased 가 문자열이므로 이것을 숫자로 바꿔보겠다 # X를 대문자로 쓰는 이유는 X는 2차원 행렬이여야 하고 y는 1차원이여서이다 먼저 유니크한값으로 출력 후 정렬을 해준다 sorted(X['Country'].unique()) >>> ['France', 'Germany', 'Spain'] 이후 앞에서부터 0 , 1 , 2 순으로 바꿔준다 이것을 레이블 인코딩이라고 한다 f..