쑤쑤_CS 기록장
Ch5. challenge1 : Binary classifier 풀이 본문
* 챌린지 내용
Remember the healthy/unhealthy snacks model?
Try to train that binary classifier using Turi Create. The approach is actually very similar to what you did in this chapter. The only difference is that you need to assign the label “healthy” or “unhealthy” to each row in the training data SFrame.
First, you assign each class into a healthy or unhealthy array — there are 10 classes in each array.
Then, you set each image’s label column to "healthy" or "unhealthy", depending on which array the image’s path name is in. The result is, you’ve divided 20 classes of images into two classes, based on the name of the subdirectory they’re in.
Verify that the resulting model gets about 80% accuracy on the test dataset.
You may wonder why you can’t use the multi-class snacks model for this, and simply look if the predicted category is in the list of healthy or unhealthy classes. This is possible but, by training from scratch on just these two categories, the model has a chance to learn what healthy/unhealthy means, and it might use a more intricate rule than just “this class label is in the list of healthy categories.”
If you want to be sure which approach works better, use the 20-class model to classify() the healthy/unhealthy test dataset, and merge its output with test_data as before. The label column contains “healthy” or “unhealthy,” while the class column contains “apple,” “banana,” etc.
Then use filter_by(healthy, "class") to find images the model predicts to be in a class listed in the healthy array. Filter these images with filter_by(["unhealthy"], "label") to find images that are really in unhealthy classes. Manually calculate the accuracy of the 20-class model in predicting healthy/ unhealthy. I got 47%.
* 챌린지 풀이
새 프로젝트에 Jupyter Notebook을 실행한다.
이때, import turicreate as tc
에서 No module named 'turicreate' 라는 문구가 뜰 경우
pip install turicreate 명령어를 먼저 실행하면 해결된다.
1. 필요한 모듈 matplotlib.pyplot 과 turicreate을 import 한다.
2. train test 데이터를 load 한다.
3. healthy = [ , ,] unhealthy = [ , , ] 를 지정해준다.
4. binary 모델을 생성한다.
5. 테스트 데이터를 사용한다.
6. 결과를 출력한다.
7. multi 모델을 생성한다.
8.healthy와 unhealthy 라벨을 찾는다.
9. 모델의 결과를 출력한다.
'IT 지식 기록 > ML for iOS | 인공지능' 카테고리의 다른 글
되돌아보는 챕터 6 (0) | 2020.08.06 |
---|---|
Ch5. challenge1 : Binary classifier 정답 코드 (0) | 2020.08.04 |
Chapter 6: Taking Control of Training with Keras (0) | 2020.08.03 |
되돌아보는 챕터 5 (0) | 2020.07.28 |
Chapter 5: Digging Deeper into Turi Create (0) | 2020.07.27 |