Gains:
- Ability to produce scripts that clean and visualize drilling, production and monitoring data with Python, with AI support
- Ability to recognize data quality, overlearning and extrapolation risks when building simple prediction and anomaly models
- Ability to verify AI-generated code and result with unit control, independent calculation and engineering plausibility
In each unit of this module you have seen AI is powerful in coding: borehole cleaning, mass balance, kriging skeleton, fleet summary, vibration analysis, environmental scanning. This last unit focuses on Python, the concrete tool for that code, and the proper discipline of generating code with AI. Python has become the de facto standard in mining data analysis because it is free, has powerful libraries (pandas: tabular data manipulation; numpy: numerical calculus; matplotlib: plotting; scikit-learn: machine learning), and automates repetitive tasks. AI multiplies the speed at which you write that code; but the code it produces is not always correct. The central principle of this unit: Never run the code the AI writes without first reading it, validating its unit, and testing it with a small amount of known data. The code may silently produce the wrong result, which can turn into a bad engineering decision in mining.
Basic flow of generating code with AI
Getting code from AI is an engineering cycle, not a conversation:
- Describe the task clearly. Input (columns, units, sample row), desired output, and constraints. Ambiguous request produces ambiguous code.
- Ask for it to be small and readable. Ask for step-by-step, commented code rather than one giant function.
- Read and understand. Understand what each line does; Don't run code you don't understand.
- Test with small data. Run it manually with 5-10 lines whose results you know and verify the expected output.
- Question edge cases. Empty cell, negative value, unit shuffling, repeating record How does the code behave?
- Scale and check logic. Run on all data; Is the result engineeringly reasonable?
Tip: The most common errors that enter AI code are silent: wrong column name, unit mixing (m vs ft, g/t vs ppm), silently dropped rows (like dropna), wrong average (plain average when it should be weighted). These do not cause errors; It just produces the wrong number. So "didn't get an error" never means "correct".
Typical Python tasks in mining
- Data cleansing: Merging drilling/production/monitoring tables, inconsistency flagging, unit normalizing.
- Summary and visualization: Histogram, time series, grade-tonnage curve, OEE graphs.
- Statistics and geostatistics: Summary statistics, correlation, variogram/kriging (with special libraries).
- Anomaly detection: Threshold-based or simple model-based drift capture.
- Simple prediction models: For example, grinding size-yield relationship with regression.
For most of these tasks, AI provides excellent starting code. But there are two pitfalls: data quality and model limits. Knowing both is key to using AI code safely.
Model limits: overlearning and extrapolation
The simple predictive models that AI easily builds are vulnerable to two major risks. Overfitting: The model memorizes training data but performs poorly on new data; Building complex models with little data invites this. Extrapolation: The model becomes unreliable when it is forced to make a prediction over a range outside of the training data; For example, a model learned in the range of 0.3-0.8 g/t may give meaningless results for 5 g/t. AI does not “spontaneously” manage these risks for you; It's up to you to read the model critically, make the training/test distinction, look at the confidence interval, and check whether the prediction is physically plausible. No matter how accurate a model number appears, it cannot be the basis for an engineering decision outside the data range.
three mini cases
Case 1 — Silent volume error. An engineer wants code that makes the AI calculate the average grade from assay data. The code works, the result is 2.1 g/t. The engineer reads the code; Notice that the average is not weighted by interval length, but is taken as a straight average. High grades in short intervals were unfairly gaining weight. When moving to the weighted average, the value decreases to 1.7 g/t. The code gave no errors; reading caught the error.
Case 2 — Silent line dropping. In a production summary code, AI cleaned up rows with missing values with dropna. The code runs smoothly, but the total tonnage is underestimated because some valid rows were dropped altogether due to a single empty column. When the engineer compares the number of lines between input and output, he sees the difference and corrects the cleaning logic. Lesson: always compare the number of input and output lines.
Case 3 — Extrapolation trap. A team applies a regression model learned in the low grade range to a high grade area; The model gives an absurdly high yield estimate. Fortunately, the engineer rejects the result, saying "this area is far outside the range seen by the model" and requests metallurgical testing. Lesson: know the range of data to which the model is valid; Do not use an out-of-state estimate.
Copiable prompt templates
SECURE DATA CLEANING CODE "Role: You are a Python data analyst assistant. Write code with pandas that cleans the following table. Columns and units: [list]. Rules: (1) print the number of rows BEFORE and AFTER dropping rows; (2) report which rows were dropped and why; (3) comment unit conversions; (4) use weighted average where necessary instead of plain. Explain each step with a comment line."
CODE REVIEW REQUEST"Explain the following Python code line by line and point out the following risk points: incorrect column name assumption, unit confusion, silent rowdrop, flat/weighted average error, edge case (null/negative)behavior. DO NOT FIX the code; just list the risks. Code: [paste]."
TEST SETUP WITH SMALL DATA "For this function, manually produce a small test data (5-6 lines) of which I know the result and the expected output; write a test block that checks whether the function works correctly on this data. Also test the extreme cases (empty cell, negative, unit extreme value). Function: [paste]."
SIMPLE MODEL + BOUNDARY WARNING"Set up a simple regression for [x -> y] with the following data. Differentiate between training/testing, report the error metric, and clearly state the range of x over which the model is VALID. Warn if predictions are made OUTSIDE this range. Comment on the risk of overtraining and sparsity of data. Data:[paste]."
Weak prompt / Strong prompt
WEAK PROMPT: "Calculate the average grade from this data."
STRONG PROMPT:"Role: You are a Python assistant. Columns: HoleID, From(m), To(m),Au(g/t). Calculate WEIGHTED average grade with interval length. Code: (1) print the number of input/output rows; (2) report null/negative values before dropping them; (3) confirm the unit assumption. Also show subtotals so I can verify the result manually. Data: [paste]."
Comparison table: risk and precaution
Risk
symptom
precaution
Unit interference
Reasonable but wrong number
Comment out the unit in code, check it
Silent line drop
Total is missing
Compare number of input/output lines
Plain vs weighted average
wrong average
Verify weighting
overlearning
Bad on test data
Training/testing separation, keep it simple
extrapolation
Nonsense guess out of range
Limit valid range
Common mistakes
- Running the code without reading it. "It didn't get any errors" doesn't mean it's true.
- Not testing with small data. Trust without a verifiable example is false.
- Not comparing the number of input/output lines. This is how silent losses escape.
- Ignoring the model range. Extrapolation estimates are unreliable.
- Trusting the beauty of the chart. A stylish chart can hide the wrong number.
Attention: If the AI code goes into an engineering account, that code is just as responsible as an account. Wherever the outcome becomes a mining decision, run the code and its output through an independent logic check and comparison with a second method if possible.
In summary
Python is the de facto tool for mining data analysis, and AI greatly increases the speed at which you write it. But AI code can harbor silent bugs (unit confusion, row dropping, wrong averaging) and model traps (overlearning, extrapolation). Secure flow: describe clearly, want small and readable, read and understand, test with small known data, query edge cases, scale and logic check. A model output cannot be the basis for a decision outside the data range; and each code carries as much responsibility as an account if it turns into a mining decision.
Application task
Use the "Secure data sanitization code" template with a grade averaging or production summary task to get the code from the AI; Have the code de-risked with the "Code review request" template. Then, with the "Test setup with small data" template, manually create a data set whose results you know and verify the code. Finally, for a simple relationship, set up a model with the "Simple model + limit warning" template and test that it gives a warning when it goes outside the valid range.
checklist
- [ ] I read the AI code and understood every line, I did not run it blindly.
- [ ] I tested it with small, manually verifiable data.
- [ ] I compared the number of input and output lines.
- [ ] I verified unit consistency and weighting.
- [ ] I limited the valid data range of the model, avoiding extrapolation.
- [ ] I checked the result, which turned into a decision, with independent logic/second method.
Module Exam
1. An intern asks the AI chat tool about the average grade of the ore body and writes the resulting value of '1.8 g/t gold' directly into the reserve report. What is the fundamental mistake in this approach?
- A) The grade value must come from the project's own drilling/analysis data and verified forecast; The number generated by the AI may be an unsourced fabrication ✔
- B) It should have been asked for AI in ounces instead of grams
- C) The value is correct, only a period should have been used instead of a comma
- D) It is enough to ask the AI the same question three times and take the average
Explanation: The language model does not know the drilling data of your project; produces a number that seems most likely (hallucination). The grade comes only from the project's own composited drilling data and geostatistical estimate; AI output cannot be included in the report without the approval of a competent person.
2. What does 'risk-based classification' enable in the use of AI in mining engineering?
- A) Lower the price of the AI tool
- B) Determine the role of AI and the mandatory depth of verification according to the risk level of the task ✔
- C) Prompts should be written shorter
- D) Automatically delegate all decisions to AI
Explanation: Not every mission is at the same risk level. Classifying the task as low/medium/high/critical determines which output can be freely used and which requires standard and field verification and competent engineer approval.
3. What does 'variogram' model in geostatistics?
- A) Fuel consumption of the equipment
- B) Change of metal price over time
- C) Spatial continuity depending on distance; ✔ how the similarity decreases as the points get further away
- D) The vibration frequency created by blasting
Description: Variogram describes how the similarity of samples to each other decreases (spatial continuity) as the distance between two points increases. Kriging uses this model to estimate unmeasured points with a margin of uncertainty.
4. What is the best approach when having AI pre-classify lithology from drill core photography?
- A) Processing the rock type given by AI directly into the drilling log
- B) Copying AI's text into the report without examining the photo at all
- C) Canceling the geologist's observation and relying solely on AI
- D) Consider the output a preliminary prediction/hypothesis and verify it with geologist observation and laboratory analysis ✔
Description: AI can generate a prediction and attention list from the image; However, the final lithology/alteration decision is made by the geologist's observation and laboratory analysis. AI output is a start, a hypothesis to be verified.
5. What does 'stripping ratio' mean in open pit planning?
- A) The amount of rust (waste rock) that must be removed to reach one unit of ore ✔
- B) Percentage of metal in the ore
- C) Daily number of trips of trucks
- D) The amount of explosive used in blasting
Description: Stripping rate is the amount of waste (strip/waste) that must be removed to achieve one unit of ore. The final pit limit and economy largely depend on this ratio; Even though AI generates scenarios, the boundary decision is up to the competent engineer.
6. What does it mean in predictive maintenance when AI finds 'anomalies' in vibration and temperature data?
- A) Proof that the equipment has definitely failed
- B) A warning that the data deviates from normal; It is not a definitive diagnosis of malfunction, but a sign that needs to be confirmed by physical examination ✔
- C) Order that the equipment should be stopped automatically
- D) Guarantee that data was recorded incorrectly
Explanation: An anomaly is a deviation of data from normal behavior and may indicate a malfunction; but it is not a definitive diagnosis. The decision to stop the equipment or replace parts is made with the physical examination of the maintenance team and the approval of the operations manager.
7. Which is essential for safety when utilizing AI in drill-blast design?
- A) Implementation of the AI recommendation directly in the field
- B) Skipping vibration measurement
- C) Verification of AI's proposed design with field measurement, regulatory limit and approval of authorized blasting expert ✔
- D) Fixing the amount of explosives with the maximum given by the AI
Description: Blasting; It carries serious safety and regulatory risks such as vibration, air shock and flying stones. AI can produce a design sketch and parameter recommendation; However, the final design must pass field measurement, regulatory limits and approval of the authorized blasting expert (detonator/responsible).
8. What is the typical relationship between 'recovery' and 'concentrate grade' in mineral processing and what should AI remember when interpreting this?
- A) The two always increase together
- B) There is no relationship between them
- C) The relationship is constant and the same in all facilities
- D) There is usually a reverse balance (yield decreases as grade increases); actual values must be verified by metallurgical testing and mass balance ✔
Explanation: Generally, as we try to obtain a higher concentrated grade, the yield decreases (grade-yield balance). AI can explain this trend, but actual operating values must be confirmed by metallurgical testing and mass balance; the general trend is not a substitute for site-specific reality.
9. What is the most appropriate use of analyzing near miss/accident data with AI in occupational safety?
- A) Classify free text records and extract recurring risk patterns; Leave the decision to the OHS expert ✔
- B) Automatically determine the culprit of accidents
- C) Delegating work stoppage orders to AI
- D) Archiving near-miss records without reviewing them
Description: AI can classify large amounts of free text records and quickly extract repetitive patterns and risky conditions. However, the decision to stop a work, evacuate an area or root cause is made within the framework of the OHS expert and the legislation; AI output is input, not decision.
10. Why is 'acceleration of deformation rate' a critical sign in radar/prism data in slope monitoring?
- A) It definitely indicates that the measuring device is broken.
- B) It may herald a progressive defeat; Early warning and evacuation decision belongs to the geotechnical engineer ✔
- C) It shows that the slope is completely safe
- D) It is only significant when there is precipitation and can be ignored
Explanation: Before slope failures, a gradual increase in the deformation rate (acceleration) is generally observed; This may be a sign of progressive failure. AI can highlight the trend, but the evacuation/early warning decision is made by the geotechnical engineer's analysis and protocol.
11. In environmental monitoring, what is the most accurate response to an 'exceedance' sign that AI finds in a water quality time series?
- A) Reporting AI output directly to the government agency
- B) Ignore the warning and continue watching
- C) Verify with accredited laboratory result, regulatory limit and environmental engineer evaluation ✔
- D) Relying only on AI and canceling laboratory analysis
Description: AI may signal a possible breach early; However, the official conformity decision is made by accredited laboratory analysis, limit values in the legislation and the evaluation of the environmental engineer. The AI output is a screening alert, not a legal/technical decision.
12. What is the most reliable way to avoid getting a made-up (hallucinatory) reference when you ask the AI for the clause number of a standard such as JORC or NI 43-101?
- A) Relying on the item number given by the AI
- B) Asking the same question again with different words
- C) Looking at a blog post instead of the standard
- D) Opening and confirming each article reference from the current official text of the standard and obtaining approval from a competent person ✔
Explanation: Although the language model knows the name of the standard correctly, it may hallucinate the article number and text. Each substance reference must be opened and confirmed from the current official text of the standard and final conformity must be confirmed by the competent person (CP/QP).
13. What is the most critical check before running an AI-written Python analysis script?
- A) Reading the code and verifying unit/column matching, testing with small known data and checking the plausibility of the result ✔
- B) Running the code directly on the entire data set without reading it
- C) Just seeing that there is no mistake and accepting the result
- D) Relying on the graphics of the output to look nice.
Description: AI code may mix units, assume column names incorrectly, or silently drop rows. It's essential to read the code, verify volume and column matching, test with a small amount of known data, and check if the result is engineering reasonable.
14. What is the best behavior in terms of privacy when giving mining data to a cloud-based AI tool?
- A) Pasting all raw data as is
- B) Anonymize context and clean sensitive reserve/coordinate/production data and use corporate, policy-compliant tool ✔
- C) Assuming that providing actual coordinates is essential for result quality
- D) Ignoring the privacy policy at all
Explanation: Reserve figures, license/coordinate information and production data are sensitive in terms of trade secrets and legislation. It is necessary to anonymize the context, clear the real coordinates and names, choose the corporate/privacy guaranteeing tool and comply with the company policy.