products:ict:python:machine_learning:light_gbm
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| products:ict:python:machine_learning:light_gbm [2023/10/12 17:28] – created wikiadmin | products:ict:python:machine_learning:light_gbm [2023/10/12 17:30] (current) – wikiadmin | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| 1. **Installation**: | 1. **Installation**: | ||
| - | You can install LightGBM using pip: | + | You can install LightGBM using pip: |
| + | |||
| + | pip install lightgbm | ||
| - | | ||
| - | pip install lightgbm | ||
| - | ``` | ||
| 2. **Importing LightGBM**: | 2. **Importing LightGBM**: | ||
| - | Once installed, you can import LightGBM in your Python script or Jupyter Notebook: | + | Once installed, you can import LightGBM in your Python script or Jupyter Notebook: |
| + | |||
| + | |||
| + | import lightgbm as lgb | ||
| - | | ||
| - | | ||
| - | ``` | ||
| 3. **Data Preparation**: | 3. **Data Preparation**: | ||
| - | Before you can use LightGBM, you need to prepare your data. LightGBM works with tabular data, and it expects the data to be in a format that is compatible with the `Dataset` object provided by the library. | + | Before you can use LightGBM, you need to prepare your data. LightGBM works with tabular data, and it expects the data to be in a format that is compatible with the `Dataset` object provided by the library. |
| - Load and preprocess your dataset using libraries like Pandas and NumPy. | - Load and preprocess your dataset using libraries like Pandas and NumPy. | ||
| Line 27: | Line 26: | ||
| 4. **Creating a Dataset**: | 4. **Creating a Dataset**: | ||
| - | To efficiently use LightGBM, you need to create a `Dataset` object from your data. This object is optimized for training and prediction. | + | To efficiently use LightGBM, you need to create a `Dataset` object from your data. This object is optimized for training and prediction. |
| + | |||
| + | |||
| + | train_data = lgb.Dataset(data=X_train, | ||
| + | test_data = lgb.Dataset(data=X_test, | ||
| - | | ||
| - | | ||
| - | | ||
| - | ``` | ||
| 5. **Setting Parameters**: | 5. **Setting Parameters**: | ||
| - | LightGBM has a wide range of parameters that control the training process and the model' | + | LightGBM has a wide range of parameters that control the training process and the model' |
| - | - `objective`: | + | - `objective`: |
| - | - `num_leaves`: | + | |
| - | - `learning_rate`: | + | |
| - | - `max_depth`: | + | |
| - | - `num_boost_round`: | + | |
| - | - `metric`: Evaluation metric for model performance. | + | |
| - | You can set these parameters in a dictionary and pass it to the training process. | + | - `num_leaves`: |
| + | |||
| + | - `learning_rate`: | ||
| + | |||
| + | - `max_depth`: | ||
| + | |||
| + | - `num_boost_round`: | ||
| + | |||
| + | - `metric`: Evaluation metric for model performance. | ||
| + | |||
| + | You can set these parameters in a dictionary and pass it to the training process. | ||
| 6. **Training the Model**: | 6. **Training the Model**: | ||
| - | To train the LightGBM model, you use the `train` method, passing in your training data and the parameter dictionary: | + | To train the LightGBM model, you use the `train` method, passing in your training data and the parameter dictionary: |
| - | | ||
| - | | ||
| - | bst = lgb.train(params, | ||
| - | ``` | ||
| - | The `early_stopping_rounds` parameter allows the training to stop early if the evaluation metric doesn' | + | num_round = 100 |
| + | bst = lgb.train(params, | ||
| + | |||
| + | |||
| + | The `early_stopping_rounds` parameter allows the training to stop early if the evaluation metric doesn' | ||
| 7. **Making Predictions**: | 7. **Making Predictions**: | ||
| - | After training, you can use the trained model to make predictions on new data: | + | After training, you can use the trained model to make predictions on new data: |
| + | |||
| + | |||
| + | predictions = bst.predict(X_new_data) | ||
| - | | ||
| - | | ||
| - | ``` | ||
| 8. **Model Evaluation**: | 8. **Model Evaluation**: | ||
| - | Evaluate the model' | + | Evaluate the model' |
| 9. **Hyperparameter Tuning**: | 9. **Hyperparameter Tuning**: | ||
| - | It's common to perform hyperparameter tuning to find the best set of parameters for your specific problem. Techniques like grid search or random search can be used. | + | It's common to perform hyperparameter tuning to find the best set of parameters for your specific problem. Techniques like grid search or random search can be used. |
| 10. **Deployment**: | 10. **Deployment**: | ||
| - | | + | Once you're satisfied with the model' |
| LightGBM' | LightGBM' | ||
products/ict/python/machine_learning/light_gbm.1697113699.txt.gz · Last modified: 2023/10/12 17:28 by wikiadmin