JorgeAEP commited on
Commit
d7e9dad
·
verified ·
1 Parent(s): ceb9980

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -10
README.md CHANGED
@@ -108,23 +108,90 @@ This curated dataset is continuously expanded as new [submissions](https://huggi
108
  ## How to Use
109
 
110
  ```bash
111
- pip install datasets
 
 
112
 
 
 
113
 
 
 
114
 
115
- from datasets import load_dataset
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
- # Load the dataset (replace with your actual dataset ID)
118
- ds = load_dataset("your-username/opheno")
 
119
 
120
- # Access the main data split
121
- # TODO: tba
 
 
122
 
123
- # Example: Filter for BBCH observations and convert value to integer
124
- # TODO: tba
 
 
 
 
125
 
126
- # Example: Filter for Plant Density and convert value to float
127
- # TODO: tba
128
  ```
129
  For more details on exploring and manipulating data with the datasets library (e.g., advanced filtering, mapping, shuffling), please refer to the official Hugging Face Datasets documentation.
130
 
 
108
  ## How to Use
109
 
110
  ```bash
111
+ # LOAD THE DATA SET
112
+ # Install required library (run once)
113
+ # pip install datasets pandas matplotlib scikit-learn
114
 
115
+ from datasets import load_dataset
116
+ import pandas as pd
117
 
118
+ # Load dataset from Hugging Face Hub
119
+ ds = load_dataset("OPheno/Weed-phenology")
120
 
121
+ # Convert to pandas DataFrame
122
+ df = ds["train"].to_pandas()
123
+
124
+ print("Dataset loaded with", len(df), "rows")
125
+ df.head(
126
+ # Do you want to filter values?
127
+
128
+ # Filter for a specific weed species
129
+ echcg = df[df["weed"] == "ECHCG"]
130
+
131
+ # Filter for emergence measurements only (raw counts)
132
+ emergence = echcg[echcg["type_of_value"].isin([
133
+ "plant_density",
134
+ "newly_emerged_plants"
135
+ ])]
136
+
137
+ emergence.head()
138
+
139
+ print("Summary of selected values:")
140
+ print(emergence[["date", "value", "type_of_value", "measurement_unit"]])
141
+
142
+ # Plot the Emergence Curve
143
+
144
+ import matplotlib.pyplot as plt
145
+
146
+ # Ensure date is datetime type
147
+ emergence["date"] = pd.to_datetime(emergence["date"])
148
+
149
+ # Sort by date
150
+ emergence = emergence.sort_values("date")
151
+
152
+ plt.figure(figsize=(8, 4))
153
+ plt.plot(emergence["date"], emergence["cum_emergence_percentage"], marker="o")
154
+
155
+ plt.xlabel("Date")
156
+ plt.ylabel("Cumulative emergence (%)")
157
+ plt.title("Weed Emergence Curve")
158
+ plt.xticks(rotation=45)
159
+ plt.tight_layout()
160
+ plt.show()
161
+
162
+ # Create a model
163
+
164
+ from sklearn.linear_model import LinearRegression
165
+ import numpy as np
166
+
167
+ # Prepare data
168
+ X = emergence["days_after_start"].values.reshape(-1, 1)
169
+ y = emergence["cum_emergence_percentage"].values.reshape(-1, 1)
170
+
171
+ # Fit linear regression
172
+ model = LinearRegression()
173
+ model.fit(X, y)
174
+
175
+ # Print model parameters
176
+ print("Intercept:", model.intercept_[0])
177
+ print("Slope:", model.coef_[0][0])
178
 
179
+ # Predict curve for plotting
180
+ X_pred = np.linspace(X.min(), X.max(), 100).reshape(-1, 1)
181
+ y_pred = model.predict(X_pred)
182
 
183
+ # Plot
184
+ plt.figure(figsize=(8, 4))
185
+ plt.scatter(X, y, label="Observed", color="blue")
186
+ plt.plot(X_pred, y_pred, label="Linear model", color="red")
187
 
188
+ plt.xlabel("Days after start")
189
+ plt.ylabel("Cumulative emergence (%)")
190
+ plt.title("Linear Model of Weed Emergence")
191
+ plt.legend()
192
+ plt.tight_layout()
193
+ plt.show()
194
 
 
 
195
  ```
196
  For more details on exploring and manipulating data with the datasets library (e.g., advanced filtering, mapping, shuffling), please refer to the official Hugging Face Datasets documentation.
197