728x90
728x90

  컨텐츠 채우기  

- 이번 포스팅에서는 portfolio 페이지에 들어갈 image 와 text content 내용을 채워 보겠습니다.

- 우선 1개의 content를 채운뒤 나머지 content들을 추가하는 방식으로 진행합니다.

- 아래의 단계별로 진행 해 보겠습니다.

 

  단계  

1. image 추가 

2. text Content 채우기

3. content 태그 추가 

4. CSS 수정

 

 

  1.image 추가  

- subimage 태그 안에 img태그를 추가합니다. 

- 경로는 static > img > portfolio 디렉토리 안에 Trading_predict_price.png 를 지정해 줍니다.

- 대체 문자로는 ' 주식가격예측'을 넣어 줍니다.

        <div class="image">
            <img src="../static/img/portfolio/Trading_predict_price.png" alt="주식가격예측">
        </div>

 

- img 태그의 max-width 값으로 100% 를 지정해 줍니다.

#portfolio > .content > .image > img {
    max-width: 100%;

}

  2. text Content 채우기  

- subtitle / subdescription / sublink 에 들어갈 문구들을 각 태그들의 span 안에 넣어 줍니다.

        <div class="textcontent">
            <div class="subtitle">
                <span>
                    Stock price prediction model
                </span>
            </div>
            <div class="subdescription">
                <span>
                    -The domestic stock price prediction model using Keras and Tensorflow trains RNN and LSTM neural network model with time series data to predict the next price according to period
                </span>
            </div>
            <div class="sublink">
                <span>
                    Link - https://github.com
                </span>
            </div>
        </div>

- link 부분은 우선 임의로 넣어 놨습니다.

- 이부분을 a태그로 감싸 주겠습니다.

                <span>
                   <a href="">
                       Link - https://github.com
                   </a>
                </span>

- 잘 들어 갔네요.

 

  3. content 태그 추가  

- 이제 만들어 놓은 content태그를 복사하여 2개 더 추가 해주고 안에 있는 내용을 수정해 줍니다.

 

    <div class="content">

        <div class="image">
            <img src="../static/img/portfolio/Trading_predict_price.png" alt="주식가격예측">
        </div>
        <div class="textcontent">
            <div class="subtitle">
                <span>
                    Stock price prediction model
                </span>
            </div>
            <div class="subdescription">
                <span>
                    -The domestic stock price prediction model using Keras and Tensorflow trains RNN and LSTM neural network model with time series data to predict the next price according to period
                </span>
            </div>
            <div class="sublink">
                <span>
                    <a href="">
                        Link - https://github.com
                    </a>
                </span>
            </div>
        </div>
    </div>

    <div class="content">

        <div class="image">
            <img src="../static/img/portfolio/oil_price_korea.jpg" alt="국내주요소가격분석">
        </div>
        <div class="textcontent">
            <div class="subtitle">
                <span>
                    Oil price analysis
                </span>
            </div>
            <div class="subdescription">
                <span>
                -Analyzing the status of domestic gas stations and analyzing prices by region, visualization through a map library, receiving and analyzing changes in oil prices as data, and conducting visualization and preparatory work for distribution
                </span>
            </div>
            <div class="sublink">
                <span>
                    <a href="">
                        Link - https://github.com
                    </a>
                </span>
            </div>
        </div>
    </div>

    <div class="content">

        <div class="image">
            <img src="../static/img/portfolio/feature_impotance%20Chart.png" alt="중요특성분석">
        </div>
        <div class="textcontent">
            <div class="subtitle">
                <span>
                    ML model Features Analysis
                </span>
            </div>
            <div class="subdescription">
                <span>
                    -Analysis and visualization of the importance of learning and feature_importances along with the analysis of fearures to learn machine learning and the data set required for learning
                </span>
            </div>
            <div class="sublink">
                <span>
                    <a href="">
                        Link - https://github.com
                    </a>
                </span>
            </div>
        </div>
    </div>

- 내용은 잘 들어 갔지만 , 컨텐츠들이 정렬 되지 않았습니다.

- CSS를 몇가지 수정하고 정렬시켜야 합니다.

 

  4. CSS 수정  

- 우선 content들을 정렬 시켜 보겠습니다.

- 정렬이 되지 않은 이유는 content의 높이가 자식 태그들의 높이들 만큼 반영 되지 않았습니다.

- image 와 textcontent가 float값이 지정 되어 있기 때문에 붕 떠있는 상태와 같습니다.

- 해결방법은 몇가지가 있지만 저는 image와 textcontent의 부모 태그인 content태그에 float 값으로 left를 주어서 해결하겠습니다.

 

#portfolio > .content {
    float: left;
    margin-top: 50px;
    width: 1240px;
}

- 이제 잘 정렬 되엇습니다.

- 다음으로 image 부분과 sidebar 부분에 간격을 60px만큼 주겠습니다.

- margin-left 값으로 60px만큼 지정하고 textcontent의 width 값을 60px만큼 감소 시킨 680px로 수정합니다.

#portfolio > .content > .image {
    float: left;
    width: 500px;
    margin-left: 60px;
}

#portfolio > .content > .textcontent {
    float: left;
    width: 680px;
}

 

- 잘 만들어 졌습니다!!

- Js 나 서버 측에서 작업물의 개수만큼 자동으로 content를 만들어 보여주면 좋을것 같습니다.

- 위와 같은 기능들은 우선 페이지들의 레이아웃을 완성 시킨 후 진행해 보도록 하겠습니다.

- 다음 포스팅에서는 마지막 페이지인 contact 페이지를 진행해 보겠습니다.

728x90
728x90

머신러닝은 데이터 가공/ 변환, 모델 학습/ 예측 , 그리고 평가의 프로세스로 구성된다.

 

분류의 선능 평가 지표

- accurary

- Confusion Matrix

- Precision

- Recall

- F1

- ROC_AUC

 

트레이드 오프 

- 정밀도 / 재현율 트레이드 오프

- 정밀도와 재현율은 상호 보완적인 평가 지표이기 때문에 어느 한쪽ㄷ을 강제로 높이면 다른 하나의 수치는 떨어지기 쉽습니다.

- 이를 정밀도/재현율 트레이드 오프 라고 합니다.

- 임계값 : threshold

- precision_recall_curve(y_test,pred_proba_class1)

- precisions, recalls, thresholds = precision_recall_curve(y_test,pred_proba_class1)

- 임계값의 인덱스 추출 하여 nd.array 로 생성

- 인덱스에 해당하는 임계값 추출

- 인덱스에 해당하는 정밀도와 재현율 값 추출

- 이를 이용한 시각화

- Binarizer(theshold=임계값) 변경된 값 , predict_proba()[:,1] 예측확률 배열에서 1에 해당하는 칼럼값을 변경 

 

교차검증

- KFold (n_splits = 분할할 폴드 수)

- cross_val_score

 

하이퍼파라미터 튜닝

- GridSearchCV(모델, param_grid = {파라미터 딕셔너리} , scoring=점수 , cv = 5)

- 최적의 하이퍼 파라미터 : best_params_

- 최고의 정확도 : best_score_

- 최적의 하이퍼 파라미터로 학습괸 Estimator : best_estimator_

 

결정트리 / DecisionTree Classifier and Regression

prameter =

- {'min_samples_split':'노드를 분할 하기 위한 최소한의 샘플 데이터 수 / defualt = 2'}

- {'min_samples_leaf':'말단 노드가 되기 위한 최소한의 샘플데이터 수'}

- {'max_features':'최적의 분할을 위해 고려할 최대 피처 개수 / defualt =None'}

- {'max_depth':'트리의 최대 깊이 / default = None'}

- {'max_leaf_nodes':'말단 노드의 최대 개수'}

- 결정트리분류 모델이 반복시마다 동일한 예측 결과 도출을 위해 random_state 설정 

 

randomforest

728x90
728x90

  Portfolio 페이지  

- 이제 Portfolio 페이지를 완성할 차례입니다.

- Portfolio 페이지는 그동안 제가 해온 작업물들에 대한 소개와 이미지 그리고 링크 등이 들어 갑니다.

- 기본적인 레이아웃 작업을 우선적으로 진행하고, 이후에 JavaScript를 통해 기능을 추가해 보겠습니다.

- Portfolio 레이아웃 구성을 위한 작업물등중 3가지를 선택했습니다.

- 이 작업물들을 통해서 레이아웃을 구성했습니다.

- Portfolio 페이지의 타이틀이 가장 상단에 들어갑니다.

- 그 밑으로 이미지가 좌측에 텍스트들이 우측에 배치 됩니다.

- 텍스트는 작업물 제목 / 소개 / 링크로 구성되어있습니다.

- 이제 아래의 단계에 따라 기본적인 레이아웃을 구성해 보겠습니다.

 

  단계  

1. portfolio.html 태그 추가

2. portfolio 크기 및 위치 지정

3.portfolio title 위치와 크기 지정

4. content 크기와 위치 지정

5. image와 textcontent 크기와 위치 지정

6. textcontent 태그 추가 및 위치 크기 지정  

1. portfolio.html 태그 추가

- portfolio.html에 필요한 태그들을 추가 해주겠습니다.

- 먼저 id 가 portfolio 인 div태그를 추가해 줍니다.

{% extends 'layout.html' %}
{% block content %}
<div id="portfolio">
</div>
{% endblock %}

- 이 태그안에 컨텐츠들을 추가 해 주겠습니다.

- 먼저 #portfolio > .title을 추가 해 주겠습니다.

{% extends 'layout.html' %}
{% block content %}
<div id="portfolio">
    <div class="title">
        portfolio
    </div>
</div>
{% endblock %}

- div.title 하단에 이미지와 텍스트들이 들어갈 클래스가 content인 div 태그를 우선 1개 추가 해 줍니다.

{% extends 'layout.html' %}
{% block content %}
<div id="portfolio">
    <div class="title">
        portfolio
    </div>
    <div class="content">
        content
    </div>
</div>
{% endblock %}

- div.content안에 이미지가 들어갈 div.image와 div.textcontent 태그를 추가해 주겠습니다.

{% extends 'layout.html' %}
{% block content %}
<div id="portfolio">
    <div class="title">
        portfolio
    </div>
    <div class="content">
        content
        <div class="image">
            img
        </div>
        <div class="textcontent">
            text
        </div>
    </div>
</div>
{% endblock %}

- 기본적인 태그들을 추가해 주었습니다.

- 다음 단계를 진행하면서 필요한 태그들을 추가해 주겠습니다.

 

  2. portfolio크기 및 위치 지정  

- 먼저 div#portfolio 의 크기와 위치를 지정해 주겠습니다.

- div#portfolio에 border 값을 주어서 지금 지정된 위치와 크기를 확인합니다.

#portfolio{
    border:1px solid red;
}

 

 

- 현재 main의 가로 크기 만큼 div#portfolio 가로크기가 지정되어있고, 높이는 폰트 사이즈의 높이 합 만큼 지정되어있습니다.

- 가로 크기를 main가로크기 - 사이드바 가로크기 / 1440px - 200px = 1240px

- 이제 position 값으로 absolute를 지정해 주고 left값으로 200px을 지정해 줍니다.

#portfolio{
    position: absolute;
    left: 200px;
    width: 1240px;
    height: auto;
    border:1px solid red;
}

 

  3.portfolio title 위치와 크기 지정  

- Portfolio페이지의 제목에 해당하는 div.title의 위치와 크기를 지정해 주겠습니다.

- div.titile에 border 값을 지정해 주어서 정확한 위치와 크기를 확인해 보겠습니다.

 

- width 값으로 100%를 지정합니다.

- div.title안에는 Portfolio 라는 폰트가 지정되어 들어 갑니다.

- 폰트 사이즈와 폰트 스타일을 적용 시켜 주겠습니다.

 

- 폰트 사이즈는 60px / 스타일은 black font-weight은 900을 지정해 줍니다.

- Text-align 값으로 center를 지정해 줘서 가운데 정렬 시켜 줍니다.

 

#portfolio > .title{
    font-size: 60px;
    font-weight: 900;
    text-align: center;
    border: 1px solid red;
}

  4. content 크기와 위치 지정  

- div.content의 지금 크기와 위치를 확인합니다.

-

- 계획 레이아웃을 보면 title과 content , content들 사이에 간격이 50px만큼 존재랍니다.

- div.content에 margin-top 값으로 50px만큼 지정해 줍니다.

- width 값으로는 div.portfolio와 같은 값이 1240px을 지정해 줍니다.

 

#portfolio > .content{
    margin-top: 50px;
    width: 1240px;
    border: 1px solid red;    
}

- 간격이 생겼습니다.

 

  5. image와 textcontent 크기와 위치 지정  

- 이제 content 안에 들어가있는 div.image 와 div.textcontent를 진행해 보겠습니다.

- content에 들어가는 이미지와 텍스트의 크기는 각 포트폴리오 작업물마다 상이합니다.

- 그래서 이미지의 가로의 크기를 고정 시켜주고 text가 들어갈 곳의 가로크기를 고정시켜 줍니다.

- float값을 left로 지정합니다.

#portfolio > .content > .image {
    float: left;
    width: 500px;
    border: 1px solid red;
}

#portfolio > .content > .textcontent {
    float: left;
    width: 730px;
    border: 1px solid red;
}

- 우선은 border 크기가 있어 textcontent 의 가로 크기를 730px 로 지정해 주었습니다. 후에 740px로 변경합니다.

  6. textcontent 태그 추가 및 위치 크기 지정  

- 이제 textcontent 안에 들어갈 subcontents 들의 태그들을 추가 해 주겠습니다.

- 안에 들어갈 subcontents들은 작업물의 제목 - subtitle / 소개내용 -subdescription / 링크 주소 - sublink 입니다.

- div.textcontent 안에 추가 해 주겠습니다.

        <div class="textcontent">
            <div class="subtitle">
                subtitle
            </div>
            <div class="subdesciption">
                subdescription
            </div>
            <div class="sublink">
                sublink
            </div>
        </div>

- 먼저 div.subtitle의 크기와 위치를 지정해 주겠습니다.

 

- 폰트 사이즈는 35px / 폰트 스타일은 regular 400 입니다.

- 그리고 가운데 정렬 시켜 줍니다.

#portfolio > .content > .textcontent > .subtitle {
    font-size: 35px;
    font-weight: 400;
    text-align: center;
    border: 1px solid red;
}

- subtitle들을 보면 모두 검은색 바탕에 흰색 글자색을 가지고 있고 상하좌우 여백을 가지고 있습니다.

- subtile문구를 span으로 감싸주고 display값으로 inline-block으로 지정합니다.

-padding 값으로 10px을 지정하고 color 값을 white / background-color 값을 black으로 지정합니다.

 

            <div class="subtitle">
                <span>
                    subtitle
                </span>
            </div>
#portfolio > .content > .textcontent > .subtitle>span{
    padding: 10px;
    color: white;
    background-color: black;
    display: inline-block;
    border: 1px solid blue;
}

- 다음으로 subdescription 부분을 진행해 보겠습니다.

- 먼저 폰트에대한 정보를 확인합니다.

- 폰트 사이즈는 20px / 폰트 스타일은 thin 100 입니다.

#portfolio > .content > .textcontent > .subdescription {
    font-size: 20px;
    font-weight: 100;
    border: 1px solid red;
}

- subtitle 과 subdescription 사이에 간견이 40px만큼 존재합니다. margin-top 값으로 40px를 지정해 주겠습니다.

#portfolio > .content > .textcontent > .subdescription {
    font-size: 20px;
    font-weight: 100;
    margin-top: 40px;
    border: 1px solid red;
}

- 다시 subdecription을 가운데 정렬 시키고, span으로 감싸줍니다.

#portfolio > .content > .textcontent > .subdescription {
    font-size: 20px;
    font-weight: 100;
    margin-top: 40px;
    text-align: center;
    border: 1px solid red;
}

 

- 마지막으로 sublink를 진행해 주겠습니다.

- 폰트 사이즈는 25px 스타일은 Light 300 입니다.

- 폰트에 대한 값들을 지정해 주고 가운데 정렬 시킨후 span값으로 감싸줍니다.

#portfolio > .content > .textcontent > .sublink {
    font-size: 25px;
    font-weight: 300;
    margin-top: 30px;
    text-align: center;
    border: 1px solid red;
}

- subdescription 과 sublink의 span을 display : inline-block으로 지정한후 width 값으로 500px을 지정합니다.

- text-aligh을 left 시켜서 두곳을 정렬 시켜 줍니다.

#portfolio > .content > .textcontent > .subdescription > span {
    display: inline-block;
    width: 500px;
    text-align: left;
    border: 1px solid blue;
}

#portfolio > .content > .textcontent > .sublink > span {
    display: inline-block;
    width: 500px;
    text-align: left;
    border: 1px solid blue;
}

 

- 다음에는 contents들에 해당하는 이미지와 텍스트들을 삽입해 보겠습니다.

728x90
728x90

볼린저 밴드 Bollinger Bands

- 이동평균선 ( 볼린저 밴드에서는 단순 이동 평균선)을 기준으로 일정한 표준편차 번위 안에 드는 밴드를 설정한 그래프

- 시장의 높고 낮음 및 과매수 또는 과매도 여부를 나타냅니다.

TA-LIB을 이용한  볼린저 밴드 구하기

TA-LIB에서 볼린저 밴드를 구하는 함수 

- talib.BBANDS()

upperband, middleband, lowerband = BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
http://mrjbq7.github.io/ta-lib/func_groups/overlap_studies.html

- talib의 BBANDS() 함수는 볼린저 밴드의 상한선 / 중간선 / 하한선에 대한 값을 반환합니다.

- 간단한 예제를 통해 볼린저 밴드값을 구해보고 차트를 그려보겠습니다.

 

예제

- 사용한 데이터는 종목코드 - 000020 입니다. 

- 최근 기간중 주말과 휴장일을 제외한 100일간의 데이터입니다.

- 간단한 봉 차트를 그려보겠습니다.

- talib의 BBANDS() 함수를 사용해 기간은 20일로 지정하고, 볼린저 밴드 값을 구합니다.

df['BBAND_UPPER'],df['BBAND_MIDDLE'],df['BBAND_LOWER'] = ta.BBANDS(df['close'],20,2)

- 대신증권 HTS 에서 그려진 볼린저 밴드와 비교해 보면 똑같이 그려졌네요.

 

728x90
728x90

넘파이 (Numpy) Numpy.c_

- Translates slice objects to concatenation along the second axis.

- 2개의 배열을 붙여 2차원 배열로 만들기

 

>>> np.c_[np.array([1,2,3]), np.array([4,5,6])]
array([[1, 4],
       [2, 5],
       [3, 6]])
>>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
array([[1, 2, 3, 0, 0, 4, 5, 6]])

 

https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.c_.html?highlight=numpy%20c_#numpy.c_
728x90
728x90
728x90

+ Recent posts