Commit f2f25046 authored by Karunarathna K.M.D.Y.K's avatar Karunarathna K.M.D.Y.K

Merge branch 'IT19983202' into 'master'

It19983202

See merge request !5
parents 5d53e813 9f8e68bc
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*-
"""time_series_model_builder.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1AWprgehWA_xbBKM_Lr1rWc6wv2BxIhAZ
##Class
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
plt.style.use('fivethirtyeight')
import xgboost as xgb
from sklearn.metrics import mean_squared_error
class TimeSeriesModel:
def __init__(self , dataset_link , model_name):
self.dataset_link = dataset_link
self.model_name = model_name
self.train_test_split_date = '2021-08.-01'
self.feature_dataframes = {}
self.feature_train_dataframes = {}
self.features_test_dataframes = {}
self.train = None
self.test = None
self.ts_models = {}
self.model_x_tests = {}
print(" =========== {} Object Instantiated ===========".format(self.model_name))
def set_details(self , split_date):
'''
Provide the Date in format YYYY-MM-DD as a String
Example :- '2021-08.-01'
'''
self.train_test_split_date = split_date
def read_data_to_df(self):
import pandas as pd
df = tempDF = pd.read_excel(self.dataset_link)
self.df = df
print(" =========== Data Stored In a Pandas DataFrame ===========)")
print(" Number of Rows --> {}".format(df.shape[0]))
print(" Number of Columns --> {}".format(df.shape[1]))
def handle_invalid_values(self):
'''Convert all No Numeric Values to Nan '''
import pandas as pd
for column in self.df.columns[1:]:
self.df[column] = pd.to_numeric(self.df[column] , errors = 'coerce')
print(" =========== Non Numeric Values Set to Nan ===========")
def handle_Null_values(self , method = "fillMean"):
'''
AVAILABLE METHODS :-
dropna - emoves any rows that contain missing or null values.
fillMean - fill with the mean values
ffil - fills the missing values with the last non-NA/null value in the column
bfill - fills the missing values with the next non-NA/null value in the column,
'''
print(" =========== handling Null Values - Started ===========")
print("Applying For Columns -->" , end=" | ")
for colname in self.df.columns:
print(colname , end=" | ")
if(method=="dropna"):
print("Dropping rows with Null Values")
self.df[colname] = self.df[colname].dropna()
elif(method=="fillMean"):
self.df[colname] = self.df[colname].fillna(self.df[colname].mean())
pass
elif(method=="ffill"):
self.df[colname] = self.df[colname].ffill()
elif(method=="bfill"):
self.df[colname] = self.df[colname].bfill()
elif(method=="fill0"):
self.df[colname] = self.df[colname].fillna(0)
else:
print(" ************ SOMETHING WENT WRONG ************")
print("\n=========== handling Null Values - Completed ===========")
return self.df.isnull().sum()
def convert_to_time_series(self):
self.df[self.df.columns[0]] = pd.to_datetime(self.df[self.df.columns[0]], format='%m/%d/%Y')
self.df = self.df.set_index(self.df.columns[0])
self.df = self.df.sort_index()
self.df = self.df.astype('float')
self.df.tail(2)
print(" =========== DataFrame Converted to a Time Series")
def view_past_data(self , district = "Kalpitiya"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
plt.style.use('fivethirtyeight')
self.df[district].plot(style='.',
figsize=(15, 5),
color=color_pal[0],
title='{} Data'.format(district))
plt.show()
def perform_train_test_split(self):
split_date = self.train_test_split_date
self.train = self.df.loc[self.df.index < split_date]
self.test = self.df.loc[self.df.index >= split_date]
print("=========== Time Series Splited as Train and Test datasets ===========")
def plot_train_test_split(self , district = "Kalpitiya"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
fig, ax = plt.subplots(figsize=(15, 5))
self.train[district].plot(ax=ax, label='Training Set', title='Data Train/Test Split')
self.test[district].plot(ax=ax, label='Test Set')
ax.axvline(self.train_test_split_date, color='black', ls='--')
ax.legend(['Training Set', 'Test Set'])
plt.show()
def plot_week_data(self, starts_from , district = "Kalpitiya"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
end_date = pd.date_range(start=starts_from, periods=7+1, freq='D', closed='right')[-1]
print(end_date)
self.df[district].loc[(self.df.index >= starts_from) & (self.df.index < end_date)] \
.plot(figsize=(15, 5), title='Week Of Data')
plt.show()
def create_features(self , tempDf , trainOrTest = "train"):
"""
Create time series features based on time series index.
"""
for colname in self.df.columns:
df = tempDf[colname].copy().to_frame()
df['dayofweek'] = tempDf[colname].index.dayofweek
df['quarter'] = tempDf[colname].index.quarter
df['month'] = tempDf[colname].index.month
df['year'] = tempDf[colname].index.year
df['dayofyear'] = tempDf[colname].index.dayofyear
df['dayofmonth'] = tempDf[colname].index.day
df['weekofyear'] = tempDf[colname].index.isocalendar().week
if(trainOrTest=="train"):
self.feature_train_dataframes[colname] = df
elif(trainOrTest=="test"):
self.features_test_dataframes[colname] = df
else:
self.feature_dataframes[colname] = df
print("=========== Creating Features Completed For {} Dataset===========".format(trainOrTest))
#return self.feature_dataframes
def plot_featured_data(self , feature='dayofweek' , district = "Monaragala"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
fig, ax = plt.subplots(figsize=(10, 8))
sns.boxplot(data=self.feature_dataframes[district], x=feature, y=district)
ax.set_title('Showing {} Data by {}'.format(district , feature))
plt.show()
def create_models(self):
import time
import xgboost as xgb
#This will create two dictionaries each contains feature datafranes for all the districts
self.create_features(self.train , trainOrTest="train")
self.create_features(self.test , trainOrTest="test")
FEATURES = ['dayofyear', 'dayofweek', 'quarter', 'month', 'year']
for district in self.df.columns:
TARGET = district
X_train = self.feature_train_dataframes[district][FEATURES]
y_train = self.feature_train_dataframes[district][TARGET]
X_test = self.features_test_dataframes[district][FEATURES]
y_test = self.features_test_dataframes[district][TARGET]
self.model_x_tests[district] = X_test
print("=========== Start Creating XGBooster for {} ===========".format(district))
reg = None
reg = xgb.XGBRegressor(base_score=0.5, booster='gbtree',
n_estimators=1000,
early_stopping_rounds=50,
objective='reg:linear',
max_depth=3,
learning_rate=0.01)
print("=========== Model Created ===========")
print("=========== Model Training : Started ===========")
reg.fit(X_train, y_train,
eval_set=[(X_train, y_train), (X_test, y_test)],
verbose=100)
print("=========== Model Training : Completed ===========")
self.ts_models[district] = reg
print("=========== Model Saved Successfully : {} District ===========".format(district))
time.sleep(3)
def check_feature_importance(self , district="Monaragala"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
reg = self.ts_models[district]
fi = pd.DataFrame(data=reg.feature_importances_,
index=reg.feature_names_in_,
columns=['importance'])
fi.sort_values('importance').plot(kind='barh', title='Feature Importance')
plt.show()
def forecaset_data(self, district="Monaragala"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
reg = self.ts_models[district]
X_test = self.model_x_tests[district].copy()
test = self.features_test_dataframes[district].copy()
df = self.feature_dataframes[district].copy()
test['prediction'] = reg.predict(X_test) #get the predictions for testing dataset
df = df.merge(test[['prediction']], how='left', left_index=True, right_index=True)
ax = df[[district]].plot(figsize=(15, 5))
df['prediction'].plot(ax=ax, style='.')
plt.legend(['Truth Data', 'Predictions'])
ax.set_title('Raw Dat and Prediction - {} District'.format(district))
plt.show()
#return test , df
def forecast_week(self, starts_from , district="Monaragala"):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
color_pal = sns.color_palette()
end_date = pd.date_range(start=starts_from, periods=7+1, freq='D', closed='right')[-1]
ax = df.loc[(df.index > starts_from) & (df.index < end_date)][district] \
.plot(figsize=(15, 5), title='Week Of Data')
df.loc[(df.index > starts_from) & (df.index < end_date)]['prediction'] \
.plot(style='.')
plt.legend(['Truth Data','Prediction'])
plt.show()
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:govimithura/providers/authentication_provider.dart';
import 'package:govimithura/screens/login.dart';
import 'package:govimithura/utils/loading_overlay.dart';
import 'package:govimithura/utils/utils.dart';
import 'package:govimithura/widgets/utils/common_widget.dart';
import 'package:provider/provider.dart';
import '../widgets/utils/buttons/custom_elevated_button.dart';
import '../widgets/utils/text_fields/primary_textfield.dart';
class ForgetPasswordScreen extends StatefulWidget {
const ForgetPasswordScreen({super.key});
@override
State<ForgetPasswordScreen> createState() => _ForgetPasswordScreenState();
}
class _ForgetPasswordScreenState extends State<ForgetPasswordScreen> {
final GlobalKey<FormState> _key = GlobalKey<FormState>();
late AuthenticationProvider pAuthentication;
@override
void initState() {
super.initState();
pAuthentication =
Provider.of<AuthenticationProvider>(context, listen: false);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
"Forget Password",
),
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: Form(
key: _key,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const LogoText(),
spacingWidget(30, SpaceDirection.vertical),
const Text(
"Please enter your email address to recieve reset password link",
style: TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
spacingWidget(20, SpaceDirection.vertical),
PrimaryTextField(
onChanged: (value) {
pAuthentication.setEmail(value);
},
label: "Email Address",
validator: (value) {
if (value == null || value.isEmpty) {
return 'Required';
} else if (!(value.contains("@") && value.contains("."))) {
return 'Enter valid Email Address';
}
return null;
},
),
spacingWidget(20, SpaceDirection.vertical),
CustomElevatedButton(
text: "Send reset password link",
onPressed: () async {
if (_key.currentState!.validate()) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => const LoginScreen()),
(route) => false);
bool isSent = await LoadingOverlay.of(context)
.during(pAuthentication.forgetPassword(context));
if (mounted && isSent) {
Utils.showDialogBox(context,
"Link sent to ${pAuthentication.authModel.email} please check your email inbox");
}
}
},
)
],
),
),
),
);
}
}
...Research problem...
Main Objective:
Agriculture is one of the major livelihoods in Sri Lanka. People are engaging in cultivation in commercial gardens and also at a smaller level, in home gardens.
Due to the current economic and fuel crisis in Sri Lanka, people have found it difficult to get their daily food needs from stores. because of these reasons again people have turned their attention on home gardening.
The Main Objective of the research topic is even a person with primary knowledge
or without any knowledge about home gardening can use this mobile application to make home
gardening in effective way to reap the harvest.
Sri Lankan people have found it difficult to get their home gardening inquiry solutions in their day-to-day life. There is no such application developed for Sri Lankan home gardening to help users. The main research problem is to answer the necessary home gardening inquiries through message commands in the chatbot.
Research Problem:
...Main Objective...
Due to the current economic and fuel crisis, most of the people living in Sri Lanka are now turning to home gardening.
But the main problem here is that people who are used to a modern lifestyle do not have proper knowledge about gardening.
There is no path to take decisions and advice about problems that arise when they start home gardening in their own living places.
Due to these facts, people cannot reap a bountiful harvest from the garden.
The main objective of this home gardening chatbot is to provide users in the agriculture industry with quick and reliable information on various topics such as crop management, weather conditions, and watering plants, among others. The aim is to improve productivity and sustainability in home gardening.
If we consider these points in more detail, the problem is that many people who turn to home gardening today, have a rudimentary knowledge
of home gardening and lack the proper understanding of home gardening and climate changes and crop growing quarters. Therefore, People who
cultivate various crops have not been able to harvest as much as they expected.
...Sub Objectives...
Another problem faced by people is that people are not able to analyze the disease affecting a particular crop. Once the disease affects
the crop, the growth of some stems of the crop is reduced, but the disease can still attack the crop. So those whole crops or parts are
destroyed and much of their produce is reduced before harvest. Therefore, people don’t have little understanding of what remedies are needed to
prevent the spread of the disease.
1. Provide small details of the home gardening inquiries and improving users' knowledge and skills through educational content.
2. Natural Language Processing model to answer inquires.
3. Develop a pre trained model to identify keywords in the given questions.
4. Then extracted documents from the Wikipedia for the identified keywords.
5. Develop a mobile application and integrate with the developed models.
And also, another problem that arises in day-to-day home gardening activities, people face various problems in crop cultivation mainly due to
their rudimentary knowledge about gardening and unable to identify the disease affecting a certain crop, people face various problems in crop
cultivation and also people use different types of fertilizers, herbicides, and insecticides while growing crops. They don’t know how to use
them properly for the crops. Also, due to the fuel crisis in the country, people have not been able to go to the agricultural service centers
to get necessary advice related to home gardening and above mention problems.
...User Requirements...
The other major problem affecting home gardening is considered to be the destruction of crops by animals, so the severity problem is attacks
of wild animals. For example, elephants, peacocks, monkeys, greater coucal, and so on. They cause crop damage. Due to that reason, people will not be
able to expect a harvest from gardening. Due to the lack of a proper remedy for it, the people who are currently engaged in home gardening activities
are hindered from cultivating successfully.
1. The user should be able to get accurate and up-to-date information related to agriculture such as crop information, weather conditions, and pest control.
2. The chatbot should be easily accessible and convenient to use.
3. The chatbot should have a user-friendly interface that is easy to navigate and understand.
Individual research question:
1. How do people cultivate crops harvested as they accepted, according to crop analysis and prediction?
2. How do people recognize the affected crop diseases and get relevant solutions using computer vision?
3. How people find the right solutions to their queries through different languages via chat messaging and voice messaging?
4. How to identify and repel harmful animals that come to the plantation?
...Functional Requirements...
Individual Objectives:
1. Crop analysis and predictions.
People may have a lack of proper understanding of home gardening and climate changes and crop growing quarters.
Therefore, People who cultivate various crops have not been able to harvest as much as they expected.
Due to that problem the user will be creating their own account while adding the location where the person lives
and the relevant quarter of their own. The location of the user will be stored in the system. After that, according
to the user's above information of predicting the type of crop suitable for cultivation at that time and giving instructions related to cultivation.
2. Crop diseases recognition based on Computer vision.
Select the leaf affected by disease and then collect the leaf from the plant and take a photo of the leaf and upload the leaf image to the system.
Preprocessing the input image to improve image quality and remove unwanted distortions from the image. Through the approach of plant disease identification
using image processing and machine learning is illustrated in Image preprocessing, segmentation, feature extraction, and classification.
And also, we can include several classification algorithms like NB, KNN, DT, SVM, and RF to identify the diagnosis of disease and give solutions and recommendations.
3. Multipurpose Chat Application.
In the study of the research papers on this Chat Applications, it was the latest digital interface developments, for the growth of the web and smartphone apps.
It is well documented for these applications to use automatic conversational agents that operate on software creation or a kind of artificial intelligence (AI)
relationship between users and automated systems. This AI-based multi-purpose chat application helps users to find the right answers to their queries to make the
right decisions. This multi-purpose chat application is made by providing feedback in two different languages and voice activation.
And also users can multilingual both text and voice programmable in this chat application. This system will enable the users to ask any number of inquiries,
which will help to spread the latest Home Gardening technology faster and to a higher number of users.
4. Animal detective camera security system.
Gardening is constantly monitored by a security camera system. This will constantly monitor the inner as well as the outer boundary of the gardening.
Due to this process, if an animal that damages the plantation reaches the outer limit of the plantation or enters the plantation,
this security camera system will identify the animal that has entered the plantation and inform the user of the location of the animal.
Because of this, the gardener does not need to keep an eye on his crops constantly to protect them from harmful animals.
Here, by installing speakers at selected locations around the gardening, the security camera system can identify the relevant animal and
emit sounds necessary to drive away the relevant animal.
(Ex: making a blast sound to drive away animals like peacocks, monkeys, and pigs and making the sound of bees to drive away wild elephants)
<<<<<<< HEAD
This measure will be able to reduce the damage caused to crops, especially by animals like elephants, peacocks, monkeys, cows and
=======
This measure will be able to reduce the damage caused to crops, especially by animals like elephants, peacocks, monkeys, cows
>>>>>>> 2a73121ebbda9d8040172a86c2353eb1ec34d682
1. The chatbot should be able to provide personalized information to users based on their specific requirements in the questions.
2. The chatbot should use NLP to understand and respond to user queries in a conversational manner.
3. The chatbot should be able to retrieve and access relevant information from the internet related to agriculture.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment