본문 바로가기

공부/파이썬19

케라스 이해하기 케라스를 사용하면서 딥러닝을 설계 해야한다면, 설계도는 하나의 모델이라고 표현된다고 한다. 모델은 퍼셉트론, 목표함수, 옵티마이저로 구성되어지며 과제의 예로 들면 아래와 같다. model = Sequential([ Dense(64, activation='sigmoid', input_dim=32), # A, B Dense(128, activation='sigmoid'), # C Dense(5, activation='softmax') # D ]) 위 예시에서 Sequential은 케라스에서 제공하는 모델 중에 하나이며 순차적인 레이어를 쌓기 위해 사용하는 모델이다. 코드의 2번째 줄에서 input_dim의 역할은 입력해야 할 뉴런의 수를 설정하는 것이고, activation의 역할은 활성화 함수를 설정하는 .. 2022. 5. 2.
파이썬에서 자연대수e를 사용하는 방법 numpy.exp() 시그모이드 함수를 구현하기 위하여 지수함수를 써야하는데 이 때 numpy에서 제공하는 numpy.exp()를 이용하여 지수함수를 사용할 수 있다. import numpy as np print(np.exp(0)) # e^0 와 동일 결과값 : 1.0 print(np.exp(1)) # e^1 와 동일 결과값 : 2.718~ print(np.exp(4.5)) # e^4.5 와 동일 결과값 : 90.01~ print(np.exp([0, 1])) # [e^0, e^1] 와 동일 결과값 : [1,2.718~] 위의 예시가 자연대수를 이용하는 방법이고 원래 목적인 시그모이드 함수를 표현하기 위해선 아래와 같다. def sigmoid(x): return 1 / (1 + np.exp(-x)) 2022. 5. 2.
클래스와 인스턴스란? 인스턴스는 클래스에 의해 만들어진 객체를 칭하는 말이다. 클래스는 하나의 공장이나 설계도라고 생각하면 되고 인스턴스는 그 공장에서 나오는 물건이라고 생각하면 이해하기 쉽다. Class 클래스란? 똑같은 무엇인가를 계속해서 만들어 낼 수 있도록 미리 구성해둔 설계도면, 틀 클래스는 객체마다 고유한 성격을 가지며 동일한 클래스로 만든 객체들은 서로 영향을 주지 않는다. 클래스로 만들어낸 것을 오브젝트(객체)라고 부른다. 즉 변수와 함수를 묶어서 하나의 새로운 객체로 만드는 역할 클래스는 아래와 같이 선언 된다 class name: #name 은 클래스의 이름을 정할때 임의로 사용. pass 클래스는 아래와 같이 사용 되며 아래의 a, b가 객체이다. a=name() b=name() 또한 a,b는 name클래.. 2022. 4. 5.
평균,분산, 표준편차 함수 코드 import numpy as np import pandas as pd v=[1,2,3,4,6] def mymean(v): #평균 sum=0 for i in v: sum+=i return sum/len(v) def myvar(v):#분산 sum=0 for i in v: sum=sum+((i-mymean(v))**2) return sum/len(v) def mystd(v):#표준편차 return np.sqrt(myvar(v)) print(mymean(v),myvar(v),mystd(v)) 루트는 어떻게 할지몰라서 넘파이를 이용하였다 2022. 2. 7.
dataframe series Dataframe - 여러 개의 series 합친 것 Series - 데이터프레임의 하나의 열 이라 생각하면 됨 dimension vector? 2022. 1. 24.
python Data structures 8.4 list 문제 8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alphabetical order. You can download the sample.. 2022. 1. 15.
Python Data Structures 3주차 파일 입출력에 관하여 배웠다. 과제 7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your so.. 2022. 1. 14.
파이썬의 다양한 string 함수 예시 1. string() 함수 word = 'banana' fruit = word.replace('ban','apple') 이라 함은 banana의 ban을 apple로 바꿔주는 역할 즉 출력 값은 appleana 가 된다 여러 반복되는 글자들도 banana 의 a를 -> o를 바꾸고 출력한 값임 즉 bonono가 됨 2.strip() ,lstrip(),rstrip()함수 출력문만 봐도 바로 이해가 가듯 공백을 제거해주는 함수 strip은 왼쪽오른쪽 전부 제거 lstrip은 왼쪽 공백제거 rstrip은 오른쪽 공백제거 2022. 1. 14.