
iris["Species"]=='Iris-setosa'

-> 이렇게 컬럼 Species 의 bool값이 반환된다.
iris[iris["Species"]=='Iris-setosa']

-> 데이터 프레임 안에 반환된 값을 넣으면 자동으로 그 컬럼의 알맞는 값만 추려진 전체 데이터프레임이 출력된다.
-> 데이터프레임 전체가 출력된다는게 잘 상상이 안가므로 꼭 기억해야하는 점



## 맨 마지막 것 제외하고 마스킹
iris[iris.columns[:-1]].corr()

-> 데이터가 얼마 없어서 바로 0.96이 눈에 띈다. 데이터가 매우 많을 때를 대비하여 더 눈에 띄게 히트맵으로 바꿔보자
plt.figure(figsize=(7,4))
sns.heatmap(iris[iris.columns[:-1]].corr(),annot=True,cmap='cubehelix_r')
plt.show()

-> 원래 0이 흰색이고 위아래로갈 수록 극명한 색이면 좋은데.. 어쨌든 아주 검정이거나 아주 파랑일 수록 좋다
train, test = train_test_split(iris, test_size = 0.3, random_state=42)train_X = train[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']]# taking the training data features
train_y=train.Species# output of our training data
test_X= test[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']] # taking test data features
test_y =test.Species #output value of test data
-> 있는 데이터를 다 지정해서 넣어봄: 세팔길이,세팔폭,페탈길이,페탈폭
SVM, Logistic Regression, Decision Tree, K-Nearest Neighbours
model = 원하는 머신러닝
model.fit(train_X,train_y)
prediction=model.predict(test_X)
-> 결국은 원하는 머신러닝 형태 지정하고, 학습값을 넣고, 테스트값을 넣어서 정확도를 출력하는 과정이다.
EDA 했을때 페탈길이, 페탈폭 데이터가 들어가면 좋을 것이라고 생각됨
-> (세팔길이, 세팔폭)을 넣었을때와, (페탈길이, 페탈폭) 넣었을 때를 비교
-> 이때 random_state를 고정하여 똑같은 랜덤한 입력값으로 비교할 수 있다!
model=svm.SVC() # 페탈만 했을때 결과?
model.fit(train_x_p,train_y_p)
prediction=model.predict(test_x_p)
print('The accuracy of the SVM using Petals is:',metrics.accuracy_score(prediction,test_y_p))
model=svm.SVC() # 세팔만 했을때 결과?
model.fit(train_x_s,train_y_s)
prediction=model.predict(test_x_s)
print('The accuracy of the SVM using Sepal is:',metrics.accuracy_score(prediction,test_y_s))

-> EDA에서 본것처럼 페팔끼리 비교한 것은 더 높은 정확도, 페팔끼리 비교한 것은 더 낮은 정확도인 것을 확인 할 수 있다.
데이터를 불러온 뒤, 항상 어떤 데이터인지 파악해야한다.
DF객체.info()
마스킹
슬라이싱
columns 키워드
loc
iloc
at
iat
in
mean()
& , |
json.load() 제이슨 파일을 읽어오는 함수
읽어온 제이슨 파일의 데이터를 확인해서 기존의 데이터프레임과 활용한 부분을 찾아야한다.

-> 서 이름으로 데이터프레임과 연결할 수 있을 것 같다.
-> 그외에도 주소값과, 위도 경도를 알 수 있어서 지도에 표기해 볼 수 있을 것 같다는 것을 파악!

-> 두개의 데이터프레임의 공통점은 경찰서명이 있다는것.
-> crime DF의 관서명을 변경하여 df_police와 똑같이 만들어주자
station_name = []
for name in crime.index:
station_name.append("서울" + str(name[:-1] +"경찰서"))
crime["police_name"] = station_name

-> 컬럼명이 동일해졌으므로, 서로 병합해본다 ( merge() )
# inner조인
crime_police_inner = pd.merge(left=crime,
right = df_police,
how = 'inner',
on=None)
# outer조인
crime_police_outer = pd.merge(left=crime,
right = df_police,
how = 'outer',
on=None)
-> inner조인은 공통된 데이터만 병합되고, outer조인은 공통된게 없어도 NaN으로 채우면서 새로운 행을 만든다.
iterrows()
데이터프레임의 각 행마다 데이터를 시리즈로 가져오고, 그 행의 인덱스를 같이 반환한다.
맵에 표현할 수 있는 함수
folium.Marker() : 마커를 띄운다.
folium.Circle() : 원을 그린다.
그래프를 그리면 그래프 위에 간단한 설명이 붙게되는데 이것을 없애는 방법
트레인 데이터와 테스트 데이터 나누기
테스트 데이터는 훈련에 절대 넣으면 안된다
train_test_split
train_test_split의 random_state=42 가 많이 쓰인다..
제이슨 파일의 데이터를 활용하기 위해서 형태를 변경할때, 리스트에 담긴 딕셔너리 형태로 제작하자.
데이터 프레임에 넣을 때 매우 편하기 때문이다.
-> 관리포인트 하나 줄여주기
police_info_list = []
for i in data:
inner_dict = {}
inner_dict["police_name"] = i["police_name"]
inner_dict['address'] = i["formatted_address"]
inner_dict['lat'] = i["geometry"]['location']['lat']
inner_dict['lng'] =i["geometry"]['location']['lng']
inner_dict['gu'] =i['formatted_address'].split(" ")[2]
police_info_list.append(inner_dict)