반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- tensorflow
- web 개발
- inorder
- web 사진
- broscoding
- C언어
- mglearn
- 머신러닝
- CES 2O21 참여
- CES 2O21 참가
- paragraph
- 대이터
- Keras
- bccard
- 결합전문기관
- pycharm
- web
- postorder
- html
- classification
- 재귀함수
- 웹 용어
- cudnn
- 자료구조
- web 용어
- java역사
- vscode
- discrete_scatter
- KNeighborsClassifier
- 데이터전문기관
Archives
- Today
- Total
bro's coding
sklearn.naive_bayes.BernoulliNB 본문
반응형
- 있다/없다 처럼 이진 속성을 가지고 속성이 아주 많은 경우 : BernoulliNB
- 이진 속성이 아닌 일반적인 연속값 속성을 가지는 데이터 : GaussianNB
import numpy as np
from sklearn.naive_bayes import BernoulliNB
X = np.random.randint(2, size=(6, 100))
#y = np.array([1, 2, 3, 4, 4, 5])
y = np.array([1, 0, 0, 1, 1, 0])
model = BernoulliNB()
model.fit(X, y)
pred_y = model.predict(X)
print(pred_y)
# [1 0 0 1 1 0]
X
'''
array([[0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0,
1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0,
0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0,
1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1],
[0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,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1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0,
0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1,
0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1],
[1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1,
1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1,
0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1,
1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1,
0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0]])
'''
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.naive_bayes import BernoulliNB, GaussianNB, MultinomialNB
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target)
# model = BernoulliNB()
model = GaussianNB()
# model = MultinomialNB()
model.fit(X_train, y_train)
train_score = model.score(X_train, y_train)
test_score = model.score(X_test, y_test)
display(train_score, test_score)
# 0.9436619718309859
# 0.9090909090909091
import mglearn
X_train, X_test, y_train, y_test = train_test_split(cancer.data[:,[0,1]], cancer.target)
model = GaussianNB()
model.fit(X_train, y_train)
print(model.score(X_test, y_test))
mglearn.plots.plot_2d_classification(model, X_train)
mglearn.discrete_scatter(X_train[:,0], X_train[:,1], y_train)
#plt.show()
from sklearn.linear_model import LogisticRegression
X_train, X_test, y_train, y_test = train_test_split(cancer.data[:,[0,1]], cancer.target)
model = LogisticRegression()
model.fit(X_train, y_train)
print(model.score(X_test, y_test))
mglearn.plots.plot_2d_classification(model, X_train)
mglearn.discrete_scatter(X_train[:,0], X_train[:,1], y_train)
반응형
'[AI] > python.sklearn' 카테고리의 다른 글
sklearn.PCA(2)를 이용한 digit data visualization (0) | 2020.04.23 |
---|---|
sklearn.datasets.load_digits (0) | 2020.04.23 |
sklearn.decomposition.PCA.picture.recover (0) | 2020.04.22 |
sklearn.datasets.fetch_lfw_people (0) | 2020.04.22 |
sklearn.ensemble .GradientBoostingClassifier (0) | 2020.04.21 |
sklearn.decomposition.PCA.dimension(30->2) (0) | 2020.04.21 |
sklearn.decomposition.PCA.dimension(4->2) (0) | 2020.04.21 |
sklearn.decomposition.PCA.visualization (0) | 2020.04.21 |
Comments