0% found this document useful (0 votes)
9 views8 pages

GT Innovative

The report discusses the use of machine learning, specifically the Random Forest algorithm, to predict soil moisture levels using environmental data. It highlights the importance of soil moisture in various fields and presents a model that effectively captures data patterns, demonstrating its utility for agricultural management and water conservation. Future work aims to enhance the model's accuracy by incorporating real-world datasets and optimizing algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

GT Innovative

The report discusses the use of machine learning, specifically the Random Forest algorithm, to predict soil moisture levels using environmental data. It highlights the importance of soil moisture in various fields and presents a model that effectively captures data patterns, demonstrating its utility for agricultural management and water conservation. Future work aims to enhance the model's accuracy by incorporating real-world datasets and optimizing algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

RV COLLEGE OF ENGINEERING ®

Mysore Road. RV Vidyaniketan Post, Bengaluru – 560059, Karnataka, India

GEOTECHNICAL ENGINEERING
(21CV63)

An Innovative Learning Report

Topic:

Predicting Soil Moisture Using Machine Learning

Submitted by
SIDDHARTHA THUKRAL – 1RV21CV099

Dr Venugopal
Assistant Professor
Department Of Civil Engineering

RV COLLEGE OF ENGINEERING ®
Bengaluru - 560059
(Autonomous Institution Affiliated to Visvesvaraya Technological University, Belagavi)
RV COLLEGE OF ENGINEERING®,
(Autonomous Institution Affiliated to Visvesvaraya Technological University, Belagavi)
Department of Civil Engineering
Bengaluru – 560059

CERTIFICATE
Certified that the report titled “Predicting Soil Moisture Using Machine Learning” carried out by
SIDDHARTHA THUKRAL (1RV21CV099) bonafide students, submitted for the Experiential
learning in GEOTECHNICAL MANAGEMENT during the year 2024-25. It is certified that all
corrections/ suggestions indicated for internal assessment have been incorporated in the report. The
report has been approved as it satisfies the academic requirement in Experiential Learning.

Dr Venugopal

Assistant Professor

Department of Civil Engineering


TABLE OF CONTENTS

1. Introduction

2.Key Definitions

3.Objectives

4.Code

5.Explanation

6.Output

7.Conclusion

8.Future Work

9.References
INTRODUCTION
Soil moisture is a critical parameter in various fields such as agriculture, hydrology, environmental science,
and geotechnical engineering. It affects plant growth, irrigation management, soil erosion, and overall
ecosystem health. Accurate prediction of soil moisture can help optimize agricultural practices, conserve
water, and prevent soil degradation.

Traditional methods for measuring soil moisture, such as using soil moisture sensors, can be expensive, time-
consuming, and limited to specific locations. With advancements in technology, artificial intelligence (AI)
and machine learning (ML) offer new, efficient, and cost-effective ways to predict soil moisture using readily
available environmental data. This report focuses on using a Random Forest algorithm, a popular ML
technique, to predict soil moisture levels based on various factors like temperature, humidity, precipitation,
soil type, and bulk density.

KEY DEFINITIONS
Soil Moisture: The amount of water present in the soil, usually expressed as a percentage of the total volume
or mass of the soil. It is a vital indicator for irrigation management and plant health.

Random Forest Algorithm: An ensemble machine learning method for classification and regression that
constructs multiple decision trees during training. The final output is determined by averaging the predictions
from all individual trees, which helps reduce overfitting and improve model accuracy.

Machine Learning: A subset of artificial intelligence that involves training computers to learn from data and
make decisions or predictions without being explicitly programmed for each specific task.

OBJECTIVES OF PROJECT
The main objective of this project is to use machine learning, specifically the Random Forest algorithm, to
predict soil moisture levels using environmental data (such as temperature, humidity, and precipitation). By
developing a model that can accurately estimate soil moisture, we aim to provide a practical tool that can assist
in agriculture, environmental monitoring, and water management.

CODE
Below is the Python code used to predict soil moisture levels using the Random Forest algorithm:

# Step 1: Import necessary libraries

import pandas as pd

import numpy as np

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestRegressor

from sklearn.metrics import mean_squared_error, r2_score


import matplotlib.pyplot as plt

# Step 2: Generate a synthetic dataset

np.random.seed(42) # For reproducibility

# Number of samples

n_samples = 1000

# Features affecting soil moisture

temperature = np.random.uniform(10, 40, n_samples) # in degrees Celsius

humidity = np.random.uniform(20, 100, n_samples) # in percentage

precipitation = np.random.uniform(0, 50, n_samples) # in mm

soil_type = np.random.randint(0, 3, n_samples) # 0: sandy, 1: clayey, 2: loamy

bulk_density = np.random.uniform(1.0, 1.8, n_samples) # in g/cm^3

# Synthetic soil moisture levels (target variable)

soil_moisture = (0.3 * temperature) + (0.5 * humidity) + (0.2 * precipitation) - (10 * soil_type) +


np.random.normal(0, 5, n_samples)

# Create a DataFrame

data = pd.DataFrame({

'Temperature': temperature,

'Humidity': humidity,

'Precipitation': precipitation,

'Soil_Type': soil_type,

'Bulk_Density': bulk_density,

'Soil_Moisture': soil_moisture

})

# Display the first few rows of the dataset

print(data.head())

# Step 3: Preprocess the data and split into training and test sets

X = data[['Temperature', 'Humidity', 'Precipitation', 'Soil_Type', 'Bulk_Density']]

y = data['Soil_Moisture']
# Split the data into training and testing sets (80% train, 20% test)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

print("Training set size:", X_train.shape)

print("Testing set size:", X_test.shape)

# Step 4: Train the Random Forest model

model = RandomForestRegressor(n_estimators=100, random_state=42)

model.fit(X_train, y_train)

# Step 5: Make predictions and evaluate the model

y_pred = model.predict(X_test)

mse = mean_squared_error(y_test, y_pred)

r2 = r2_score(y_test, y_pred)

print("Mean Squared Error (MSE):", mse)

print("R-squared (R2) Score:", r2)

# Step 6: Visualize the results

plt.figure(figsize=(8, 6))

plt.scatter(y_test, y_pred, color='blue', alpha=0.6)

plt.xlabel('Actual Soil Moisture')

plt.ylabel('Predicted Soil Moisture')

plt.title('Actual vs Predicted Soil Moisture')

plt.grid(True)

plt.show()

EXPLANATION

Step 1: Importing Libraries


This step imports essential libraries such as pandas for data manipulation, numpy for numerical operations, scikit-
learn for machine learning, and matplotlib for visualization.

Step 2: Generating Synthetic Data


A synthetic dataset is created with 1000 samples. Each sample contains features such as temperature, humidity,
precipitation, soil type, and bulk density. The target variable is soil moisture, which is calculated using a linear
combination of the features plus some added noise to simulate real-world variability.

Step 3: Data Preprocessing and Splitting


The dataset is split into training (80%) and testing (20%) sets. This step is crucial for evaluating the model's
performance on unseen data, which helps in avoiding overfitting.

Step 4: Training the Model


A Random Forest Regressor model is initialized and trained using the training data (X_train and y_train). The
n_estimators parameter is set to 100, indicating the number of decision trees in the forest.

Step 5: Making Predictions and Evaluating the Model


The model makes predictions on the test set (X_test). The performance is evaluated using Mean Squared Error (MSE)
and R-squared (R2) score. Lower MSE and higher R2 values indicate better model performance.

Step 6: Visualizing the Results


A scatter plot is created to visualize the predicted soil moisture values against the actual values. Ideally, the points
should lie close to the diagonal line, indicating that the model's predictions are accurate. findings suggest that the
dynamic adjustment of NPK ratios is essential for maximizing plant growth and yield. The implementation of these
findings can vary depending on several factors:

OUTPUT
CONCLUSION
Using the Random Forest algorithm, we developed a machine learning model to predict soil moisture levels
effectively. The model's performance, as indicated by the MSE and R2 score, shows that it can capture the
underlying patterns in the data. By leveraging readily available environmental data, this model provides a
valuable tool for agricultural management, environmental monitoring, and efficient water usage planning.
Future work can focus on using real-world datasets and applying advanced techniques for feature selection
and hyperparameter tuning to further enhance model accuracy.

FUTURE WORK
Data Collection: Incorporate real-world datasets from field sensors or satellite data to improve model
accuracy.

Model Optimization: Experiment with different algorithms (e.g., Gradient Boosting, Neural Networks) and
optimize hyperparameters for enhanced performance.

Feature Expansion: Include additional relevant features, such as soil temperature, wind speed, and solar
radiation, to improve the prediction model.

REFERENCES
1.Scikit-learn Documentation: https://scikit-learn.org/

2.Machine Learning in Agriculture: Articles and research papers on the application of machine learning in
predicting soil moisture.

You might also like