Download task_units/task_127/workspace/machine_learning.py from lhpku20010120/WorkSurface-Build: direct link, hf CLI and curl.
- Browser
- Download file 562 Bytes
-
https://huggingface.co/datasets/lhpku20010120/WorkSurface-Build/resolve/main/task_units/task_127/workspace/machine_learning.py
- Command line
-
hf download hf://datasets/lhpku20010120/WorkSurface-Build/task_units/task_127/workspace/machine_learning.py
-
curl -L -o machine_learning.py https://huggingface.co/datasets/lhpku20010120/WorkSurface-Build/resolve/main/task_units/task_127/workspace/machine_learning.py
562 Bytes
| # -*- coding: utf-8 -*- | |
| """Machine learning: scikit-learn, torch""" | |
| from sklearn.datasets import load_iris | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.ensemble import RandomForestClassifier | |
| import torch | |
| # scikit-learn example | |
| iris = load_iris() | |
| X, y = iris.data, iris.target | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) | |
| clf = RandomForestClassifier() | |
| clf.fit(X_train, y_train) | |
| print("sklearn accuracy:", clf.score(X_test, y_test)) | |
| # PyTorch example | |
| x = torch.tensor([1.0, 2.0, 3.0]) | |
| print("pytorch tensor:", x) |