분류 전체보기
-
Python 데이터분석 기초 63 - DecisionTreeRegressor, RandomForestRegressorPython 데이터 분석 2022. 11. 23. 10:09
중요변수 얻을 때는 RandomForestRegressor를 사용하는 것을 추천한다. 그 이외에는 ols를 추천 # import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.tree import DecisionTreeRegressor from sklearn.ensemble import RandomForestRegressor from sklearn.datasets import load_boston from sklearn.metrics import r2_score boston = load_boston() # print(boston.keys()) dfx = pd.DataFrame(boston.data, colum..
-
RandomForest 예제 2 - django를 활용(patient 데이터 사용)Python 데이터 분석 2022. 11. 22. 18:12
url.py from django.contrib import admin from django.urls import path from myapp import views urlpatterns = [ path("admin/", admin.site.urls), path("", views.MainFunc), path("show", views.ShowFunc), path("list", views.ListFunc) ] views.py from django.shortcuts import render import pandas as pd import numpy as np from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection impo..
-
RandomForest 예제 1 - Red Wine quality 데이터Python 데이터 분석 2022. 11. 22. 18:02
import pandas as pd import numpy as np from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split, cross_val_score from sklearn.metrics import accuracy_score df = pd.read_csv('../testdata/winequality-red.csv') print(df.head(3)) print(df.info()) df_x = df.drop(columns = ['quality']) df_y = df['quality'] train_x, test_x, train_y, test_y = train_test_sp..
-
Python 데이터분석 기초 62 - Random forest 예제(titanic)Python 데이터 분석 2022. 11. 22. 14:59
# titanic dataset으로 LogisticRegression, DecisionTree, RandomForest 분류 모델 비교 import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.metrics imp..
-
Python 데이터분석 기초 61 - Random forestPython 데이터 분석 2022. 11. 22. 12:23
Random forest는 ensemble(앙상블) machine learning 모델입니다. 여러개의 decision tree를 형성하고 새로운 데이터 포인트를 각 트리에 동시에 통과시키며, 각 트리가 분류한 결과에서 투표를 실시하여 가장 많이 득표한 결과를 최종 분류 결과로 선택합니다. Bagging 방식을 사용 Titanic dataset을 사용 # Random forest는 ensemble(앙상블) machine learning 모델입니다. # 여러개의 decision tree를 형성하고 새로운 데이터 포인트를 각 트리에 동시에 통과시키며, # 각 트리가 분류한 결과에서 투표를 실시하여 가장 많이 득표한 결과를 최종 분류 결과로 선택합니다. # Bagging 방식을 사용 # Titanic data..
-
Python 데이터분석 기초 60 - Ensemble LearningPython 데이터 분석 2022. 11. 22. 10:45
Ensemble Learning : 개별적인 여러 모델들을 모아 종합적으로 취합 후 최종 분류 결과를 출력 종류로는 voting, baggin, boosting 방법이 있다. # Ensemble Learning : 개별적인 여러 모델들을 모아 종합적으로 취합 후 최종 분류 결과를 출력 # 종류로는 voting, baggin, boosting 방법이 있다. # breast_cancer dataset 사용 # LogisticRegressoin, DecisionTree, KNN을 사용하여 보팅 분류기 작성 import pandas as pd from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_..
-
Python 데이터분석 기초 59 - 일반화 모델을 위한 과적합 방지 방법Python 데이터 분석 2022. 11. 21. 13:17
1. train/test split 방법 2. Validation = train data를 쪼개 학습과 검정을 같이한다. 교차검증(cross validation) - train/test split을 해도 과적합 발생 또는 데이터의 양이 적은 경우 3. GridSearchCV = 최적의 모델을 찾아준다. ''' 일반화 모델을 위한 과적합 방지 방법 iris dataset을 사용 train/test split, KFold, GridSearchCV ''' from sklearn.datasets import load_iris from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import accuracy_score iris=load_iris..
-
Python 데이터분석 기초 58 - 의사결정나무(Decision Tree), 시각화Python 데이터 분석 2022. 11. 21. 11:22
# 의사결정나무(Decision Tree) # 의사결정나무는 데이터를 분석하여 이들 사이에서 존재하는 패턴을 예측 가능한 규칙들의 조합으로 나타내며, # 그 모양이 '나무'와 같다고 해서 의사결정나무라 불린다. # 질문을 던져서 대상을 좁혀나가는 '스무고개' 놀이와 비슷한 개념이다. # 의사결정나무는 분류(classification)와 회귀(regression) 모두 가능하다. 범주나 연속형 수치 모두 예측할 수 있다. # Entropy : 독립변수의 혼잡도. 0 ~ 1 사이의 값을 가지며 낮을수록 좋다. # Information Gain : 지정된 속성이 얼마나 잘 학습 데이터들 간 import pydotplus from sklearn import tree # 키와 머리카락의 길이로 남녀 구분 x = ..