본문 바로가기

DataScience/MachineLearning21

Machine [supervised{Classification(Support Vector Machine)}] In [3]: # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd In [6]: # Importing the dataset df = pd.read_csv('../data/Social_Network_Ads.csv') In [7]: df Out[7]: User ID Gender Age EstimatedSalary Purchased 0 15624510 Male 19 19000 0 1 15810944 Male 35 20000 0 2 15668575 Female 26 43000 0 3 15603246 Female 27 57000 0 4 15804002 Male 19 76000 0.. 2022. 12. 2.
Machine Logistic Regression 데이터의 결점보완(0,nan), 데이터의 불균형 up sampling 기법, 결과를 히트맵으로 표현 In [1]: import pandas as pd In [3]: df = pd.read_csv("../data/pima-indians-diabetes.csv") In [28]: df.describe() # 데이터값이 이상한 부분이있다. Out[28]: Preg Plas Pres skin test mass pedi age class count 768.000000 768.000000 768.000000 768.000000 768.000000 768.000000 768.000000 768.000000 768.000000 mean 3.845052 120.894531 69.105469 20.536458 79.799479 31.992578 0.471876 33.240885 0.348958 std 3.369578 3.. 2022. 12. 2.
Machine [supervised{Classification(Logisticregression)}] In [1]: # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd In [2]: # 나이와 연봉으로 분석해서, 물건을 구매할지 안할지를 분류하자!! In [3]: df = pd.read_csv("../data/Social_Network_Ads.csv") In [4]: df.head() Out[4]: User ID Gender Age EstimatedSalary Purchased 0 15624510 Male 19 19000 0 1 15810944 Male 35 20000 0 2 15668575 Female 26 43000 0 3 15603246 Female 27 57000 0 4 158.. 2022. 12. 2.
Machine 예측 모델 실습, 배포를 위한 저장 In [260]: import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.preprocessing import OneHotEncoder from sklearn.compose import ColumnTransformer from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression In [244]: df=pd.read_csv("../data/auto-mpg.csv") In [245]: df.head(2) Out[245]: mpg cyl displ hp weight accel yr origin .. 2022. 12. 1.
Machine Multiple Linear Regression In [1]: # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd 50_Startups.csv 데이터를 읽으세요.¶각각의 피쳐를 분석하여, 어떤 신생 회사의 데이터가 있으면, 그 회사가 얼마의 수익을 낼 지 예측합니다. (투자를 해야 할지 말아야 할지)¶ In [3]: df = pd.read_csv("../data/50_Startups.csv") In [4]: df Out[4]: R&D Spend Administration Marketing Spend State Profit 0 165349.20 136897.80 471784.10 New York 192261.83 1 162597.70.. 2022. 12. 1.
Machine [supervised{Prediction(Linear Regression)}] In [1]: # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd 'Salary_Data.csv' 를 읽으세요.¶경력과 연봉의 관계 분석을 통해, 누군가 입사했을 때, 그사람의 경력에 맞는 연봉을 제시해 줄 수 있도록 합니다.¶ In [2]: df = pd.read_csv("../data/Salary_Data.csv") In [3]: df Out[3]: YearsExperience Salary 0 1.1 39343.0 1 1.3 46205.0 2 1.5 37731.0 3 2.0 43525.0 4 2.2 39891.0 5 2.9 56642.0 6 3.0 60150.0 7 3.2 5444.. 2022. 12. 1.
Machine preprocessing, Feature Scaling, Dataset Training & Test Feature Scaling¶ Age 와 Salary 는 같은 스케일이 아니다.¶Age 는 27 ~ 50 Salary 는 40k ~ 90k In [59]: # 유클리디언 디스턴스로 오차를 줄여 나가는데, 하나의 변수는 오차가 크고, 하나의 변수는 오차가 작으면, 나중에 오차를 수정할때 편중되게 된다. # 따라서 값의 레인지를 맞춰줘야 정확히 트레이닝 된다. Feature Scaling 2가지 방법¶ 표준화 : 평균을 기준으로 얼마나 떨어져 있느냐? 같은 기준으로 만드는 방법, 음수도 존재, 데이터의 최대최소값 모를때 사용. 정규화 : 0 ~ 1 사이로 맞추는 것. 데이터의 위치 비교가 가능, 데이터의 최대최소값 알떄 사용 In [74]: from sklearn.preprocessing import Sta.. 2022. 12. 1.
Machine 원핫 인코딩 (One Hot Encoding) In [51]: # 2. 원 핫 인코딩 하는 방법 In [37]: X Out[37]: Country Age Salary 0 France 44.0 72000.0 1 Spain 27.0 48000.0 2 Germany 30.0 54000.0 3 Spain 38.0 61000.0 5 France 35.0 58000.0 7 France 48.0 79000.0 8 Germany 50.0 83000.0 9 France 37.0 67000.0 In [53]: # 원핫 인코딩으로 바꾸고 싶은 컬럼의 인덱스를 써준다. # [0] 이라고 써준다. # 만약에, 원핫 인코딩으로 바꾸고 싶은 컬럼이 여러개이면 # 리스트안에 인덱스만 써주면 된다. 예) [1, 4, 5] ct = ColumnTransformer( [ ("enco.. 2022. 12. 1.
Machine 레이블인코딩(Label Encoding) sklearn 설치¶아나콘다에 설치되어 있으며, 만약 설치가 안되었으면 다음으로 설치함 $ conda install -c conda-forge scikit-learn In [1]: In [ ]: import library¶ In [2]: # Data Preprocessing Template # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd import the dataset¶ In [4]: df = pd.read_csv("../data/Data.csv") In [5]: df Out[5]: Country Age Salary Purchased 0 France 44.0 72000.0 No .. 2022. 12. 1.