python
import kaml
graph = kaml.load_graph("knowledge_graph.kml")
python
def graph_based_feature_extraction(data):
features = []
for item in data:
feature = []
crop_feature = graph.query(entity=item.crop, relation="has_feature")
feature.append(crop_feature)
disease_feature = graph.query(entity=item.disease, relation="has_feature")
feature.append(disease_feature)
features.append(feature)
return features
python
from sklearn import svm
from sklearn.model_selection import train_test_split
data = load_data()
features = graph_based_feature_extraction(data)
train_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size=0.2, random_state=42)
clf = svm.SVC()
clf.fit(train_features, train_labels)
accuracy = clf.score(test_features, test_labels)