vault backup: 2025-03-02 21:07:59
This commit is contained in:
21
01.00. - Me/🏪 訂閱.md
Normal file
21
01.00. - Me/🏪 訂閱.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
tags:
|
||||||
|
aliases:
|
||||||
|
date: 2025-03-02
|
||||||
|
time: 20:48:27
|
||||||
|
description:
|
||||||
|
---
|
||||||
|
|
||||||
|
# 目前訂閱
|
||||||
|
- Apple Music, $320
|
||||||
|
- Netflix, $420
|
||||||
|
|
||||||
|
|
||||||
|
# 考慮訂閱
|
||||||
|
- Felo
|
||||||
|
- Grok
|
||||||
|
- ChatGPT
|
||||||
|
- Kagi
|
||||||
|
|
||||||
|
|
||||||
|
# 參考來源
|
||||||
@@ -13,7 +13,7 @@ description:
|
|||||||
# 今日發生什麼事?
|
# 今日發生什麼事?
|
||||||
想要擺脫手機的想法愈來愈大,可是又覺得沒辦法完全擺脫,感覺會變成脫節的人、古板的人,先讓自己一天看幾次手機就好。
|
想要擺脫手機的想法愈來愈大,可是又覺得沒辦法完全擺脫,感覺會變成脫節的人、古板的人,先讓自己一天看幾次手機就好。
|
||||||
|
|
||||||
想要買 Makita [[🤷♂️想買的東西#DCF301|DCF301]],就覺得出門在外的時候可以用,可是真的有那麼需要嗎?我的買買病感覺又發作了。
|
想要買 Makita [[🤷♂️ 想買的東西#DCF301|DCF301]],就覺得出門在外的時候可以用,可是真的有那麼需要嗎?我的買買病感覺又發作了。
|
||||||
|
|
||||||
|
|
||||||
# 有什麼想法?
|
# 有什麼想法?
|
||||||
|
|||||||
173
21.01. Programming/Python/Write a Package.md
Normal file
173
21.01. Programming/Python/Write a Package.md
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
---
|
||||||
|
tags:
|
||||||
|
aliases:
|
||||||
|
date: 2025-03-02
|
||||||
|
time: 20:53:47
|
||||||
|
description:
|
||||||
|
---
|
||||||
|
|
||||||
|
# Project Structure
|
||||||
|
```
|
||||||
|
mlpredictor/
|
||||||
|
│
|
||||||
|
├── mlpredictor/
|
||||||
|
│ ├── __init__.py
|
||||||
|
│ ├── model.py
|
||||||
|
│
|
||||||
|
├── tests/
|
||||||
|
│ ├── test_model.py
|
||||||
|
│
|
||||||
|
├── LICENSE
|
||||||
|
├── README.md
|
||||||
|
├── pyproject.toml
|
||||||
|
└── .gitignore
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Content of `setup.py`
|
||||||
|
```
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='mypackage',
|
||||||
|
version='0.1',
|
||||||
|
packages=['mypackage'],
|
||||||
|
install_requires=['requests'])
|
||||||
|
```
|
||||||
|
|
||||||
|
## Content of `pyproject.toml`
|
||||||
|
```toml
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=42", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "mlpredictor"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "A simple machine learning package using scikit-learn"
|
||||||
|
authors = [
|
||||||
|
{name = "Ebrahim", email = "ebimsv0501@gmail.com"}
|
||||||
|
]
|
||||||
|
license = {text = "MIT"}
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.6"
|
||||||
|
dependencies = [
|
||||||
|
"scikit-learn>=1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
"Homepage" = "https://github.com/ebimsv/mlpredictor"
|
||||||
|
```
|
||||||
|
- **[build-system]**: Specifies the build system requirements (i.e., using `setuptools` and `wheel`).
|
||||||
|
- **[project]**: Contains metadata about the package, like name, version, description, and dependencies.
|
||||||
|
|
||||||
|
|
||||||
|
## Content of `README.md`
|
||||||
|
<pre><code>
|
||||||
|
# MLPredictor
|
||||||
|
|
||||||
|
MLPredictor is a simple machine learning package that trains a RandomForest model using the Iris dataset and enables users to make predictions. The package is built using `scikit-learn` and is intended as a demonstration of packaging Python machine learning projects for distribution.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Train a RandomForestClassifier on the Iris dataset.
|
||||||
|
- Make predictions on new data after training.
|
||||||
|
- Save and load trained models.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
You can install the package via **PyPI** or from **source**.
|
||||||
|
|
||||||
|
### Install from PyPI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install mlpredictor
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install from Source (GitHub)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/ebimsv/mlpredictor.git
|
||||||
|
cd mlpredictor
|
||||||
|
pip install .
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
After installation, you can use `MLPredictor` to train a model and make predictions.
|
||||||
|
|
||||||
|
### Example: Training and Making Predictions
|
||||||
|
|
||||||
|
```python
|
||||||
|
from mlpredictor import MLPredictor
|
||||||
|
|
||||||
|
# Initialize the predictor
|
||||||
|
predictor = MLPredictor()
|
||||||
|
|
||||||
|
# Train the model on the Iris dataset
|
||||||
|
predictor.train()
|
||||||
|
|
||||||
|
# Make a prediction on a sample input
|
||||||
|
sample_input = [5.1, 3.5, 1.4, 0.2]
|
||||||
|
prediction = predictor.predict(sample_input)
|
||||||
|
|
||||||
|
print(f"Predicted class: {prediction}")
|
||||||
|
```
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
## Content of `.gitignore`
|
||||||
|
```
|
||||||
|
*.pyc
|
||||||
|
__pycache__/
|
||||||
|
*.pkl
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Test
|
||||||
|
## Content of `tests/test_model.py`
|
||||||
|
```python
|
||||||
|
import pytest
|
||||||
|
from mlpredictor import MLPredictor
|
||||||
|
|
||||||
|
def test_train_and_predict():
|
||||||
|
model = MLPredictor()
|
||||||
|
model.train()
|
||||||
|
result = model.predict([5.1, 3.5, 1.4, 0.2])
|
||||||
|
assert len(result) == 1
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pytest.main()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run test
|
||||||
|
```bash
|
||||||
|
pytest tests
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Install
|
||||||
|
## Test locally
|
||||||
|
```
|
||||||
|
pip install .
|
||||||
|
```
|
||||||
|
|
||||||
|
## Publish on PyPI
|
||||||
|
1. **Install 'Twine' and 'build'**:
|
||||||
|
```
|
||||||
|
pip install twine build
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Build the Package**:
|
||||||
|
```
|
||||||
|
python -m build
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Upload to PyPI**
|
||||||
|
```
|
||||||
|
twine upload dist/*
|
||||||
|
```
|
||||||
|
|
||||||
|
# 參考來源
|
||||||
|
- [Building Python Packages. A Comprehensive Guide to setup.py and… | by Ebrahim Mousavi | Medium](https://medium.com/@ebimsv/building-python-packages-07fbfbb959a9)
|
||||||
Reference in New Issue
Block a user