Python/Python기초

Python 67_ kNN 직접 구현하기 >> 에 이어서 작업해주시면 됩니다. # 데이터 프레임을 이용해서 각 특성(변수)들과 Class(레이블)과의 관계 그래프iris_by_class = iris.groupby(by='Class')for name, group in iris_by_class: # print(name, len(group)) plt.scatter(group['sepal_length'], group['sepal_width'], label=name)plt.legend()plt.xlabel('sepal_length')plt.ylabel('sepal_width')plt.show() for name, group in iris_by_class: # print(name, len(group)) plt.sc..
"""scikit-learn 패키지를 이용한 kNN(k Nearest Neighbor: 최근접 이웃)"""import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom sklearn.model_selection import train_test_splitfrom sklearn.neighbors import KNeighborsClassifierfrom sklearn.preprocessing import StandardScalerfrom sklearn.metrics import confusion_matrix, classification_report # 1. 데이터 준비col_names = ['sepal-length', 'sepal-width'..
import pandas as pd # 1. 데이터 준비col_names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'Class'] # csv 파일에서 DataFrame을 생성dataset = pd.read_csv('iris.csv', encoding='UTF-8', header=None, names=col_names) # DataFrame 확인print(dataset.shape) # (row개수, column개수)print(dataset.info()) # 데이터 타입, row 개수, column 개수, 컬럼 데이터 타입print(dataset.describe()) # 요약 통계 정보 (150, 5) RangeIndex: 150 e..
"""icrawler 패키지를 이용해서, Google 이미지 검색 결과의 이미지들을 다운로드> pip install icrawler"""from icrawler.builtin import GoogleImageCrawlerimport os # 이미지 저장 폴더 경로save_dir = os.path.join('..', '..', 'images')# GoogleImageCrawler 객체 생성google_crawler = GoogleImageCrawler(storage={'root_dir': save_dir})google_crawler.crawl(keyword='펭수', max_num=50) 결과 >> 위의 결과는 images.google.com에서 '펭수' 검색 결과를 가져온 것이다. 그 밖에 여러 검색 조..
Codezoy
'Python/Python기초' 카테고리의 글 목록 (4 Page)