카테고리 없음

230117

Berylly 2023. 1. 17. 17:44

T.김동식

 

lambda:  λ, 람다, 익명함수

#Python
#익명함수 > 람다함수 name=lambda a:a+1
add = lambda a : a+1
add(1, 2)
//Java 익명함수
public interface StringConcat {
void add(int a);
}

public class StringConcatImpl implements StringConcat{
@Override
public void add(int a) {System.out.println(a+1);}	
}

public static void main(String[] args) {
StringConcatImpl concatImpl = new StringConcatImpl();
concatImpl.add(1); //2
}
//Java 람다함수 
public interface StringConcat {
void add(int a);
}
public static void main(String[] args) {
StringConcat concat = a -> System.out.print(a+1);
concat.add(1);
}

 

 

 

Stream 스트림

클래스/함수를 만들지않고 쉽게 집계구현가능
*빅데이터 처리를 위한 언어, 집계함수(sum, average, count, max, min)

int arr[] = {1, 2, 3, 4, 5};
Arrays.stream(arr);
System.out.println(Arrays.stream(arr).count()); //5
System.out.println(Arrays.stream(arr).sum()); //15

System.out.println(Arrays.stream(arr).average()); //OptionalDouble[3.0]
System.out.println(Arrays.stream(arr).max()); //OptionalInt[5]
System.out.println(Arrays.stream(arr).min()); //OptionalInt[1]

//Optional 값 출력하기
System.out.println(Arrays.stream(arr).average().getAsDouble()); //3.0
System.out.println(Arrays.stream(arr).max().getAsInt()); //5
System.out.println(Arrays.stream(arr).min().getAsInt()); //1

 

 

 

정렬하기: for, Iterator&while, Steam 

ArrayList<Integer> test = new ArrayList<Integer>();
test.add(4);
test.add(1);
test.add(2);
test.add(3);
System.out.println("\n"+"for문 이용하기");
for(Integer i:test) {System.out.print(i);}
System.out.println("\n"+"\n"+"iterator 이용하기");
Iterator<Integer> iter = test.iterator();
while(iter.hasNext()) {System.out.print(iter.next());}
System.out.println("\n"+"\n"+"Stream 이용해 정렬하기");
Stream str = test.stream();
str.sorted().forEach(i->System.out.print(i));

 

 

 

javascript

documemt, screen, history, location, navigator

location.reload();

location.href="https://www.naver.com/";
location="https://www.naver.com/";

location.replace("https://www.naver.com/");

setTimeout("location.href='https://www.naver.com/'",3000);

 

 

Servlet

페이지이동: addHeader, javascript  location, sendRedirect, RequestDispatcher 

 

addHeader(초단위)

@WebServlet("/sanghee1")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.addHeader("Refresh", "1");
response.addHeader("Refresh", "1;url=sanghee2");


}

 

javascript location

@WebServlet("/sanghee1")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//javascript location
response.setContentType("text/html; charset=utf-8");
PrintWriter pw = response.getWriter();
pw.print("<script>location.href=\"sanghee2\";</script>");

}

 

sendRedirect (key=value지원, url이 sanghee2로 변경된다.)

@WebServlet("/sanghee1")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//sendRedirect
response.sendRedirect("sanghee2?name=sanghee");

}

 

RequestDispatcher (key=value지원, url이 sanghee2로 변화하지않은채, 페이지를 불러온다.)

@WebServlet("/sanghee1")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//RequestDispatcher 
RequestDispatcher dispatch = request.getRequestDispatcher("sanghee2?key=value");
dispatch.forward(request, response);
}

}

 

이동할 화면 sanghee2,

getParameter를 읽어 변수로 담아 출력한다.

@WebServlet("/sanghee2")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

PrintWriter pw =  response.getWriter();
String key = request.getParameter("key");
pw.print(key);

}

 

 

통계

데이터분석에서는 for나 if를 가급적 사용하지않는다.
데이터분석에서의 배열은 많은 데이터를 통채로 이용하는 개념임을 기억하자.

 

결측치: 값이 비어있는 상태 missing value

 

데이터는 항상 일부분의 데이터를 가지고 분석하는 경우가 대다수.

모수에서 추출하는 경우가 대부분

*모수: 데이터의 실제 전체 집단

 

 

Excel

 

Ctrl+1 셀서식

 

 

통계적인 기능을 추가해보자.

옵션 - 추가기능 - 이동 - 사용가능한 추가 기능 - 분석도구 VBA - 확인
*분석도구: 통계 및 엔지니어링 분석용 데이터 분석 도구를 제공.

 

 

통계프로그램 R

https://www.r-project.org/
https://cran.r-project.org/mirrors.html
https://cran.yu.ac.kr/

 

The Comprehensive R Archive Network

 

cran.yu.ac.kr

 

 

 

R Studio

통계프로그램 R을 편하게 이용할 수 있도록 하는 프로그램

https://support--rstudio-com.netlify.app/products/rstudio/download/
https://support--rstudio-com.netlify.app/products/rstudio/download/#download

 

Posit

Used by millions of people weekly, the RStudio integrated development environment (IDE) is a set of tools built to help you be more productive with R and Python.

posit.co

코드입력창 R script: ctrl shift n

 

창 정렬

 

 

 

 

 

 

Python

 

numpy

import numpy as np #import numpy로도 가능하나, numpy를 np로 줄여 이용을 많이 한다.
arr = np.array([110, 120, 130, 140, 150]) #list는 사용하지않는게좋다, 같은 데이터타입일때 유리
type(arr) #n차원 dimemstion, 1, 2, 3차원(선, 면, 입체)이 될 수 있다. #numpy.ndarray

np.mean(arr) #평균 130.0
arr.ndim #차원알아보기 1
arr[0] #인덱싱 가능 110

 

 

pandas

import pandas as pd #표를 다루기 위한 라이브러리
#엑셀일때 불러오기
#df=pd.read_excel('excel/student.xlsx')

#csv일때 불러오기, encoding은 utf-8 or cp949로 설정
ageLoan = pd.read_csv('excel/bank/ageLoan.csv', encoding='cp949')
ageLoan.head() #5줄만 보여준다.
ageLoan.info() #정보
ageLoan.describe() #표준편차
ageLoan.columns #열 리스트
ageLoan.set_index('25세 미만대출잔액', inplace=True)
ageLoan.index #name='25세 미만대출잔액'의 정보, length=195
ageLoan['25세_29세대출금액'] #'25세_29세대출금액'의 정보