일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- matplotlib
- IN
- sklearn
- 반복문
- analizer
- DataFrame
- data
- 분류 결과표
- 최댓값
- 덴드로그램
- hierarchical_clustering
- append()
- wcss
- count()
- Machine Learning
- DataAccess
- 최솟값
- function
- Python
- Dictionary
- len()
- elbow method
- del
- pandas
- dendrogram
- insert()
- list
- string
- nan
- numpy
- Today
- Total
목록Python (54)
개발공부

CountVectorizing 카운터 벡터라이징 여러개의 문자열데이터에서 각 단어별로 쪼개 해당 단어가 몇개씩 나왔는지 계산해 변환해준다, 예제 from sklearn.feature_extraction.text import CountVectorizer sample_data = ['This is the first document', 'I loved them', 'This document is the second document', 'I am loving you', 'And this is the third one'] vec = CountVectorizer() #fit_transform() 함수를 사용해 sample_data의 문자열의 모든 단어에 대해 # 각 리스트요소마다 각 단어에 대해 몇개씩 있는지를 학..

Grid Search 우리가 지정해준 잠재적 Parameter 들의 후보군 조합중에서 가장 최적의 조합을 찾아준다. sklearn 라이브러리에서 이를 제공해 주고 있어 쉽게 사용 가능하다. 예제 from sklearn.model_selection import GridSearchCV 우리는 Support Vector Machine 방식을 사용하겠다. # 파라미터의 조합으로 사용할 값들을 설정해준다. param_grid = { 'C' : [0.1, 1, 10, 100], 'kernel' : ['linear', 'rbf', 'poly'], 'gamma' : [1, 0.1, 0.01]} # estimator : classifier, regressor, pipeline 등 가능 # refit : True가 디폴트..

import pandas as pd Pandas에서 시간처리를 위한 datetime64를 생성하는 법은 datetimeIndex() , to_datetime() 2가지가 있다. pandas.datetimeIndex() >>> dates = ['2022-01-04', '2022-01-07', '2022-01-08', '2022-01-22'] >>> dates ['2022-01-04', '2022-01-07', '2022-01-08', '2022-01-22'] >>> pd.to_datetime(dates) DatetimeIndex(['2022-01-04', '2022-01-07', '2022-01-08', '2022-01-22'], dtype='datetime64[ns]', freq=None) pandas...

Numpy 시간 처리 방법 np.datetime64 기존의 파이썬 datetime 을 보강하기 위해, date 의 array 도 처리할 수 있게 numpy 에서 64-bit 로 처리하도록 라이브러리를 강화했다. 생성은 아래와 같이 할 수 있다. >>> import numpy as np >>> any_date = np.array('2022-05-11', dtype = np.datetime64) >>> any_date array('2022-05-11', dtype='datetime64[D]') 날짜 연산 넘파이의 datetime64는 날짜 연산이 단순하게 + - 연산자를 이용하면 돼서 간편하다. >>> any_date + 10 numpy.datetime64('2022-05-21') >>> any_date -..

import pandas as pd import numpy as np pivot_table() 피봇팅한다는 것은 즉 컬럼의 값을 열로 만드는것을 말한다. pivot_table()은 해당 컬럼의 데이터들에 중복데이터들이 있어도, 이를 하나의 인덱스로 합치고 수치 데이터들의 평균(디폴트)을 출력한다. 아래와 같은 데이터프레임으로 예를 들어보자. Name으로 피봇팅을 해도 되는지 (즉 카테고리컬 데이터가 맞는지) 확인을 해보자. >>> df['Name'].nunique() 12 df의 총 행은 17개인데 nunique()의 값은 12이기 때문에 Name은 카테고리컬 데이터이다. 평균값으로 피봇테이블 생성 그럼 Name을 기준으로 피봇테이블을 생성해보자. pd.pivot_table(df, index = ['Na..

1. 구글 클라우드의 MAPS API 페이지로 이동한다. https://cloud.google.com/maps-platform/?hl=ko Google Maps Platform - Location and Mapping Solutions Create real world and real time experiences for your customers with dynamic maps, routes & places APIs from Google Maps Platform’s location solutions. mapsplatform.google.com 2. 콘솔로 이동 => Geocoding API 선택 => 사용자인증정보 에서 API 키 생성 이제 받은 API KEY를 가지고 원하는 장소의 위치(위도, 경도) ..

import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sb 아래는 차량의 메이커, 모델, 년도, 분류, 연비 등등을 나타낸 데이터 프레임이다. 두 컬럼간의 관계를 표현하는 차트 1. matplotlib 의 scatter 사용 displ과 comb의 상관관계를 표현하라 plt.scatter(data = df, x = 'displ', y = 'comb') plt.title('Displ Vs Comb') plt.xlabel('Displacement (L)') plt.ylabel('Combined Fuel Etf (mpg)') plt.show() 2. seaborn 의 regplot 을 이용하는 방법 reg..

Matpotlib의 subplot을 사용하면 각각 다른 차트들을 행과 열에 맞춰서 배치할 수 있다. 아래는 포켓몬 세대와 종에 대한 정보가 담겨있는 데이터 프레임이다. speed 값의 구간에 따른 데이터의 갯수에 대한 히스토그램을 bins(구간)가 10과 20에 대해 그리면 아래와 같이 그릴 수 있다. import matplotlib as plt # 하나에 여러개의 plot을 그린다. plt.figure(figsize= (12, 5)) plt.subplot(1, 2, 1) # subplot(행, 열, 번호) plt.hist(data = df, x = 'speed', rwidth = 0.8, bins = 10) plt.subplot(1, 2, 2) plt.hist(data = df, x = 'speed',..

import matplotlib.pyplot as plt 가장 기본적인 Plot x 좌표의 데이터와, y좌표의 데이터를 가지고 만들수 있는 선형 그래프다. >>> x = np.arange(0, 9+1) >>> x array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> y = np.arange(0, 9+1) >>> y array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) plt.plot(x, y) plt.savefig('test1.jpg') plt.show() Bar Chart (ceaborn) import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sb 아래는 포켓몬 ..

데이터 프레임 붙이기 concat() 단순히 다른 데이터 프레임을 붙여서 합친다. import pandas as pd df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'], 'B': ['B0', 'B1', 'B2', 'B3'], 'C': ['C0', 'C1', 'C2', 'C3'], 'D': ['D0', 'D1', 'D2', 'D3']}, index=[0, 1, 2, 3]) df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'], 'B': ['B4', 'B5', 'B6', 'B7'], 'C': ['C4', 'C5', 'C6', 'C7'], 'D': ['D4', 'D5', 'D6', 'D7']}, index=[4, 5, 6, 7]) df..