본문 바로가기

Study_note(zb_data)

(97)
스터디노트 (ML5) 📌 LabelEncoder df = pd.DataFrame({ 'A' : ['a', 'b', 'c', 'a', 'b'], 'B' : [1, 2, 3, 1, 0], }) df 📌 Label_encoder - fit -> transform from sklearn.preprocessing import LabelEncoder le = LabelEncoder() le.fit(df['A']) le.classes_ >>>> array(['a', 'b', 'c'], dtype=object) le.transform(df['A']) >>>> array([0, 1, 2, 0, 1]) le.fit_transform(df['A']) >>>> array([0, 1, 2, 0, 1]) le.inverse_transform(df['..
스터디노트 (ML4) 📌 LabelEncoder - Label을 붙여서 성별을 0과 1로 구분해보자 - 결측치는 notnull로 없애기 from sklearn.preprocessing import LabelEncoder le = LabelEncoder() le.fit(titanic['sex']) titanic['gender'] = le.transform(titanic['sex']) titanic.head() # 결측치 확인 titanic.info() >>>> RangeIndex: 1309 entries, 0 to 1308 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 pclass 1309 non-nu..
스터디노트 (ML3) 📌 Titanic_EDA 🔻 Titanic 생존율 확인하기 import pandas as pd titanic = pd.read_excel('../data/titanic.xls') titanic.head() import matplotlib.pyplot as plt import seaborn as sns # graph 2개 제작 f, ax = plt.subplots(1, 2, figsize = (16, 8)); # autopct = %표시 titanic['survived'].value_counts().plot.pie(ax=ax[0], autopct='%1.1f%%', shadow=True, explode = [0, 0.1]); ax[0].set_title('Pie plot - survived') ax[0]...
스터디 노트 (ML2) 📌 Scikit Learn Tree 🔻 Tree model visualization from sklearn.tree import plot_tree plt.figure(figsize=(12, 8)) plot_tree(iris_clf); 🔻 mlxtend.plotting - 제공한 데이터에 따라 경계선을 그려주는 함수 - feature가 적어서 사용함, feature가 많다면 사용하기 어려움 - 경계면이 과연 올바른 걸까 의심을 해봐야 한다. (복잡한 경계면은 모델의 성능을 결국 나쁘게 만든다.) from mlxtend.plotting import plot_decision_regions plt.figure(figsize=(14, 8)) plot_decision_regions(X=iris.data[:, 2:]..
스터디 노트 (ML) 📌 Machine Learning - 명시적으로 프로그래밍 하지 않아도 컴퓨터에 학습할 수 있는 능력을 부여하는 학문 - 주어진 데이터를 통해 규칙을 찾는 것이다. 📌 iris 데이터 셋 import 하기 - sklearn.datasets에서 iris 데이터를 import - 데이터 셋을 활용하여 setosa, versicolor, virginica를 구분해보자 from sklearn.datasets import load_iris iris = load_iris() iris.keys() >>>> dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename', 'data_module']) print(iris[..
책 데이터 사이언스 입문 3 (기술 통계량 ~ 표준편차) 📌 데이터를 값으로 요약하는 기술 통계량의 4가지 분류 🔻 중심 경향성 - 평균 값, 중앙 값, 최빈 값 등이 중심 경향성이다 - 어느 값이 빈번하게 나타나는 지, 정 가운데 값은 무엇인지 등을 나타내므로 일상에서도 많이 사용된다. 🔻산포도 - 데이터의 흩어져 있는 정도, 최댓값과 최솟값은 가장 큰 데이터와 가장 작은 데이터를 나타낸다. - 범위 내에서 데이터가 전반적으로 어떻게 흩어져 있는지, 얼마나 변화하는지 나타내기 위해 분산, 표준편차, 표준오차 등이 쓰인다. 🔻분포의 형태 - 중심 경향성과 산포도를 이용하면, 데이터 중심이 어디 인지와 각 데이터가 중심으로부터 어느 정도 흩어져 있는지 알 수 있다. - but 어느 쪽으로 쏠려 있는지는 확인이 어렵다. -- 이를 해결하기 위해 첨도와 왜도를 사용..
Python Selenium wait 📌 selenium 웹 크롤링 wait 옵션 - 웹 크롤링 시도할 때, time 옵션을 많이 사용했었는데 불필요한 시간 낭비를 줄여준 옵션 - 로딩이 끝나면 다음 동작을 바로 수행한다. from selenium.webdriver.support.ui import WebDriverWait as wait from selenium.webdriver.support import expected_conditions as EC 🔻 기존 코드 예시 driver.find_element(By.CSS_SELECTOR, f"#body1 > tr:nth-child({n}) > td.rlist > a").click() 🔻적용 코드 예시 - 최대 10초 기다리고, 로딩 후 바로 이어서 click을 수행한다. wait(driver, ..
SQL 위도 경도를 활용하여 거리 계산하기 📌 lng, lat 활용하기 - Table의 lng,lat 컬럼 확인하기 (decimal로 설정) 🧷 기준이 되는 장소 lat, lng 값 먼저 구하기 import googlemaps gmaps_key = "AIzaSyAtk5M33oHwG4_v6oKqTwVITZb30fRTGfQ" gmaps = googlemaps.Client(key=gmaps_key) # 미왕빌딩 주소 입력 tmp = gmaps.geocode("서울특별시 강남구 역삼동 826-21", language='ko') tmp tmp[0]['geometry']['location'] >>>> {'lat': 37.4955525, 'lng': 127.0292924} 🧷 코드 예시 - user_Lat ▶ 현재 위도 / user_Lng ▶ 현재 경도 - ..