■ 1. 주제 설정
-수입에 영향을 주는 요인은 어떤것이 있을까?
■ 2. 데이터 수집
출처: https://www.kaggle.com/danielbethell/adult-incomes-in-the-united-states?select=adult.data
중 adult.data 파일사용
설명 : 약 48,000건의 미국 인구조사 결과로 14개의 요소와 수입과의 연관관계를 비교하기 용이하다.
하지만 수입의 기준은 $50K/yr으로 연봉 약 5,500만원 이상인지 이하인지만 알 수 있다.
약 48,000건의 데이터 중 test데이터 제외, 중복데이터 제외 후 32,537건만 사용
($50K이상 24.78%, $50K 이하 75.22%)
■ 3. Maria DB 테이블 생성
drop table adult;
create table adult
(age float,
workclass varchar(60),
representativeness float,
education varchar(60),
education_num float,
marital_status varchar(60),
occupation varchar(60),
relationship varchar(60),
race varchar(30),
sex varchar(30),
capital_gain float,
capital_loss float,
hours_per_week float,
native_country varchar(60),
income varchar(60) );
■ 4. 데이터 전처리 및 데이터 로드
데이터 공백제거 vi편집기에서 :%s/ //g
중복제거및 나이순으로 행순서 변환 :sort -u
LOAD DATA LOCAL INFILE '/home/scott/adult.data'
REPLACE
INTO TABLE orcl.adult
fields TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(age,
workclass,
representativeness,
education,
education_num,
marital_status,
occupation,
relationship,
race,
sex,
capital_gain,
capital_loss,
hours_per_week,
native_country,
income);
<컬럼별 선택지 종류>
Variable Name Description
age : continuous
workclass : Private, Self-emp-not-inc, Self-emp-inc, Federal-gov, Local-gov, State-gov, Without-pay, Never-worked
representativeness : continuous (설문조사기관이 응답자가 미국에서 대표한다고 생각하는 사람 수)
Education : Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool.
Education-num : continuous (교육기간)
Marital-status : Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-AF-spouse.
Occupation : Tech-support, Craft-repair, Other-service, Sales, Exec-managerial, Prof-specialty, Handlers-cleaners, Machine-op-inspct, Adm-clerical, Farming-fishing, Transport-moving, Priv-house-serv, Protective-serv, Armed-Forces.
Relationship : Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried.
Race : White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.
Sex : Female, Male
Capital-loss : continuous
Capital-gain : continuous (자본이익, 불로소득)
Hours-per-week : continuous
Native-country : United-States, Cambodia, England, Puerto-Rico, Canada, Germany, Outlying-US(Guam-USVI-etc), India, Japan, Greece, South, China, Cuba, Iran, Honduras, Philippines, Italy, Poland, Jamaica, Vietnam, Mexico, Portugal, Ireland, France, Dominican-Republic, Laos, Ecuador, Taiwan, Haiti, Columbia, Hungary, Guatemala, Nicaragua, Scotland, Thailand, Yugoslavia, El-Salvador, Trinadad&Tobago, Peru, Hong, Holand-Netherlands.
Income : >50K , <=50K
※일부 컬럼명은 이해하기 쉽게 변경함
■ 5.세부 질문과 결과 해석
1.교육기간과 수입은 정비례관계일까?
(income 선택지가 두개 뿐이라, 50K이하 사람들의 평균 교육기간, 50K이상 사람들의 평균교육기간 비교)
select income, avg(education_num)
from adult
group by income;
설명: 연봉 5만 달러 이하인 사람들보다 연봉 5만 달러 이상인 사람들의 평균 교육기간이 약 2년정도 더 높은 것을 확인할수있다. 고학력일수록 임금이 높게 나타난다.
2.연봉이 5만달러 이상인 사람들의 직업은 무엇일까
select occupation,count(*)
from adult
where income='>50K'
group by occupation
order by 2 desc
limit 7;
설명 : 연봉 5만 달러 이상인 사람들의 직업은 1.관리자 2. 전문직 3.영업원 4. 수공예/수리 전문가 5.사무직 6.물류관련직종 7.기술지원 순으로 나타난다.
3.수입이 50K 이상인사람들의 인종은 무엇일까?
select Race, round(count(*)/(select count(*) from adult where income='>50K')*100,1) as percentage
from adult
where income='>50K'
group by Race
order by percentage desc;
설명: 연봉이 5만 달러 이상인 사람들의 인종은 백인이 91%로 압도적으로 많았고 흑인이 5%, 기타 인종들이 4%를 차지했다.
5.일주일당 일하는 시간이 길수록 수입이 증가할까?
select income, round(avg(hours_per_week),1) as working_hour
from adult
group by income;
설명: 연봉 5만달러 이하의 사람들은 일주일에 평균 38.8시간을 일하고 5만달러 이상인 사람들은 45.5시간을 일한다. 약 7시간차이지만 그에 따른 연봉은 차이가 많이나는 것을 보아 연봉 5만달러 이상의 사람들이 고부가가치의 직업을 가지고 있을 것으로 추측이 가능하다.