ํ์ต ๋ชฉํ
ํ์ต ์ ์
pip install scikit-learn
pip install matplotlib
petal์ ๊ฝ์, sepal์ ๊ฝ๋ฐ์นจ
# sklearn ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ datasets ํจํค์ง ์ load_iris๋ฅผ import
# iris ๋ฐ์ดํฐ๋ฅผ ๋ก๋ฉ
from sklearn.datasets import load_iris
iris = load_iris()
print(dir(iris)) # iris ๊ฐ์ฒด๊ฐ ์ด๋ค ๋ณ์์ ๋ฉ์๋๋ฅผ ๊ฐ์ง๊ณ ์๋
# dir()๋ ๊ฐ์ฒด๊ฐ ์ด๋ค ๋ณ์์ ๋ฉ์๋๋ฅผ ๊ฐ์ง๊ณ ์๋์ง ๋์ดํจ
['DESCR', 'data', 'data_module', 'feature_names', 'filename', 'frame', 'target', 'target_names']
# iris์๋ ์ด๋ค ์ ๋ณด๋ค์ด ๋ด๊ฒผ์์ง, keys() ๋ผ๋ ๋ฉ์๋๋ก ํ์ธ
iris.keys()
dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename', 'data_module'])
7๊ฐ์ง : 'data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename'
->>data_module ์???
# ์ค์ํ ๋ฐ์ดํฐ๋ iris_data ๋ณ์์ ์ ์ฅ
iris_data = iris.data
print(iris_data.shape)
#shape๋ ๋ฐฐ์ด์ ํ์์ ๋ณด๋ฅผ ์ถ๋ ฅ
(150, 4)
- 150๊ฐ ๋ฐ์ดํฐ
- 4์ข ๋ฅ์ ์ ๋ณด
iris_data[0] # 0๋ฒ index์ ์ ๊ทผๆฅ่ฟ
array([5.1, 3.5, 1.4, 0.2])
๋ถ๊ฝ์ ๊ฝ์ ๊ธธ์ด์ ํญ / ๊ฝ๋ฐ์นจ ๊ธธ์ด์ ํญ ์ด์ฉ
๋ถ๊ฝ์ ์ข ๋ฅ๊ฐ setosa, versicolor, virginica ์ธ ๊ฐ์ง ์ค ๋ฌด์์ธ์ง.
iris_label = iris.target # iris_label ๋ณ์์ ํ๊ฒ์ ๋ณด ์ ์ฅ
print(iris_label.shape) # ๋ณ์ ํฌ๊ธฐ ์ถ๋ ฅ
iris_label #
(150,)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
# ๋ผ๋ฒจ์ ์ด๋ฆ์ target_names์์ ํ์ธ
iris.target_names
array(['setosa', 'versicolor', 'virginica'], dtype='<U10')
- 0 ์ด๋ผ๋ฉด setosa,
- 1 ์ด๋ผ๋ฉด versicolor,
- 2 ๋ผ๋ฉด virginica
print(iris.DESCR) # DESCR์๋ ๋ฐ์ดํฐ์
์ ์ค๋ช
.. _iris_dataset:
Iris plants dataset
--------------------
**Data Set Characteristics:**
:Number of Instances: 150 (50 in each of three classes)
:Number of Attributes: 4 numeric, predictive attributes and the class
:Attribute Information:
- sepal length in cm
- sepal width in cm
- petal length in cm
- petal width in cm
- class:
- Iris-Setosa
- Iris-Versicolour
- Iris-Virginica
:Summary Statistics:
============== ==== ==== ======= ===== ====================
Min Max Mean SD Class Correlation
============== ==== ==== ======= ===== ====================
sepal length: 4.3 7.9 5.84 0.83 0.7826
sepal width: 2.0 4.4 3.05 0.43 -0.4194
petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)
petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)
============== ==== ==== ======= ===== ====================
:Missing Attribute Values: None
:Class Distribution: 33.3% for each of 3 classes.
:Creator: R.A. Fisher
:Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
:Date: July, 1988
The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken
from Fisher's paper. Note that it's the same as in R, but not as in the UCI
Machine Learning Repository, which has two wrong data points.
This is perhaps the best known database to be found in the
pattern recognition literature. Fisher's paper is a classic in the field and
is referenced frequently to this day. (See Duda & Hart, for example.) The
data set contains 3 classes of 50 instances each, where each class refers to a
type of iris plant. One class is linearly separable from the other 2; the
latter are NOT linearly separable from each other.
.. topic:: References
- Fisher, R.A. "The use of multiple measurements in taxonomic problems"
Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions to
Mathematical Statistics" (John Wiley, NY, 1950).
- Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.
(Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.
- Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System
Structure and Classification Rule for Recognition in Partially Exposed
Environments". IEEE Transactions on Pattern Analysis and Machine
Intelligence, Vol. PAMI-2, No. 1, 67-71.
- Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule". IEEE Transactions
on Information Theory, May 1972, 431-433.
- See also: 1988 MLC Proceedings, 54-64. Cheeseman et al"s AUTOCLASS II
conceptual clustering system finds 3 classes in the data.
- Many, many more ...
# feature_names์๋ ๋ค์๊ณผ ๊ฐ์ด 4๊ฐ์ ๊ฐ feature์ ๋ํ ์ค๋ช
iris.feature_names
['sepal length (cm)',
'sepal width (cm)',
'petal length (cm)',
'petal width (cm)']
# filename์๋ ๋ฐ์ดํฐ์
์ ์ ์ฒด ์ด๋ฆ
iris.filename
'iris.csv'
csv ํ์ผ์ด๊ตฐ...
pandas = pd = ํ๋ค์ค
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- ํ์ด์ฌ์์ ํ ํํ๋ก ์ด๋ฃจ์ด์ง 2์ฐจ์ ๋ฐฐ์ด ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃจ๋ ๋ฐ์ ๊ฐ์ฅ ๋ง์ด ์ฐ์ด๋ ๋๊ตฌ
- ํ ๋ฐ์ดํฐ๋ฅผ ํ์ฉํด์ ๋ฐ์ดํฐ ๋ถ์
- ๋ํ ๋ฐ์ดํฐ์ ์ฌ๋ฌ ํต๊ณ๋์ ๋ค๋ฃจ๋ ๊ฒ์ ์ต์ ํ
import pandas as pd
print(pd.__version__)
1.3.5
# ๋ถ๊ฝ ๋ฐ์ดํฐ์
์ pandas๊ฐ ์ ๊ณตํ๋ DataFrame ์ด๋ผ๋ ์๋ฃํ์ผ๋ก ๋ณํ
iris_df = pd.DataFrame(data=iris_data, columns=iris.feature_names)
# iris_df
# DataFrame ์ ๋ง๋ค๋ฉด์ data์๋ iris_data๋ฅผ ๋ฃ์ด์ฃผ๊ณ , ๊ฐ ์ปฌ๋ผ์๋ feature_names๋ก ์ด๋ฆ์ ๋ถ์ฌ์ค
# label ์ปฌ๋ผ ์ถ๊ฐ
iris_df["label"] = iris.target
iris_df
sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | label | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | 0 |
1 | 4.9 | 3.0 | 1.4 | 0.2 | 0 |
2 | 4.7 | 3.2 | 1.3 | 0.2 | 0 |
3 | 4.6 | 3.1 | 1.5 | 0.2 | 0 |
4 | 5.0 | 3.6 | 1.4 | 0.2 | 0 |
... | ... | ... | ... | ... | ... |
145 | 6.7 | 3.0 | 5.2 | 2.3 | 2 |
146 | 6.3 | 2.5 | 5.0 | 1.9 | 2 |
147 | 6.5 | 3.0 | 5.2 | 2.0 | 2 |
148 | 6.2 | 3.4 | 5.4 | 2.3 | 2 |
149 | 5.9 | 3.0 | 5.1 | 1.8 | 2 |
150 rows ร 5 columns
4๊ฐ์ง์ feature ๋ฐ์ดํฐ๋ค์ ๋ฐ๋ก ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ด ํ์ด์ผ ํ๋ ๋ฌธ์ ์ง
-> [5.1, 3.5, 1.4, 0.2]๋ผ๋ ๋ฌธ์ ๊ฐ ์ฃผ์ด์ง๋ค๋ฉด ๋ชจ๋ธ์ 0, ์ฆ setosa๋ผ๋ ๋ต์ ๋งํ์ผ ํ๋ ๊ฒ
label ๋ฐ์ดํฐ๋ ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์๊ฒ ์ ๋ต์ง
-> 0, 1, 2์ ๊ฐ์ด ํํ๋ label ๋ฐ์ดํฐ
๋ฌธ์ ์ง :
- ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์๊ฒ ์ ๋ ฅ๋๋ ๋ฐ์ดํฐ.
- feature๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํจ.
- ๋ณ์ ์ด๋ฆ์ผ๋ก๋ X๋ฅผ ๋ง์ด ์ฌ์ฉ.
์ ๋ต์ง :
- ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ด ๋งํ์ผ ํ๋ ๋ฐ์ดํฐ.
- label ๋๋ target์ด๋ผ๊ณ ๋ถ๋ฆ.
- ๋ณ์ ์ด๋ฆ์ผ๋ก๋ y๋ฅผ ๋ง์ด ์ฌ์ฉ
- sklearn.model_selection ํจํค์ง์ train_test_split์ ํ์ฉ
- training dataset๊ณผ test dataset์ ๋ถ๋ฆฌ
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris_data,
# iris_data๋ ๋ฌธ์ ์ง : feature
iris_label,
# ๋ง์ถฐ์ผ ํ ์ ๋ต๊ฐ : Label(3๊ฐ์ง์ค)
test_size=0.2,
# test dataset์ ํฌ๊ธฐ๋ฅผ ์กฐ์ : ์ ์ฒด์ 20%๋ง ํ
์คํธ๋ฐ์ดํฐ๋ก ์ฌ์ฉ
random_state=7)
# train ๋ฐ์ดํฐ์ test ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฆฌ(split)ํ๋๋ฐ ์ ์ฉ๋๋ ๋๋ค์ฑ
print('X_train ๊ฐ์: ', len(X_train),', X_test ๊ฐ์: ', len(X_test))
X_train ๊ฐ์: 120 , X_test ๊ฐ์: 30
# X_train๋ถํฐ y_test๊น์ง ๋ง๋ค์ด์ง ๋ฐ์ดํฐ์
์ ํ์ธ
X_train.shape, y_train.shape
((120, 4), (120,))
X_test.shape, y_test.shape
((30, 4), (30,))
20%์ ๋ฐ์ดํฐ๋ test ๋ฐ์ดํฐ์
๋๋จธ์ง 80%์ ๋ฐ์ดํฐ๋ train ๋ฐ์ดํฐ์
y_train, y_test
(array([2, 1, 0, 2, 1, 0, 0, 0, 0, 2, 2, 1, 2, 2, 1, 0, 1, 1, 2, 0, 0, 0,
2, 0, 2, 1, 1, 1, 0, 0, 0, 1, 2, 1, 1, 0, 2, 0, 0, 2, 2, 0, 2, 0,
1, 2, 1, 0, 1, 0, 2, 2, 1, 0, 0, 1, 2, 0, 2, 2, 1, 0, 1, 0, 2, 2,
0, 0, 2, 1, 2, 2, 1, 0, 0, 2, 0, 0, 1, 2, 2, 1, 1, 0, 2, 0, 0, 1,
1, 2, 0, 1, 1, 2, 2, 1, 2, 0, 1, 1, 0, 0, 0, 1, 1, 0, 2, 2, 1, 2,
0, 2, 1, 1, 0, 2, 1, 2, 1, 0]),
array([2, 1, 0, 1, 2, 0, 1, 1, 0, 1, 1, 1, 0, 2, 0, 1, 2, 2, 0, 0, 1, 2,
1, 2, 2, 2, 1, 1, 2, 2]))
๋ถ๊ฝ์
Supervised Learning / Classification
# Decision Tree๋ sklearn.tree ํจํค์ง ์์ DecisionTreeClassifier ๋ผ๋ ์ด๋ฆ์ผ๋ก ๋ด์ฅ
from sklearn.tree import DecisionTreeClassifier
# ๋ชจ๋ธ์ importํด์ ๊ฐ์ ธ์ค๊ณ , decision_tree ๋ผ๋ ๋ณ์์ ๋ชจ๋ธ์ ์ ์ฅ
decision_tree = DecisionTreeClassifier(random_state=32)
print(decision_tree._estimator_type)
classifier
์ ๊ฒฐ๊ณผ์ ์๋ฏธ๋?
๋ชจ๋ธ ํ์ต์ ์ฐ๋ฆฌ๊ฐ ์ค๋นํด ๋ X_train ์ y_train ๋ฐ์ดํฐ๋ก
๋ค์ ํ ์ค์ด๋ฉด ์๋ฃ
decision_tree.fit(X_train, y_train)
#๋ชจ๋ธ ํ์ต์ ์ํค๊ธฐ ์ํด ์ค๋นํด๋ X_train y_train๋ก ์์ฌ๊ฒฐ์ ๋๋ฌด์ fit
DecisionTreeClassifier(random_state=32)
test ๋ฐ์ดํฐ๋ก ์์ธก
y_pred = decision_tree.predict(X_test)
y_pred
array([2, 1, 0, 1, 2, 0, 1, 1, 0, 1, 2, 1, 0, 2, 0, 2, 2, 2, 0, 0, 1, 2,
1, 1, 2, 2, 1, 1, 2, 2])
X_test ๋ฐ์ดํฐ์๋ ์ ๋ต์ธ label์ด ์๊ณ feature ๋ฐ์ดํฐ๋ง ์กด์ฌ
ํ์ต์ด ์๋ฃ๋ decision_tree ๋ชจ๋ธ์
X_test ๋ฐ์ดํฐ๋ก predict๋ฅผ ์คํํ๋ฉด
๋ชจ๋ธ์ด ์์ธกํ y_pred์ ์ป๊ฒ ๋จ
๋ชจ๋ธ์ ์ด 30๊ฐ์ ๋ฐ์ดํฐ์ ๋ํด
array([2, 1, 0, 1, 2, 0, 1, 1, 0, 1, 2, 1, 0, 2, 0, 2, 2, 2, 0, 0, 1, 2,
1, 1, 2, 2, 1, 1, 2, 2])๋ผ๋ ์์ธก ๊ฒฐ๊ณผ
์ค์ ์ ๋ต์ธ y_test์ ๋น๊ตํด์ ์ผ๋ง๋ ๋ง์๋์ง ํ์ธ
y_test
array([2, 1, 0, 1, 2, 0, 1, 1, 0, 1, 1, 1, 0, 2, 0, 1, 2, 2, 0, 0, 1, 2,
1, 2, 2, 2, 1, 1, 2, 2])
์์๋ณด๊ธฐ ํ๋ฆ ใ ใ
์ฝ๊ฒ ๋น๊ตํ๋ ๋ฐฉ๋ฒ์
scikit-learn์์ ์ฑ๋ฅ ํ๊ฐ์ ๋ํ ํจ์๋ค์ด ๋ชจ์ฌ์๋ sklearn.metrics ํจํค์ง๋ฅผ ์ด์ฉ
# ์ฑ๋ฅ์ ํ๊ฐํ๋ ๋ค์ํ ์ฒ๋ ์ค ์ ํ๋(Accuracy) ํ์ธ
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_test, y_pred)
accuracy
0.9
0.9๋ ์์น๋ 90% ์ ๋์ ์ ํ๋
# ์ ๋ด์ฉ ์ ๋ฆฌ
# (1) ํ์ํ ๋ชจ๋ import
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import classification_report
# (2) ๋ฐ์ดํฐ ์ค๋น
iris = load_iris()
iris_data = iris.data
iris_label = iris.target
# (3) train, test ๋ฐ์ดํฐ ๋ถ๋ฆฌ
X_train, X_test, y_train, y_test = train_test_split(iris_data,
iris_label,
test_size=0.2,
random_state=7)
# (4) ๋ชจ๋ธ ํ์ต ๋ฐ ์์ธก -> ๋ชจ๋ธ์ ๋ฐ๊พธ๊ณ ์ถ์ ๋ ๋ณ๊ฒฝํ๋ ๋ถ๋ถ
decision_tree = DecisionTreeClassifier(random_state=32)
decision_tree.fit(X_train, y_train)
y_pred = decision_tree.predict(X_test)
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 1.00 1.00 1.00 7
1 0.91 0.83 0.87 12
2 0.83 0.91 0.87 11
accuracy 0.90 30
macro avg 0.91 0.91 0.91 30
weighted avg 0.90 0.90 0.90 30
# Random Forest๋ sklearn.ensemble ํจํค์ง ๋ด
from sklearn.ensemble import RandomForestClassifier
X_train, X_test, y_train, y_test = train_test_split(iris_data,
iris_label,
test_size=0.2,
random_state=21)
random_forest = RandomForestClassifier(random_state=32)
random_forest.fit(X_train, y_train)
y_pred = random_forest.predict(X_test)
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 1.00 1.00 1.00 11
1 1.00 0.83 0.91 12
2 0.78 1.00 0.88 7
accuracy 0.93 30
macro avg 0.93 0.94 0.93 30
weighted avg 0.95 0.93 0.93 30
2 ์ฐจ์ ๊ณต๊ฐ์์, ์ฆ ๋ฐ์ดํฐ์ 2๊ฐ์ ํด๋์ค๋ง ์กด์ฌํ ๋,
Margin์ด ๋์์๋ก ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ์ ๊ตฌ๋ถํ ์ ์๋ค. (Margin ์ต๋ํ -> robustness ์ต๋ํ)
from sklearn import svm
svm_model = svm.SVC()
print(svm_model._estimator_type)
classifier
# ๋ถ๊ฝ์ ์ฝ๋๋ฅผ ์ ์ฉ
svm_model.fit(X_train, y_train)
y_pred = svm_model.predict(X_test)
print(classification_report(y_test, y_pred))
# ์๋๋ decision_tree
# decision_tree = DecisionTreeClassifier(random_state=32)
# decision_tree.fit(X_train, y_train)
# y_pred = decision_tree.predict(X_test)
# print(classification_report(y_test, y_pred))
precision recall f1-score support
0 1.00 1.00 1.00 11
1 0.91 0.83 0.87 12
2 0.75 0.86 0.80 7
accuracy 0.90 30
macro avg 0.89 0.90 0.89 30
weighted avg 0.91 0.90 0.90 30
<์ต์๊ฐ์ ์ฐพ๋ ๊ณผ์ >
๋ฐฐ์น
์์ฒญ๋ ๋ฐ์ดํฐ ์
๋ง์ฝ์ ํจ์ฌ ์ ์ ๊ณ์ฐ์ผ๋ก ์ ์ ํ ๊ธฐ์ธ๊ธฐ๋ฅผ ์ป์ ์ ์๋ค๋ฉด?
from sklearn.linear_model import SGDClassifier
sgd_model = SGDClassifier()
print(sgd_model._estimator_type)
# ์ฐธ๊ณ SVM ์ฌ์ฉ๋ฒ
from sklearn import svm
svm_model = svm.SVC()
print(svm_model._estimator_type)
# SVM ์ ์ฉ ์
svm_model.fit(X_train, y_train)
y_pred = svm_model.predict(X_test)
print(classification_report(y_test, y_pred))
# Tree ์ฌ์ฉ๋ฒ
from sklearn.tree import DecisionTreeClassifier
decision_tree = DecisionTreeClassifier(random_state=32)
print(decision_tree._estimator_type)
#Tree ์ ์ฉ ์
decision_tree = DecisionTreeClassifier(random_state=32)
decision_tree.fit(X_train, y_train)
y_pred = decision_tree.predict(X_test)
print(classification_report(y_test, y_pred))
File "/tmp/ipykernel_379/2372895087.py", line 8
from sklearn import svm
^
IndentationError: unexpected indent
# ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์ ์ ์ฉ ์
sgd_model.fit(X_train, y_train)
y_pred = sgd_model.predict(X_test)
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 1.00 1.00 1.00 11
1 1.00 0.92 0.96 12
2 0.88 1.00 0.93 7
accuracy 0.97 30
macro avg 0.96 0.97 0.96 30
weighted avg 0.97 0.97 0.97 30
# ์ ์ฉ์ ๋ต์
sgd_model.fit(X_train, y_train)
y_pred = sgd_model.predict(X_test)
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 1.00 1.00 1.00 11
1 0.86 1.00 0.92 12
2 1.00 0.71 0.83 7
accuracy 0.93 30
macro avg 0.95 0.90 0.92 30
weighted avg 0.94 0.93 0.93 30
์ํํธ๋งฅ์ค ํจ์
from sklearn.linear_model import LogisticRegression
logistic_model = LogisticRegression()
print(logistic_model._estimator_type)
# ์ฐธ๊ณ SGD ์ฌ์ฉ๋ฒ
from sklearn.linear_model import SGDClassifier
sgd_model = SGDClassifier()
print(sgd_model._estimator_type)
# SDG ์ ์ฉ ์
sgd_model.fit(X_train, y_train)
y_pred = sgd_model.predict(X_test)
print(classification_report(y_test, y_pred))
# ์ฐธ๊ณ SVM ์ฌ์ฉ๋ฒ
from sklearn import svm
svm_model = svm.SVC()
print(svm_model._estimator_type)
# SVM ์ ์ฉ ์
svm_model.fit(X_train, y_train)
y_pred = svm_model.predict(X_test)
print(classification_report(y_test, y_pred))
# Tree ์ฌ์ฉ๋ฒ
from sklearn.tree import DecisionTreeClassifier
decision_tree = DecisionTreeClassifier(random_state=32)
print(decision_tree._estimator_type)
#Tree ์ ์ฉ ์
decision_tree = DecisionTreeClassifier(random_state=32)
decision_tree.fit(X_train, y_train)
y_pred = decision_tree.predict(X_test)
print(classification_report(y_test, y_pred))
File "<tokenize>", line 22
from sklearn import svm
^
IndentationError: unindent does not match any outer indentation level
# ์ ์ฉ ์
# ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์
logistic_model.fit(X_train, y_train)
y_pred = logistic_model.predict(X_test)
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 1.00 1.00 1.00 11
1 1.00 0.83 0.91 12
2 0.78 1.00 0.88 7
accuracy 0.93 30
macro avg 0.93 0.94 0.93 30
weighted avg 0.95 0.93 0.93 30
ํจ์ ์ ์ฌ๋ก
from sklearn.datasets import load_digits
digits = load_digits()
digits.keys()
dict_keys(['data', 'target', 'frame', 'feature_names', 'target_names', 'images', 'DESCR'])
digits ๋ผ๋ ๋ณ์์ ์๊ธ์จ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๊ณ , ๊ทธ ์์๋ iris ๋ฐ์ดํฐ์ ๋๊ฐ์ด ๋ช ๊ฐ์ง์ ์ ๋ณด
# ๊ฐ์ฅ ์ค์ํ data๋ฅผ ๋จผ์ ํ์ธ
digits_data = digits.data
digits_data.shape
(1797, 64)
๋ฐ์ดํฐ๋ ์ด 1,797๊ฐ,
๊ฐ ๋ฐ์ดํฐ๋ 64๊ฐ์ ์ซ์.
# 1,797๊ฐ์ ๋ฐ์ดํฐ ์ค ์ฒซ ๋ฒ์งธ ๋ฐ์ดํฐ๋ฅผ ์ํ๋ก ํ์ธ
digits_data[0]
array([ 0., 0., 5., 13., 9., 1., 0., 0., 0., 0., 13., 15., 10.,
15., 5., 0., 0., 3., 15., 2., 0., 11., 8., 0., 0., 4.,
12., 0., 0., 8., 8., 0., 0., 5., 8., 0., 0., 9., 8.,
0., 0., 4., 11., 0., 1., 12., 7., 0., 0., 2., 14., 5.,
10., 12., 0., 0., 0., 0., 6., 13., 10., 0., 0., 0.])
์์๋๋ก 64๊ฐ์ ์ซ์๋ก ์ด๋ฃจ์ด์ง ๋ฐฐ์ด(array)์ด ์ถ๋ ฅ
์ซ์๋ ์ด๋ค ์๋ฏธ๊ฐ ์์๊น์?
์๊ธ์จ ๋ฐ์ดํฐ๋ ์ด๋ฏธ์ง ๋ฐ์ดํฐ. -> ๊ฐ ์ซ์๋ ํฝ์
๊ฐ ์๋ฏธ
๊ธธ์ด 64์ ์ซ์ ๋ฐฐ์ด์ ์ฌ์ค (8 x 8) ํฌ๊ธฐ์ ์ด๋ฏธ์ง๋ฅผ ์ผ๋ ฌ๋ก ์ญ ํด๋์ ๊ฒ
์ด๋ฏธ์ง๋ฅผ ๋ณด๊ธฐ ์ํด์๋ matplotlib์ด๋ผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ์.
matplotlib.pyplot์ plt๋ผ๋ ์ด๋ฆ์ผ๋ก ๊ฐ์ ธ์ค๊ณ ,
์ด๋ฏธ์ง๋ฅผ ํ์ฌ ํ๋ฉด์ ๋ณด์ฌ์ฃผ๊ธฐ ์ํด
%matplotlib inline์ด๋ผ๋ ์ฝ๋๋ฅผ ์ถ๊ฐ
# ์ผ๋ ฌ๋ก ํด์ง 64๊ฐ ๋ฐ์ดํฐ๋ฅผ (8, 8)๋ก reshape
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(digits.data[0].reshape(8, 8), cmap='gray')
plt.axis('off')
plt.show()
# ์ฌ๋ฌ ๊ฐ์ ์ด๋ฏธ์ง๋ฅผ ํ ๋ฒ์ ํ์ธ
for i in range(10):
plt.subplot(2, 5, i+1)
plt.imshow(digits.data[i].reshape(8, 8), cmap='gray')
plt.axis('off')
plt.show()
# target ๋ฐ์ดํฐ๋?
digits_label = digits.target
print(digits_label.shape)
digits_label[:20]
(1797,)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
์ด 1,797๊ฐ์ ๋ฐ์ดํฐ๊ฐ ์๊ณ , 0๋ถํฐ 9๊น์ง์ ์ซ์๋ก ๋ํ๋จ.
๋ฐ๋ก ๊ฐ ์ด๋ฏธ์ง ๋ฐ์ดํฐ๊ฐ ์ด๋ค ์ซ์๋ฅผ ๋ํ๋ด๋์ง๋ฅผ ๋ด๊ณ ์๋ ๋ฐ์ดํฐ
๋ถ๊ฝ ๋ฌธ์ ์ ๊ฐ์ด,
๊ฐ ์ด๋ฏธ์ง ๋ฐ์ดํฐ๊ฐ ์
๋ ฅ๋์์ ๋
๊ทธ ์ด๋ฏธ์ง๊ฐ ์ซ์ ๋ช์ ๋ํ๋ด๋
์ด๋ฏธ์ง์ธ์ง๋ฅผ ๋ง์ถ๋ ๋ถ๋ฅ ๋ชจ๋ธ์ ํ์ต
์ ํ๋์ ํจ์ ์ ํ์ธํ๋ ์คํ์ด๊ธฐ ๋๋ฌธ์ ์ฝ๊ฐ์ ์ฅ์น๋ฅผ ๋ฃ์ด๋ณผ ๊ฒ
->์ซ์ 10๊ฐ๋ฅผ ๋ชจ๋ ๋ถ๋ฅํ๋ ๊ฒ์ด ์๋๋ผ,
ํด๋น ์ด๋ฏธ์ง ๋ฐ์ดํฐ๊ฐ 3์ธ์ง ์๋์ง๋ฅผ ๋งํ๋ ๋ฌธ์ ๋ก ๋ณํํด์ ํ์ด๋ณด๋ ๊ฒ
# target์ธ digits_label์ ์๋์ ๊ฐ์ด ์ด์ง ๋ณํ
# label์ธ digits_label์์ ์ซ์๊ฐ 3์ด๋ผ๋ฉด ๊ทธ๋๋ก 3์, ์๋๋ผ๋ฉด 0์ ๊ฐ์ง๋ new_label
new_label = [3 if i == 3 else 0 for i in digits_label]
new_label[:20]
[0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0]
digits_data์ new_label๋ก Decision Tree ๋ชจ๋ธ์ ํ์ต, ์ ํ๋๋ฅผ ํ์ธ
# ์ฐธ๊ณ ๋ถ๊ฝ์ ์
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris_data,
# iris_data๋ ๋ฌธ์ ์ง : feature
iris_label,
# ๋ง์ถฐ์ผ ํ ์ ๋ต๊ฐ : Label(3๊ฐ์ง์ค)
test_size=0.2,
# test dataset์ ํฌ๊ธฐ๋ฅผ ์กฐ์ : ์ ์ฒด์ 20%๋ง ํ
์คํธ๋ฐ์ดํฐ๋ก ์ฌ์ฉ
random_state=7)
# train ๋ฐ์ดํฐ์ test ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฆฌ(split)ํ๋๋ฐ ์ ์ฉ๋๋ ๋๋ค์ฑ
print('X_train ๊ฐ์: ', len(X_train),', X_test ๊ฐ์: ', len(X_test))
X_train ๊ฐ์: 120 , X_test ๊ฐ์: 30
from sklearn.metrics import accuracy_score # ์ ํ๋ ํ์ธ ๋ชจ๋
from sklearn.model_selection import train_test_split #
from sklearn.tree import DecisionTreeClassifier # Decision Tree Model
X_train, X_test, y_train, y_test = train_test_split(digits_data, # digits_data ๋ผ๋ ๋ฌธ์ ์ง
new_label, # ๋ง์ถฐ์ผํ ์ ๋ถ๊ฐ
test_size=0.2, # ์ ์ฒด์ 20%๋ง ํ
์คํธ๋ฐ์ดํฐ๋ก ์ฌ์ฉ
random_state=15) # train ๋ฐ์ดํฐ์ test ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฆฌ(split)ํ๋๋ฐ ์ ์ฉ๋๋ ๋๋ค์ฑ
decision_tree = DecisionTreeClassifier(random_state=15) #๋ํธ๋ฆฌ
decision_tree.fit(X_train, y_train) #๋ํธ๋ฆฌ๋ชจ๋ธ Fit
y_pred = decision_tree.predict(X_test) #๋ํธ๋ฆฌ๋ชจ๋ธ ํ
์คํธ๋ก ์์ธก
accuracy = accuracy_score(y_test, y_pred) #์ ํ๋ ์ค์ฝ์ด ํ
์คํธ์ ์์ธก๊ฐ ๋น๊ต
accuracy #๊ฐ์
0.9388888888888889
# ๊ธธ์ด๋ y_pred์ ๊ฐ์ผ๋ฉด์ 0์ผ๋ก๋ง ์ด๋ฃจ์ด์ง ๋ฆฌ์คํธ๋ฅผ fake_pred๋ผ๋ ๋ณ์๋ก ์ ์ฅํด ๋ณด๊ณ ,
# ์ด ๋ฆฌ์คํธ์ ์ค์ ์ ๋ต์ธ y_test๊ฐ์ ์ ํ๋๋ฅผ ํ์ธ.
fake_pred = [0] * len(y_pred)
accuracy = accuracy_score(y_test, fake_pred)
accuracy
0.925
์ ๋ต์ ๋ชจ๋ 0์ผ๋ก๋ง ์ ํํด๋ ์ ํ๋๊ฐ 90%๊ฐ๋์ด ๋์ค๊ฒ ๋๋ค๋ ๊ฒ
์ด๋ฌํ ๋ฌธ์ ๋ ๋ถ๊ท ํํ ๋ฐ์ดํฐ, unbalanced ๋ฐ์ดํฐ์์ ์์ฃผ ๋ฐ์ํ ์ ์์
์ฆ ์ ํ๋๋ ์ ๋ต์ ๋ถํฌ์ ๋ฐ๋ผ ๋ชจ๋ธ์ ์ฑ๋ฅ์ ์ ํ๊ฐํ์ง ๋ชปํ๋ ์ฒ๋๊ฐ ๋ ์ ์๋ ๊ฒ
What is Confusion Matrix and Advanced Classification Metrics?
์ค์ฐจ ํ๋ ฌ์์๋ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๋ค ๊ฐ์ง๋ก ๊ตฌ๋ถ
- TN(True Negative), FP(False Positive), FN(False Negative), TP(True Positive)
์ค์ฐจ ํ๋ ฌ์์ ๋ํ๋๋ ์ฑ๋ฅ ์งํ๋ฅผ ๋ค์ฏ ๊ฐ์ง
- Precision, Negative Predictive Value, Sensitivity, Specificity, Accuracy
TP, FN, FP, TN์ ์์น๋ก ๊ณ์ฐ๋๋ ์ฑ๋ฅ ์งํ
Q17. ์ ์ฒด ๋ฉ์ผํจ์์ ์คํธ ๋ฉ์ผ์ ๊ฑฐ๋ฅด๋ ๋ชจ๋ธ์๊ฒ๋
Precision์ด ๋ ์ค์ํ ๊น์, Recall์ด ๋ ์ค์ํ ๊น์?
(์คํธ ๋ฉ์ผ์ positive, ์ ์ ๋ฉ์ผ์ negative๋ก ์๊ฐํฉ๋๋ค)
์์๋ต์
๋ฉ์ผ ์ฒ๋ฆฌ ๋ชจ๋ธ์ ์คํธ ๋ฉ์ผ์ ๋ชป ๊ฑฐ๋ฅด๋ ๊ฒ์ ๊ด์ฐฎ์ง๋ง,
์ ์ ๋ฉ์ผ์ ์คํธ ๋ฉ์ผ๋ก ๋ถ๋ฅํ๋ ๊ฒ์ ๋ ํฐ ๋ฌธ์ ์ด๋ค.
์ฆ ์์ฑ์ ์์ฑ์ผ๋ก ํ๋จํ๋ฉด ์ ๋๋ค.
๋ฐ๋ผ์ Precision์ด ๋ ์ค์ํ๋ค.
์ค์ (Actual Class)์์ ๋ญ๊ฐ ๋ ์ฌ๊ฐํ๋. ๋ฌธ์ ๊ฐ ํฌ๋. ๋ญ๊ฐ ์ค์ํ๋
==>>>์ ์์ด ์ค์
์ค์ฐจ ํ๋ ฌ์ ๋ค์๊ณผ ๊ฐ์ด sklearn.metrics ํจํค์ง ๋ด์ confusion_matrix๋ก ํ์ธ
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, y_pred)
array([[320, 13],
[ 9, 18]])
์ผ์ชฝ ์๋ถํฐ ์์๋๋ก TPTP, FNFN, FPFP, TNTN์ ๊ฐ์
# ๋ชจ๋ ์ซ์๋ฅผ 0์ผ๋ก ์์ธกํ fake_pred์ ๊ฒฝ์ฐ
confusion_matrix(y_test, fake_pred)
array([[333, 0],
[ 27, 0]])
์๊ธ์จ ๊ฒฐ๊ณผ์ Precision, Recall, F1 score๋
sklearn.metrics์ classification_report๋ฅผ ํ์ฉ.
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 0.97 0.96 0.97 333
3 0.58 0.67 0.62 27
accuracy 0.94 360
macro avg 0.78 0.81 0.79 360
weighted avg 0.94 0.94 0.94 360
# fake_pred์ ๊ฒฝ์ฐ
print(classification_report(y_test, fake_pred, zero_division=0))
precision recall f1-score support
0 0.93 1.00 0.96 333
3 0.00 0.00 0.00 27
accuracy 0.93 360
macro avg 0.46 0.50 0.48 360
weighted avg 0.86 0.93 0.89 360
์ ํ๋๋ง์ผ๋ก ํ๋จํ์ง ๋ง๊ฒ.
๋ฐ์ดํฐ์ ์๊ฐ : ์ฌ์ดํท๋ฐ toy datasets
Toy Dataset ์ค ๋ถ๋ฅ ๋ฌธ์ ์ ์ ํฉํ ๋ฐ์ดํฐ์
load_digits : ์๊ธ์จ ์ด๋ฏธ์ง ๋ฐ์ดํฐ
load_wine : ์์ธ ๋ฐ์ดํฐ
load_breast_cancer : ์ ๋ฐฉ์ ๋ฐ์ดํฐ
# sklearn ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ datasets ํจํค์ง ์ load_$$$$๋ฅผ import
# $$$$ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ฉ
from sklearn.datasets import load_wine
print(wine.DESCR) # DESCR์๋ ๋ฐ์ดํฐ์
์ ์ค๋ช
.. _wine_dataset:
Wine recognition dataset
------------------------
**Data Set Characteristics:**
:Number of Instances: 178 (50 in each of three classes)
:Number of Attributes: 13 numeric, predictive attributes and the class
:Attribute Information:
- Alcohol
- Malic acid
- Ash
- Alcalinity of ash
- Magnesium
- Total phenols
- Flavanoids
- Nonflavanoid phenols
- Proanthocyanins
- Color intensity
- Hue
- OD280/OD315 of diluted wines
- Proline
- class:
- class_0
- class_1
- class_2
:Summary Statistics:
============================= ==== ===== ======= =====
Min Max Mean SD
============================= ==== ===== ======= =====
Alcohol: 11.0 14.8 13.0 0.8
Malic Acid: 0.74 5.80 2.34 1.12
Ash: 1.36 3.23 2.36 0.27
Alcalinity of Ash: 10.6 30.0 19.5 3.3
Magnesium: 70.0 162.0 99.7 14.3
Total Phenols: 0.98 3.88 2.29 0.63
Flavanoids: 0.34 5.08 2.03 1.00
Nonflavanoid Phenols: 0.13 0.66 0.36 0.12
Proanthocyanins: 0.41 3.58 1.59 0.57
Colour Intensity: 1.3 13.0 5.1 2.3
Hue: 0.48 1.71 0.96 0.23
OD280/OD315 of diluted wines: 1.27 4.00 2.61 0.71
Proline: 278 1680 746 315
============================= ==== ===== ======= =====
:Missing Attribute Values: None
:Class Distribution: class_0 (59), class_1 (71), class_2 (48)
:Creator: R.A. Fisher
:Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
:Date: July, 1988
This is a copy of UCI ML Wine recognition datasets.
https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data
The data is the results of a chemical analysis of wines grown in the same
region in Italy by three different cultivators. There are thirteen different
measurements taken for different constituents found in the three types of
wine.
Original Owners:
Forina, M. et al, PARVUS -
An Extendible Package for Data Exploration, Classification and Correlation.
Institute of Pharmaceutical and Food Analysis and Technologies,
Via Brigata Salerno, 16147 Genoa, Italy.
Citation:
Lichman, M. (2013). UCI Machine Learning Repository
[https://archive.ics.uci.edu/ml]. Irvine, CA: University of California,
School of Information and Computer Science.
.. topic:: References
(1) S. Aeberhard, D. Coomans and O. de Vel,
Comparison of Classifiers in High Dimensional Settings,
Tech. Rep. no. 92-02, (1992), Dept. of Computer Science and Dept. of
Mathematics and Statistics, James Cook University of North Queensland.
(Also submitted to Technometrics).
The data was used with many others for comparing various
classifiers. The classes are separable, though only RDA
has achieved 100% correct classification.
(RDA : 100%, QDA 99.4%, LDA 98.9%, 1NN 96.1% (z-transformed data))
(All results using the leave-one-out technique)
(2) S. Aeberhard, D. Coomans and O. de Vel,
"THE CLASSIFICATION PERFORMANCE OF RDA"
Tech. Rep. no. 92-01, (1992), Dept. of Computer Science and Dept. of
Mathematics and Statistics, James Cook University of North Queensland.
(Also submitted to Journal of Chemometrics).
# sklearn ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ datasets ํจํค์ง ์ load_$$$$๋ฅผ import
# $$$$ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ฉ
from sklearn.datasets import load_breast_cancer
breast_cancer = load_breast_cancer()
print(breast_cancer.DESCR) # DESCR์๋ ๋ฐ์ดํฐ์
์ ์ค๋ช
.. _breast_cancer_dataset:
Breast cancer wisconsin (diagnostic) dataset
--------------------------------------------
**Data Set Characteristics:**
:Number of Instances: 569
:Number of Attributes: 30 numeric, predictive attributes and the class
:Attribute Information:
- radius (mean of distances from center to points on the perimeter)
- texture (standard deviation of gray-scale values)
- perimeter
- area
- smoothness (local variation in radius lengths)
- compactness (perimeter^2 / area - 1.0)
- concavity (severity of concave portions of the contour)
- concave points (number of concave portions of the contour)
- symmetry
- fractal dimension ("coastline approximation" - 1)
The mean, standard error, and "worst" or largest (mean of the three
worst/largest values) of these features were computed for each image,
resulting in 30 features. For instance, field 0 is Mean Radius, field
10 is Radius SE, field 20 is Worst Radius.
- class:
- WDBC-Malignant
- WDBC-Benign
:Summary Statistics:
===================================== ====== ======
Min Max
===================================== ====== ======
radius (mean): 6.981 28.11
texture (mean): 9.71 39.28
perimeter (mean): 43.79 188.5
area (mean): 143.5 2501.0
smoothness (mean): 0.053 0.163
compactness (mean): 0.019 0.345
concavity (mean): 0.0 0.427
concave points (mean): 0.0 0.201
symmetry (mean): 0.106 0.304
fractal dimension (mean): 0.05 0.097
radius (standard error): 0.112 2.873
texture (standard error): 0.36 4.885
perimeter (standard error): 0.757 21.98
area (standard error): 6.802 542.2
smoothness (standard error): 0.002 0.031
compactness (standard error): 0.002 0.135
concavity (standard error): 0.0 0.396
concave points (standard error): 0.0 0.053
symmetry (standard error): 0.008 0.079
fractal dimension (standard error): 0.001 0.03
radius (worst): 7.93 36.04
texture (worst): 12.02 49.54
perimeter (worst): 50.41 251.2
area (worst): 185.2 4254.0
smoothness (worst): 0.071 0.223
compactness (worst): 0.027 1.058
concavity (worst): 0.0 1.252
concave points (worst): 0.0 0.291
symmetry (worst): 0.156 0.664
fractal dimension (worst): 0.055 0.208
===================================== ====== ======
:Missing Attribute Values: None
:Class Distribution: 212 - Malignant, 357 - Benign
:Creator: Dr. William H. Wolberg, W. Nick Street, Olvi L. Mangasarian
:Donor: Nick Street
:Date: November, 1995
This is a copy of UCI ML Breast Cancer Wisconsin (Diagnostic) datasets.
https://goo.gl/U2Uwz2
Features are computed from a digitized image of a fine needle
aspirate (FNA) of a breast mass. They describe
characteristics of the cell nuclei present in the image.
Separating plane described above was obtained using
Multisurface Method-Tree (MSM-T) [K. P. Bennett, "Decision Tree
Construction Via Linear Programming." Proceedings of the 4th
Midwest Artificial Intelligence and Cognitive Science Society,
pp. 97-101, 1992], a classification method which uses linear
programming to construct a decision tree. Relevant features
were selected using an exhaustive search in the space of 1-4
features and 1-3 separating planes.
The actual linear program used to obtain the separating plane
in the 3-dimensional space is that described in:
[K. P. Bennett and O. L. Mangasarian: "Robust Linear
Programming Discrimination of Two Linearly Inseparable Sets",
Optimization Methods and Software 1, 1992, 23-34].
This database is also available through the UW CS ftp server:
ftp ftp.cs.wisc.edu
cd math-prog/cpo-dataset/machine-learn/WDBC/
.. topic:: References
- W.N. Street, W.H. Wolberg and O.L. Mangasarian. Nuclear feature extraction
for breast tumor diagnosis. IS&T/SPIE 1993 International Symposium on
Electronic Imaging: Science and Technology, volume 1905, pages 861-870,
San Jose, CA, 1993.
- O.L. Mangasarian, W.N. Street and W.H. Wolberg. Breast cancer diagnosis and
prognosis via linear programming. Operations Research, 43(4), pages 570-577,
July-August 1995.
- W.H. Wolberg, W.N. Street, and O.L. Mangasarian. Machine learning techniques
to diagnose breast cancer from fine-needle aspirates. Cancer Letters 77 (1994)
163-171.
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn.datasets import load_digits
print(digits.DESCR)
.. _digits_dataset:
Optical recognition of handwritten digits dataset
--------------------------------------------------
**Data Set Characteristics:**
:Number of Instances: 1797
:Number of Attributes: 64
:Attribute Information: 8x8 image of integer pixels in the range 0..16.
:Missing Attribute Values: None
:Creator: E. Alpaydin (alpaydin '@' boun.edu.tr)
:Date: July; 1998
This is a copy of the test set of the UCI ML hand-written digits datasets
https://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Handwritten+Digits
The data set contains images of hand-written digits: 10 classes where
each class refers to a digit.
Preprocessing programs made available by NIST were used to extract
normalized bitmaps of handwritten digits from a preprinted form. From a
total of 43 people, 30 contributed to the training set and different 13
to the test set. 32x32 bitmaps are divided into nonoverlapping blocks of
4x4 and the number of on pixels are counted in each block. This generates
an input matrix of 8x8 where each element is an integer in the range
0..16. This reduces dimensionality and gives invariance to small
distortions.
For info on NIST preprocessing routines, see M. D. Garris, J. L. Blue, G.
T. Candela, D. L. Dimmick, J. Geist, P. J. Grother, S. A. Janet, and C.
L. Wilson, NIST Form-Based Handprint Recognition System, NISTIR 5469,
1994.
.. topic:: References
- C. Kaynak (1995) Methods of Combining Multiple Classifiers and Their
Applications to Handwritten Digit Recognition, MSc Thesis, Institute of
Graduate Studies in Science and Engineering, Bogazici University.
- E. Alpaydin, C. Kaynak (1998) Cascading Classifiers, Kybernetika.
- Ken Tang and Ponnuthurai N. Suganthan and Xi Yao and A. Kai Qin.
Linear dimensionalityreduction using relevance weighted LDA. School of
Electrical and Electronic Engineering Nanyang Technological University.
2005.
- Claudio Gentile. A New Approximate Maximal Margin Classification
Algorithm. NIPS. 2000.
load_digits ๋ฉ์๋
digits = load_digits()
sklearn.metrics ์์ ์ ๊ณตํ๋ ํ๊ฐ์งํ