Views
No views yet
mltrev23/Rice-classification dataset. The model is designed to predict the type of rice grain based on various geometric and morphological features. XGBoost (eXtreme Gradient Boosting) is a powerful, efficient, and scalable machine learning algorithm that excels at handling structured data.mltrev23/Rice-classification dataset.
Area, MajorAxisLength, MinorAxisLength, Eccentricity, ConvexArea, EquivDiameter, Extent, Perimeter, Roundness, and AspectRation.Class, a binary label indicating the type of rice grain.1pip install xgboost
2pip install pandas
3pip install numpy
4pip install scikit-learn1import xgboost as xgb
2
3# Load the trained model
4model = xgb.Booster()
5model.load_model('rice_classification_xgboost.model')1import pandas as pd
2
3# Example input data (replace with your actual data)
4data = pd.DataFrame({
5 'Area': [4537, 2872],
6 'MajorAxisLength': [92.23, 74.69],
7 'MinorAxisLength': [64.01, 51.40],
8 'Eccentricity': [0.72, 0.73],
9 'ConvexArea': [4677, 3015],
10 'EquivDiameter': [76.00, 60.47],
11 'Extent': [0.66, 0.71],
12 'Perimeter': [273.08, 208.32],
13 'Roundness': [0.76, 0.83],
14 'AspectRation': [1.44, 1.45]
15})
16
17# Convert DataFrame to DMatrix for XGBoost
18dtest = xgb.DMatrix(data)
19
20# Predict class
21predictions = model.predict(dtest)1from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
2
3# Assuming you have ground truth labels and predictions
4y_true = [1, 0] # Replace with your actual labels
5y_pred = predictions.round() # XGBoost predictions may need to be rounded
6
7print("Accuracy:", accuracy_score(y_true, y_pred))
8print("Precision:", precision_score(y_true, y_pred))
9print("Recall:", recall_score(y_true, y_pred))
10print("F1 Score:", f1_score(y_true, y_pred))1import matplotlib.pyplot as plt
2
3# Plot feature importance
4xgb.plot_importance(model)
5plt.show()mltrev23/Rice-classification