Views
No views yet
1from huggingface_hub import hf_hub_download
2import joblib
3import pandas as pd
4
5# Download the model file from the Hugging Face hub
6model_path = hf_hub_download(repo_id="DNgigi/NPKRecommendation", filename="ModelV2.joblib")
7
8# Load the trained model
9model = joblib.load(model_path)
10
11# Example input data
12new_data = {
13 'Crop Name': 'coffee',
14 'Target Yield': 1200.0,
15 'Field Size': 1.0,
16 'pH (water)': 5.76,
17 'Organic Carbon': 12.9,
18 'Total Nitrogen': 1.1,
19 'Phosphorus (M3)': 1.2,
20 'Potassium (exch.)': 1.7,
21 'Soil moisture': 11.4
22}
23
24# Preprocess the input data
25input_df = pd.DataFrame([new_data])
26
27# Ensure the same columns as in training
28input_df = pd.get_dummies(input_df, columns=['Crop Name'])
29# Assuming X is your feature set used during training
30for col in X.columns:
31 if col not in input_df.columns:
32 input_df[col] = 0
33
34# Make predictions
35predictions = model.predict(input_df)
36
37print("Predicted nutrient needs:")
38print(predictions)
39