---
# System prepended metadata

title: sklearn

---

# sklearn
#### 照著圖表走來選擇要用的算法
![](https://i.imgur.com/jIjdxTm.png)
遇到data依據流程去找適合的model
#### 各種類型和其相對適合的方法
![](https://i.imgur.com/F9Kq9MN.png)


#### 練習一個分類器
導入模塊（用花的）
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
創建數據
iris = datasets.load_iris()
iris_X = iris.data
iris_y = iris.target
分割數據
X_train, X_test, y_train, y_test = train_test_split(iris_X, iris_y, test_size=0.3)
用KNeighbors來訓練
knn = KNeighborsClassifier()
knn.fit(X_train, y_train)
預測（test x對test y做比對）
knn.predict(X_test)
#### sklearn 可以用來練習的data set
https://scikit-learn.org/stable/datasets/index.html
#### preprocesssing
有時候遇到的data可能很差，可以做ex. normalization的資料處理讓其準確率提高很多
https://morvanzhou.github.io/tutorials/machine-learning/sklearn/3-1-normalization/
還有很多種方法
https://scikit-learn.org/stable/modules/preprocessing.html
#### 對model進行evaluation
sklearn的cross validation可以看出model及其參數對這個r結構準確度的影響
https://scikit-learn.org/stable/modules/cross_validation.html
## 之後在遇到問題可以來這裡尋求解答
https://scikit-learn.org/stable/user_guide.html



