- Machine Learning with Swift
- Alexander Sosnovshchenko
- 144字
- 2021-06-24 18:54:56
Splitting the data
Finally, we want to split our data into training and test sets. We will train our classifier only on the training set, so it will never see the test set until we want to evaluate its performance. This is a very important step, because as we will see in the future, the quality of predictions on the test set can differ dramatically from the quality measured on the training set. Data splitting is an operation specific to machine learning tasks, so we will import scikit-learn (a machine learning package) and use some functions from it:
In []: from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.3, random_state=42) X_train.shape, y_train.shape, X_test.shape, y_test.shape Out[]: ((700, 6), (700,), (300, 6), (300,))
Now we have 700 training samples with 6 features each, and 300 test samples with the same number of features.
推薦閱讀
- Raspberry Pi 3 Cookbook for Python Programmers
- Applied Unsupervised Learning with R
- 嵌入式技術基礎與實踐(第5版)
- 計算機組裝·維護與故障排除
- Unity 5.x Game Development Blueprints
- 單片機原理及應用系統設計
- 微軟互聯網信息服務(IIS)最佳實踐 (微軟技術開發者叢書)
- SiFive 經典RISC-V FE310微控制器原理與實踐
- 超大流量分布式系統架構解決方案:人人都是架構師2.0
- Blender Quick Start Guide
- Spring Cloud微服務和分布式系統實踐
- Neural Network Programming with Java(Second Edition)
- 無蘋果不生活:OS X Mountain Lion 隨身寶典
- 基于網絡化教學的項目化單片機應用技術
- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide