인공지능 공부/Fandas
2021-04-20 판다스 SVM 실습
SVM import pandas as pd import seaborn as sns #데이터 준비 기본 설정 df = sns.load_dataset('titanic') pd.set_option('display.max_columns', 15) #데이터 전처리 rdf = df.drop(['deck', 'embark_town'], axis=1) #age 열에 나이 데이터가 없는 모든 행 삭제 - age rdf = rdf.dropna(subset=['age'], how='any', axis=0) most_freq = rdf['embarked'].value_counts(dropna=True).idxmax() rdf['embarked'].fillna(most_freq, inplace = True) rdf['embar..
2021-04-20 판다스 원 - 핫인코딩 실습
원핫인코딩 = 범주형 데이터를 모형이 인식할 수 있도로 숫자형 변환 onehot_sex = pd.get_dummies(ndf['sex']) ndf = pd.concat([ndf, onehot_sex], axis = 1) onehot_embarked = pd.get_dummies(ndf['embarked'], prefix = 'town') ndf = pd.concat([ndf, onehot_embarked], axis = 1) ndf.drop(['sex', 'embarked'], axis=1, inplace=True) print(ndf.head()) survived pclass age sibsp parch female male town_C town_Q town_S 0 0 3 22.0 1 0 0 1 0 0 ..
2021-04-20 판다스 다중회귀 실습
다중회귀분석 X=ndf[['cylinders','horsepower','weight']] y=ndf['mpg'] from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3, random_state=10) print('훈련데이터', X_train.shape) print('검증데이터', X_test.shape) 훈련데이터 (274, 3) 검증데이터 (118, 3) lr = LinearRegression() lr.fit(X_train, y_train) r_square = lr.score(X_test, y_test) print(r_square) prin..
2021-04-20 판다스 실습 다항회귀 실습
다항회귀 분석 from sklearn.preprocessing import PolynomialFeatures #다항식 변환 poly = PolynomialFeatures(degree=2) X_train_poly = poly.fit_transform(X_train) print('원데이터', X_train.shape) print('2차항 변환 데이터:', X_train_poly.shape) 원데이터 (274, 1) 2차항 변환 데이터: (274, 3) pr = LinearRegression() pr.fit(X_train_poly, y_train) #학습을 마친 모형에 test data적용하여 결정계수 (R-제곱 계산) X_test_poly = poly.fit_transform(X_test) r_square ..
2021-04-20 판다스 머신러닝 실습
import numpy as np import matplotlib.pyplot as plt import seaborn as sns #read_csv() 함수로 자동차 연비 데이터셋 가져오기 df = pd.read_csv('C:/Users/SM2130/Desktop/인공지능 관련/데이터/auto-mpg.csv',header = None) df.columns = ['mpg','cylinders','displacement','horsepower','weight','acceleration','model year','origin','name'] print(df.head()) mpg cylinders displacement horsepower weight acceleration model year \ 0 18.0 ..