본문 바로가기
프로그래밍/머신러닝

인공신경망(neural_network)_파이썬으로 머신러닝 배우기

by 조크리 2021. 5. 5.
반응형

 

1. 인간 뇌의 특징

 

인간의 뇌는 100억개의 뉴런과 각 뉴런을 연결하는 6조 개의 시냅스의 결합체라고 한다. 

인간의 뇌는 매우 복잡하며, 비선형적이고, 병렬적으로 정보를 처리한다. 

 

출처   https://commons.wikimedia.org/wiki/File:ANN_neuron.svg.   https://en.wikibooks.org/wiki/

 

 

 

2. 인공신경망의 특징

 

인공신경망은 입력신호, 가중치, 출력신호로 이루어진다. 

뉴런은 입력신호에 가중치를 부여함으로써 출력신호를 만들어낸다. 

출처 http://scienceon.hani.co.kr/397536

 

3. neural_network를 활용해보기

 

손실, 계수, 바이어스, 반복, 출력, 손실, 층수도 나타내보자! 

 

 

4. Teachable Machine에서 조절 가능한 인자 

 

 

5. 인자 살펴보기 

 

 

hidden_layer_sizes = (j,j),

max_iter = k,

learning_rate_init = i,

random_state = 0,

tol = 0.01

 

 

6. 수학 점수로 총점 예상하기

 

python
닫기
import matplotlib.pyplot as plot import numpy as np import math import pandas as pd import seaborn as sns import openpyxl plot.rcParams["font.family"] = 'Malgun gothic' data = pd.read_excel('student.xlsx', header = 0) newData = data[['kor', 'eng', 'math', 'social', 'science', 'total']] #속성(변수)선택 x = newData[['math']] y = newData[['total']] from sklearn.neural_network import MLPRegressor for i in (0.1, 0.01, 0.001, 0.0001): ​​​​for j in range(10, 100, 20): ​​​​​​​​for k in range(10, 40, 10): ​​​​​​​​​​​​model = MLPRegressor(hidden_layer_sizes=(j, j), ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​max_iter=k, ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​learning_rate_init=i, ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​random_state=0, ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​tol=0.01) ​​​​​​​​​​​​model.fit(x, y) ​​​​​​​​​​​​relation_square = model.score(x, y) ​​​​​​​​​​​​print('결정계수 R : ', relation_square) y_p = model.predict(x) ax1 = sns.distplot(y, hist = False, label = 'y_실제') ax2 = sns.distplot(y_p, hist = False, label = 'y_예측') plot.show() print('손실', model.loss_) print('계수', model.coefs_) print('바이어스', model.intercepts_) print('반복', model.n_iter_) print('출력', model.n_outputs_) print('손실', model.out_activation_) print('층수', model.n_layers_)

 

 

7. 국, 영, 수, 사회 점수로 총점 예측하기

 

python
닫기
import matplotlib.pyplot as plot import numpy as np import math import pandas as pd import seaborn as sns import openpyxl plot.rcParams["font.family"] = 'Malgun gothic' data = pd.read_excel('student.xlsx', header = 0) newData = data[['kor', 'eng', 'math', 'social', 'science', 'total']] #속성(변수)선택 x = newData[['kor', 'eng', 'math', 'social']] y = newData[['total']] from sklearn.neural_network import MLPRegressor for i in (0.1, 0.01, 0.001, 0.0001): ​​​​for j in range(10, 100, 20): ​​​​​​​​for k in range(10, 40, 10): ​​​​​​​​​​​​model = MLPRegressor(hidden_layer_sizes=(j, j), ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​max_iter=k, ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​learning_rate_init=i, ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​random_state=0, ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​tol=0.01) ​​​​​​​​​​​​model.fit(x, y) ​​​​​​​​​​​​relation_square = model.score(x, y) ​​​​​​​​​​​​print('결정계수 R : ', relation_square) y_p = model.predict(x) ax1 = sns.distplot(y, hist = False, label = 'y_실제') ax2 = sns.distplot(y_p, hist = False, label = 'y_예측') plot.show() print('손실', model.loss_) print('계수', model.coefs_) print('바이어스', model.intercepts_) print('반복', model.n_iter_) print('출력', model.n_outputs_) print('손실', model.out_activation_) print('층수', model.n_layers_)

 

 

반응형