이번 포스팅에서는
킹갓제네레이션 Scikit Learn에서 제공해주는
연습 데이터 사용을 해보겠습니다.
이전 포스팅에서 사이킷런을 알아볼때
예제데이터도 제공한다고 했는데
이제 써보네요!
https://aigaeddo.tistory.com/12
9. 데이터) Scikit-Learn "train_test_split" 사용해서 데이터 쪼개보기
안녕하세요. 오늘은 Scikit Learn 의 train_test_split 함수를 이용해서 데이터를 쪼개보겠습니다. 일단 사이킷런(Scikit Learn)이 무엇인지 알아야겠죠? 1. Scikit Learn 사이킷 런이란 머신러닝을 위한 데이터
aigaeddo.tistory.com
1. 예제데이터 가져오기
scikit learn의 datasets 모듈에서 예제데이터를 가져올 수 있습니다.
https://scikit-learn.org/stable/modules/classes.html#module-sklearn.datasets
API Reference
This is the class and function reference of scikit-learn. Please refer to the full user guide for further details, as the class and function raw specifications may not be enough to give full guidel...
scikit-learn.org
저는 이 중에서 "fetch_california_housing"이라는 데이터를 써볼게요.
사이킷런의 datasets모듈의 fetch_california_housing 함수를 import 하겠습니다.
이 함수를 호출하면 Bunch라는 key_value기반 컨테이너 객체를 반환해주네요.
=
from sklearn.datasets import fetch_california_housing
datasets = fetch_california_housing()
x 즉 입력데이터는 data로, y 출력데이터는 target이라는
변수로 가져와보겠습니다.
x = datasets.data
y = datasets.target
문서를 보면
data는 (20640, 8)의 8종류의 데이터들이 20640개 있는 배열로
targe은 (20640,) 1종류의 데이터가 20640 개 있는 벡터로 리턴되네요.
sklearn.datasets.fetch_california_housing
Examples using sklearn.datasets.fetch_california_housing: Release Highlights for scikit-learn 0.24 Comparing Random Forests and Histogram Gradient Boosting models Imputing missing values before bui...
scikit-learn.org
x, y 반환형이 numpy형태의 배열이니
shape를 이용해서 행렬 구조를 찍어볼 수 있습니다!
또한 feature_name , DESCR, frame 이란 것도 사용할 수 있습니다.
pandas DataFrame으로도 받을 수 있네요.!
print(x.shape , y.shape) #(20640, 8) (20640,)
# print(datasets.feature_names) #['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']
# print(datasets.DESCR)
'''
:Attribute Information:
- MedInc median income in block group
- HouseAge median house age in block group
- AveRooms average number of rooms per household
- AveBedrms average number of bedrooms per household
- Population block group population
- AveOccup average number of household members
- Latitude block group latitude
- Longitude block group longitude
'''
그럼 이 연습데이터로
머신러닝 모델을 만들어 볼 수 있겠죠.
사이킷런은
학습데이터까지 있고
정말 유용한 패키지네요...
원작자 데이비드님 및 Contributor 분들 최고!
'인공지능 개발하기 > Machine Learning' 카테고리의 다른 글
[Tensorflow] 14. 데이콘(Dacon) 연습 대회 참가하기 (2) | 2024.01.09 |
---|---|
[Tensorflow] 13. csv 파일 데이터 다루기(pandas 패키지) (1) | 2024.01.08 |
[Tensorflow] 11. 결정계수(R2) - Scikit Learn r2_score (1) | 2024.01.05 |
[Tensorflow] 10. 모델 훈련 결과 시각화 하기 (feat. matplolib) (0) | 2024.01.04 |
[Tensorflow] 9. Scikit-Learn "train_test_split" 사용해서 데이터 쪼개기 (0) | 2024.01.04 |